Please do not use sudo with pamac. It uses polkit and will ask for authentication when needed. Otherwise, you end up with incorrect ownership/permissions.
#!/bin/bash
if [[ $(ps -o comm= $PPID) == "sudo" ]]; then
echo "Warning: Do not use 'pamac' with 'root' privileges. It can cause permission issues."
read -p "Are you sure you want to continue? (y/n): " choice
if [[ $choice != "y" ]]; then
echo "Exiting..."
exit 1
else
echo "Continuing..."
fi
fi
/usr/bin/pamac "$@"
Edited; now requests confirmation instead of exiting.
A very nice fix to a longstanding issue. You might also want to look at using the Effective UID (which is 0 for root):
#!/bin/bash
if [[ $EUID -eq 0 ]]; then
echo "Warning: Do not use 'pamac' with 'root' privileges. It can cause permission issues."
exit 1
fi
/usr/bin/pamac "$@"
This will protect against pamac being run as root using sudo, run0 or su:
~ sudo pamac install x2goserver
Warning: Do not use 'pamac' with 'root' privileges. It can cause permission issues.
~ run0 pamac install x2goserver
Warning: Do not use 'pamac' with 'root' privileges. It can cause permission issues.
~ su
Password:
[scott-ser scotty]# pamac install x2goserver
Warning: Do not use 'pamac' with 'root' privileges. It can cause permission issues.
I can’t imagine any case where a user would need to run pamac as root, even if they are unable to log in as a normal user for some reason. pacman would be the goto in that type of situation.
The thing is pamac is aware of root/sudo/user0 … and even has contingencies for when it is run this way.
I recognized this even when submitting a PR to disallow running this way but it was rejected on the grounds that pamac is intended to be able to be run under these circumstances.
Obviously … it still breaks things when run this way … so …