Skip to content

Commit 7ee5a3c

Browse files
committed
fix(installer): Fallback to su if sudo is unavailable
1 parent 70fc3a5 commit 7ee5a3c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

install.sh

+16-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@ function fail {
2626
# The goal is to allow the user to run this script as a normal user and
2727
# to be asked for authorizations as needed
2828
function askRoot {
29-
echo "The following command needs administrator privileges:"
30-
echo
31-
echo -e "\\t$*"
32-
echo
33-
# The -k flag forces sudo to re-ask the user for their authorization
34-
sudo -k "$@"
29+
if [ $(id -u) -eq 0 ]; then
30+
"$@"
31+
else
32+
echo "The following command needs administrator privileges:"
33+
echo
34+
echo -e "\\t$*"
35+
echo
36+
# The -k flag forces sudo to re-ask the user for their authorization
37+
if command -v sudo > /dev/null; then
38+
sudo -k "$@"
39+
elif command -v su > /dev/null; then
40+
su root -c "/bin/bash $@"
41+
else
42+
fail "neither sudo nor su are installed"
43+
fi
44+
fi
3545
}
3646

3747
function install {

0 commit comments

Comments
 (0)