diff --git a/mount_rubikpi3.sh b/mount_rubikpi3.sh index d4f80271..2340b8d4 100644 --- a/mount_rubikpi3.sh +++ b/mount_rubikpi3.sh @@ -39,43 +39,37 @@ if [[ "$base_image" == *.yaml ]]; then elif [[ "$base_image" == *.tar.xz ]]; then # Directly download the tar.xz file wget -nv -O base_image.tar.xz "${base_image}" - tar -xJf base_image.tar.xz + tar -xJvf base_image.tar.xz else echo "Error: base_image must be a .yaml manifest or .tar.xz" exit 1 fi -# Find the rootfs image - look for the largest .img.xz file or one with "rootfs" in name -ROOTFS_IMG_XZ="" - -# First try to find a file with "rootfs" in the name -for file in *.img.xz; do - if [[ "$file" == *"rootfs"* ]]; then - ROOTFS_IMG_XZ="$file" - echo "Found rootfs image by name: $ROOTFS_IMG_XZ" - break - fi -done +# Find the rootfs image - look for the largest .img.xz or .img file +ROOTFS_IMG="" # If not found, use the largest .img.xz file -if [ -z "$ROOTFS_IMG_XZ" ]; then - ROOTFS_IMG_XZ=$(ls -S *.img.xz 2>/dev/null | head -n1) - echo "Using largest .img.xz file as rootfs: $ROOTFS_IMG_XZ" -fi +ROOTFS_IMG="${ROOTFS_IMG:-$(find . -type f \( -name '*.img.xz' -o -name '*.img' \) -exec ls -s {} + 2>/dev/null | sort -rn | head -n1 | awk '{print $2}')}" +[ -n "$ROOTFS_IMG" ] && echo "Using largest .img.xz or .img file as rootfs: $ROOTFS_IMG" -if [ -z "$ROOTFS_IMG_XZ" ] || [ ! -f "$ROOTFS_IMG_XZ" ]; then +if [ -z "$ROOTFS_IMG" ] || [ ! -f "$ROOTFS_IMG" ]; then echo "Error: Could not find a suitable rootfs image file" echo "Available files:" ls -la exit 1 fi -ROOTFS_IMG="${ROOTFS_IMG_XZ%.xz}" - -echo "Extracting rootfs image: $ROOTFS_IMG_XZ" -xz -d "$ROOTFS_IMG_XZ" +# Only extract if ROOTFS_IMG is an .img.xz file +if [[ "$ROOTFS_IMG" == *.img.xz ]]; then + ROOTFS_IMG_XZ="$ROOTFS_IMG" + ROOTFS_IMG="${ROOTFS_IMG_XZ%.xz}" + echo "Extracting rootfs image: $ROOTFS_IMG_XZ" + xz -d "$ROOTFS_IMG_XZ" +fi if [ ! -f "$ROOTFS_IMG" ]; then - echo "Error: Failed to extract $ROOTFS_IMG" + echo "Error: Root filesystem image not found: $ROOTFS_IMG" + echo "Available files:" + ls -la exit 1 fi