2022-12-06 17:17:41 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-02-04 03:52:45 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2022-10-16 19:46:42 +00:00
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
2022-10-16 17:17:50 +00:00
|
|
|
|
2022-12-19 14:19:26 +00:00
|
|
|
. "${script_path}/shell_include.sh"
|
2022-02-04 03:52:45 +00:00
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if [ -d mnt ]; then
|
|
|
|
umount mnt || ( sleep 1 && sync && umount mnt )
|
|
|
|
rmdir mnt
|
|
|
|
echo "done"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$(id -u)" != 0 ]; then
|
2022-09-03 10:54:05 +00:00
|
|
|
set +e
|
2023-07-16 15:04:31 +00:00
|
|
|
${SUDO} -- "${SHELL}" -c "\"$0\" $* || exit 42"
|
2022-09-03 10:54:05 +00:00
|
|
|
case $? in
|
|
|
|
1)
|
|
|
|
die "this script needs to run as root"
|
|
|
|
;;
|
|
|
|
42)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
2022-02-04 03:52:45 +00:00
|
|
|
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/build-root-filesystem.sh"
|