Skip to content

Commit

Permalink
Meta: Don't tell to run script as root when that's not the actual error
Browse files Browse the repository at this point in the history
Before, and that was the cause of many confusion in #build-problems
on Discord, the Meta/build-image-*.sh scripts would error out with
the message "this script needs to run as root" while the actual error
was unrelated.
  • Loading branch information
demostanis authored and linusg committed Oct 14, 2022
1 parent d007337 commit 48aea32
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
14 changes: 13 additions & 1 deletion Meta/build-image-extlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ die() {
}

if [ "$(id -u)" != 0 ]; then
exec sudo -E -- "$0" "$@" || die "this script needs to run as root"
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"
;;
42)
exit 1
;;
*)
exit 0
;;
esac
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
fi
Expand Down
14 changes: 13 additions & 1 deletion Meta/build-image-grub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ die() {
}

if [ "$(id -u)" != 0 ]; then
exec sudo -E -- "$0" "$@" || die "this script needs to run as root"
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"
;;
42)
exit 1
;;
*)
exit 0
;;
esac
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
fi
Expand Down
14 changes: 13 additions & 1 deletion Meta/build-image-limine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ if [ ! -d "limine" ]; then
fi

if [ "$(id -u)" != 0 ]; then
exec sudo -E -- "$0" "$@" || die "this script needs to run as root"
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"
;;
42)
exit 1
;;
*)
exit 0
;;
esac
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
fi
Expand Down
15 changes: 13 additions & 2 deletions Meta/build-image-qemu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,19 @@ if [ "$(id -u)" != 0 ]; then
if [ -x "$FUSE2FS_PATH" ] && $FUSE2FS_PATH --help 2>&1 |grep fakeroot > /dev/null; then
USE_FUSE2FS=1
else
${SUDO} -E -- "$0" "$@" || die "this script needs to run as root"
exit 0
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"
;;
42)
exit 1
;;
*)
exit 0
;;
esac
fi
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
Expand Down
15 changes: 13 additions & 2 deletions Meta/build-native-partition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ cleanup() {
}

if [ "$(id -u)" != 0 ]; then
sudo -E -- "$0" "$@" || die "this script needs to run as root"
exit 0
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"
;;
42)
exit 1
;;
*)
exit 0
;;
esac
else
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
fi
Expand Down

0 comments on commit 48aea32

Please sign in to comment.