Skip to content

Commit

Permalink
fix(installer): Fallback to su if sudo is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Mar 20, 2018
1 parent 70fc3a5 commit 7ee5a3c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ function fail {
# The goal is to allow the user to run this script as a normal user and
# to be asked for authorizations as needed
function askRoot {
echo "The following command needs administrator privileges:"
echo
echo -e "\\t$*"
echo
# The -k flag forces sudo to re-ask the user for their authorization
sudo -k "$@"
if [ $(id -u) -eq 0 ]; then
"$@"
else
echo "The following command needs administrator privileges:"
echo
echo -e "\\t$*"
echo
# The -k flag forces sudo to re-ask the user for their authorization
if command -v sudo > /dev/null; then
sudo -k "$@"
elif command -v su > /dev/null; then
su root -c "/bin/bash $@"
else
fail "neither sudo nor su are installed"
fi
fi
}

function install {
Expand Down

0 comments on commit 7ee5a3c

Please sign in to comment.