Meta: Implement proper checks for sudo alternatives

This introduces support for building with doas.
This commit is contained in:
Dominique Liberda 2023-07-08 06:31:05 +02:00 committed by Linus Groh
parent af5eaf5edf
commit fddbd11baa
6 changed files with 21 additions and 11 deletions

View file

@ -8,7 +8,7 @@ script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -- sh -c "\"$0\" $* || exit 42"
${SUDO} "${SHELL}" -c -- "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View file

@ -8,7 +8,7 @@ script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -- sh -c "\"$0\" $* || exit 42"
${SUDO} "${SHELL}" -c -- "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View file

@ -17,7 +17,7 @@ fi
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -- sh -c "\"$0\" $* || exit 42"
${SUDO} "${SHELL}" -c -- "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View file

@ -12,7 +12,7 @@ if [ "$(id -u)" != 0 ]; then
USE_FUSE2FS=1
else
set +e
${SUDO} -- sh -c "\"$0\" $* || exit 42"
${SUDO} "${SHELL}" -c -- "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View file

@ -16,7 +16,7 @@ cleanup() {
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -- sh -c "\"$0\" $* || exit 42"
${SUDO} "${SHELL}" -c -- "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View file

@ -6,17 +6,27 @@
# NOTE: If using another privilege escalation binary make sure it is configured or has the appropiate flag
# to keep the current environment variables in the launched process (in sudo's case this is achieved
# through the -E flag described in sudo(8).
SUDO="sudo -E"
if [ "$(uname -s)" = "SerenityOS" ]; then
SUDO="pls -E"
fi
die() {
echo "die: $*"
exit 1
}
if [ "$(uname -s)" = "SerenityOS" ]; then
SUDO="pls -E"
elif command -v sudo >/dev/null; then
SUDO="sudo -E"
elif command -v doas >/dev/null; then
if [ "$SUDO_UID" = '' ]; then
SUDO_UID=$(id -u)
SUDO_GID=$(id -g)
export SUDO_UID SUDO_GID
fi
# To make doas work, you have to make sure you use the "keepenv" flag in doas.conf
SUDO="doas"
else
die "You need sudo, doas or pls to build Serenity..."
fi
exit_if_running_as_root() {
if [ "$(id -u)" -eq 0 ]; then
die "$*"