Meta: Don't tell to run script as root when that's not the actual error

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.
This commit is contained in:
demostanis 2022-09-03 12:54:05 +02:00 committed by Linus Groh
parent d007337d97
commit 48aea321c5
5 changed files with 65 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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}"

View file

@ -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