From ab21f9c83879843b79f66f6ac5f49e6968dea21d Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Fri, 11 Oct 2024 11:44:04 -0400 Subject: [PATCH] more error handling in detecting disk image creation will need ported to macOS sometime --- scripts/create-disk.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/create-disk.sh b/scripts/create-disk.sh index 0310811..2d1928b 100755 --- a/scripts/create-disk.sh +++ b/scripts/create-disk.sh @@ -21,7 +21,7 @@ # SOFTWARE. if ! [ $(id -u) = 0 ]; then - echo "Script must be run as root!" + echo "Script must be run as root!" >&2 exit 1 fi @@ -43,12 +43,18 @@ disk_sector_size=512 if ! [ -e $disk_tmp_file ]; then # create raw disk image - dd if=/dev/zero of=$disk_tmp_file bs=$disk_sector_size count=$disk_size + if ! dd if=/dev/zero of=$disk_tmp_file bs=$disk_sector_size count=$disk_size; then + echo "Failed creating blank disk image." >&2 + exit 1 + fi sync else echo "Removing old disk image..." rm -rfv $disk_tmp_file - dd if=/dev/zero of=$disk_tmp_file bs=$disk_sector_size count=$disk_size + if ! dd if=/dev/zero of=$disk_tmp_file bs=$disk_sector_size count=$disk_size; then + echo "Failed creating blank disk image." >&2 + exit 1 + fi sync fi @@ -105,12 +111,19 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then mkdir $mount_point fi mount $firstpart $mount_point - mkdir -p $mount_point + + # ensure mountpoint is actually a mountpoint + if ! mountpoint -q $mount_point; then + echo "Failed to mount partition at $mount_point." >&2 + exit 1 + fi + + # copy kernel to filesystem if [ -e $boottest_file ]; then cp -v $boottest_file $mount_point/BOOTI686.BIN else - echo "unable to find boot32.bin!" - exit 3 + echo "Failed to write $boottest_file to disk image" >&2 + exit 1 fi # detach loop device @@ -126,8 +139,8 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then chown --from=root:root --reference=LICENSE.md $disk_tmp_file else - echo "unable to find MBR/VBR binaries!" - exit 2 + echo "unable to find MBR/VBR binaries!" >&2 + exit 1 fi # requires util-linux from homebrew elif [[ "$OSTYPE" == "darwin"* ]]; then