After gemini-propoesed fixes

This commit is contained in:
Sam Hardeman 2026-03-13 01:38:34 +01:00
parent 2e31283b61
commit 83324dd0f7
11 changed files with 228 additions and 307 deletions

View file

@ -1,38 +1,46 @@
#!/bin/bash
DIR="$@"
# Lackadaisical squashfs tools - Mount
DIR="$1"
if [[ -z "$DIR" ]]; then
echo "Usage: $0 <directory>"
exit 1
fi
DIR=$(readlink -f "$DIR")
DIR_SHORT=$(basename "$DIR")
BIN_DIR=$(dirname "$(readlink -f "$0")")
mkdir -p "$DIR"
OVERLAY_ROOT=$(readlink -f "${DIR}/..")/.squashfs/${DIR_SHORT}
OVERLAY_UPPER=${OVERLAY_ROOT}/upper
OVERLAY_LOWER=${OVERLAY_ROOT}/lower
OVERLAY_WORK=${OVERLAY_ROOT}/work
OVERLAY_TARG=$DIR
OVERLAY_ROOT="$(dirname "$DIR")/.squashfs/$DIR_SHORT"
OVERLAY_UPPER="$OVERLAY_ROOT/upper"
OVERLAY_LOWER="$OVERLAY_ROOT/lower"
OVERLAY_WORK="$OVERLAY_ROOT/work"
OVERLAY_TARG="$DIR"
if [ ! -f "${OVERLAY_ROOT}.img" ]; then
echo "Error: SquashFS image ${OVERLAY_ROOT}.img not found." >&2
if [[ ! -f "${OVERLAY_ROOT}.img" ]]; then
echo "Error: SquashFS image \"${OVERLAY_ROOT}.img\" not found." >&2
exit 1
fi
"$BIN_DIR"/umount-squash-image "$@" 1>/dev/null 2>/dev/null
# Unmount existing first
"$BIN_DIR/umount-squash-image" "$DIR" 2>/dev/null
# Mount lower squashfs image via loopback
mkdir -p "$OVERLAY_LOWER"
sudo mount "${OVERLAY_ROOT}.img" "$OVERLAY_LOWER" -t squashfs -o loop
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "Error: Failed to mount squashfs image (exit code $EXIT_CODE)." >&2
exit $EXIT_CODE
if [[ $? -ne 0 ]]; then
echo "Error: Failed to mount squashfs image." >&2
exit 1
fi
sudo mount -t overlay -o lowerdir="$OVERLAY_LOWER",upperdir="$OVERLAY_UPPER",workdir="$OVERLAY_WORK" none "$OVERLAY_TARG"
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "Error: Failed to mount overlay (exit code $EXIT_CODE)." >&2
# Cleanup: unmount the lower squashfs if overlay mount fails
# Mount overlay
sudo mount -t overlay none "$OVERLAY_TARG" \
-o lowerdir="$OVERLAY_LOWER",upperdir="$OVERLAY_UPPER",workdir="$OVERLAY_WORK"
if [[ $? -ne 0 ]]; then
echo "Error: Failed to mount overlay." >&2
sudo umount "$OVERLAY_LOWER" 2>/dev/null
exit $EXIT_CODE
exit 1
fi
echo "SquashFS filesystem is mounted and ready."
exit 0