diff --git a/Meta/build-image-extlinux.sh b/Meta/build-image-extlinux.sh index 3647c67766..d16659beb0 100755 --- a/Meta/build-image-extlinux.sh +++ b/Meta/build-image-extlinux.sh @@ -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" diff --git a/Meta/build-image-grub.sh b/Meta/build-image-grub.sh index 4b48615613..a130723df9 100755 --- a/Meta/build-image-grub.sh +++ b/Meta/build-image-grub.sh @@ -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" diff --git a/Meta/build-image-limine.sh b/Meta/build-image-limine.sh index e68ee4dcf2..1be38b2555 100755 --- a/Meta/build-image-limine.sh +++ b/Meta/build-image-limine.sh @@ -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" diff --git a/Meta/build-image-qemu.sh b/Meta/build-image-qemu.sh index f58734ea44..9d9e2eaf74 100755 --- a/Meta/build-image-qemu.sh +++ b/Meta/build-image-qemu.sh @@ -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" diff --git a/Meta/build-native-partition.sh b/Meta/build-native-partition.sh index 8ebb3ba6a6..c79f6a052a 100755 --- a/Meta/build-native-partition.sh +++ b/Meta/build-native-partition.sh @@ -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" diff --git a/Meta/shell_include.sh b/Meta/shell_include.sh index 11da2e1999..f1a28291d7 100644 --- a/Meta/shell_include.sh +++ b/Meta/shell_include.sh @@ -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 "$*"