more error handling in detecting disk image creation

will need ported to macOS sometime
This commit is contained in:
2024-10-11 11:44:04 -04:00
parent 2f391a0fc2
commit ab21f9c838

View File

@@ -21,7 +21,7 @@
# SOFTWARE. # SOFTWARE.
if ! [ $(id -u) = 0 ]; then if ! [ $(id -u) = 0 ]; then
echo "Script must be run as root!" echo "Script must be run as root!" >&2
exit 1 exit 1
fi fi
@@ -43,12 +43,18 @@ disk_sector_size=512
if ! [ -e $disk_tmp_file ]; then if ! [ -e $disk_tmp_file ]; then
# create raw disk image # 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 sync
else else
echo "Removing old disk image..." echo "Removing old disk image..."
rm -rfv $disk_tmp_file 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 sync
fi fi
@@ -105,12 +111,19 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
mkdir $mount_point mkdir $mount_point
fi fi
mount $firstpart $mount_point 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 if [ -e $boottest_file ]; then
cp -v $boottest_file $mount_point/BOOTI686.BIN cp -v $boottest_file $mount_point/BOOTI686.BIN
else else
echo "unable to find boot32.bin!" echo "Failed to write $boottest_file to disk image" >&2
exit 3 exit 1
fi fi
# detach loop device # detach loop device
@@ -126,8 +139,8 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
chown --from=root:root --reference=LICENSE.md $disk_tmp_file chown --from=root:root --reference=LICENSE.md $disk_tmp_file
else else
echo "unable to find MBR/VBR binaries!" echo "unable to find MBR/VBR binaries!" >&2
exit 2 exit 1
fi fi
# requires util-linux from homebrew # requires util-linux from homebrew
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then