diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2020-12-05 22:03:53 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2020-12-05 22:03:53 -0300 |
commit | a0a5fc9b66ea81459dbe6674d218a154b183bdf0 (patch) | |
tree | 9756021188b3ec988cd60eeb861ea4b0977974b6 /share | |
parent | 87bfedf023968d831735b4450932c055ec46e1a3 (diff) | |
download | trashman-a0a5fc9b66ea81459dbe6674d218a154b183bdf0.tar.gz trashman-a0a5fc9b66ea81459dbe6674d218a154b183bdf0.tar.bz2 |
Feat: trashman: try to invoke with sudo if user is not root
Diffstat (limited to 'share')
-rw-r--r-- | share/trashman/trashman/functions | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/share/trashman/trashman/functions b/share/trashman/trashman/functions index 61102e9..48700cd 100644 --- a/share/trashman/trashman/functions +++ b/share/trashman/trashman/functions @@ -203,6 +203,7 @@ trashman_check_exit_status() { # Check for superuser privileges trashman_check_root() { local action="$1" + local package="$2" if [ -z "$action" ]; then return @@ -213,8 +214,15 @@ trashman_check_root() { fi if [ "`whoami`" != "root" ]; then - trashman_echo "Action $action requires root privileges" - exit 1 + if which sudo &> /dev/null; then + # Try to invoke it with sudo + trashman_echo "You're running as a regular user, trying to re-invoke the command using sudo..." + sudo $PROGRAM $action $package + exit $? + else + trashman_echo "Action $action requires root privileges" + exit 1 + fi fi } |