ladybird/Meta/build-native-partition.sh
Tim Schumacher 032ef1b461 Meta: Define SUDO for all the image building scripts
Back when adding support for `pls` as a `sudo` replacement,
`build-image-qemu` dynamically set the `SUDO` variable depending on what
system it was running on and used the contents of that variable to call
the correct elevation utility.

During recent changes to the elevation error message, that usage of the
variable was replicated across all of our scripts, but without also
replicating the logic to set that variable in the first place.

Add back the variable setting logic to all the other scripts to keep
them from running into unset variables.
2022-10-16 23:39:45 +02:00

65 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
set -e
SUDO="sudo"
if [ "$(uname -s)" = "SerenityOS" ]; then
SUDO="pls"
fi
die() {
echo "die: $*"
exit 1
}
cleanup() {
if [ -d mnt ]; then
umount mnt || ( sleep 1 && sync && umount mnt )
rmdir mnt
echo "done"
fi
}
if [ "$(id -u)" != 0 ]; then
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
if [ -z "$SERENITY_TARGET_INSTALL_PARTITION" ]; then
die "SERENITY_TARGET_INSTALL_PARTITION environment variable was not set!"
fi
printf "verifying partition %s is already ext2... " "$SERENITY_TARGET_INSTALL_PARTITION"
if file -sL "$SERENITY_TARGET_INSTALL_PARTITION" 2>&1 | grep "ext2" > /dev/null; then
echo "done"
else
die "$SERENITY_TARGET_INSTALL_PARTITION is not an ext2 partition!"
fi
trap cleanup EXIT
printf "mounting filesystem on device %s... " "$SERENITY_TARGET_INSTALL_PARTITION"
mkdir -p mnt
if ! eval "mount $SERENITY_TARGET_INSTALL_PARTITION mnt/"; then
die "could not mount existing ext2 filesystem on $SERENITY_TARGET_INSTALL_PARTITION"
else
echo "done"
fi
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
"$script_path/build-root-filesystem.sh"