BuildSystem: Cleanup image creation

This commit is contained in:
2024-04-24 01:27:59 +03:00
parent e7e1dd91c7
commit d255141bd4
3 changed files with 149 additions and 139 deletions

View File

@@ -1,31 +1,36 @@
#!/bin/bash
if [[ -z $BANAN_DISK_IMAGE_PATH ]]; then
if [ -z $BANAN_DISK_IMAGE_PATH ]; then
echo "You must set the BANAN_DISK_IMAGE_PATH environment variable" >&2
exit 1
fi
if [[ -z $BANAN_SYSROOT_TAR ]]; then
if [ -z $BANAN_SYSROOT_TAR ]; then
echo "You must set the BANAN_SYSROOT_TAR environment variable" >&2
exit 1
fi
if [[ -z $BANAN_BUILD_DIR ]]; then
if [ -z $BANAN_BUILD_DIR ]; then
echo "You must set the BANAN_BUILD_DIR environment variable" >&2
exit 1
fi
if [[ "$1" == "full" ]] || [[ ! -f $BANAN_DISK_IMAGE_PATH ]]; then
if [ "$1" == "full" ] || [ ! -f $BANAN_DISK_IMAGE_PATH ]; then
$BANAN_SCRIPT_DIR/image-create.sh
fi
LOOP_DEV="$(sudo losetup --show -f $BANAN_DISK_IMAGE_PATH)"
sudo partprobe $LOOP_DEV
set -u
MOUNT_DIR="$BANAN_BUILD_DIR/mount"
mkdir -p $MOUNT_DIR
LOOP_DEV="$(sudo losetup --show -Pf $BANAN_DISK_IMAGE_PATH || exit 1)"
ROOT_PARTITION="${LOOP_DEV}p2"
MOUNT_DIR="${MOUNT_DIR:-$BANAN_BUILD_DIR/bananmnt}"
sudo mkdir -p $MOUNT_DIR || { echo "Failed to create mount point dir."; exit 1; }
if [ ! -b $ROOT_PARTITION ]; then
echo "Failed to probe partitions for banan disk image." >&2
sudo losetup -d $LOOP_DEV
exit 1
fi
sudo mount $ROOT_PARTITION $MOUNT_DIR
@@ -33,8 +38,6 @@ cd $MOUNT_DIR
sudo tar xf $BANAN_SYSROOT_TAR
cd
sudo umount $MOUNT_DIR || { echo "Failed to unmount banan mount."; exit 1; }
sudo umount $MOUNT_DIR
sudo losetup -d $LOOP_DEV || { echo "Failed to remove loop device for banan mount."; exit 1; }
sudo rm -rf "$MOUNT_DIR"
sudo losetup -d $LOOP_DEV