From 1f6208801b48dacfd650f91930bc9b5443803fc3 Mon Sep 17 00:00:00 2001 From: samfreund Date: Fri, 10 Oct 2025 01:56:26 -0500 Subject: [PATCH 1/5] search recursively within directories for image --- mount_rubikpi3.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/mount_rubikpi3.sh b/mount_rubikpi3.sh index d4f80271..617820a5 100644 --- a/mount_rubikpi3.sh +++ b/mount_rubikpi3.sh @@ -39,7 +39,7 @@ 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 @@ -48,19 +48,15 @@ fi 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 +for file in $(find . -type f -name '*rootfs*.img.xz' -o -name '*rootfs*.img'); do + ROOTFS_IMG_XZ="$file" + echo "Found rootfs image by name: $ROOTFS_IMG_XZ" + break done # 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_XZ="${ROOTFS_IMG_XZ:-$(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_XZ" ] && echo "Using largest .img.xz file as rootfs: $ROOTFS_IMG_XZ" if [ -z "$ROOTFS_IMG_XZ" ] || [ ! -f "$ROOTFS_IMG_XZ" ]; then echo "Error: Could not find a suitable rootfs image file" From 587fd76e30f0ba4a0a42975cfaf47a762731fa55 Mon Sep 17 00:00:00 2001 From: samfreund Date: Fri, 10 Oct 2025 08:40:16 -0500 Subject: [PATCH 2/5] remove unnecessary search --- mount_rubikpi3.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mount_rubikpi3.sh b/mount_rubikpi3.sh index 617820a5..e4fcd694 100644 --- a/mount_rubikpi3.sh +++ b/mount_rubikpi3.sh @@ -47,13 +47,6 @@ 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 $(find . -type f -name '*rootfs*.img.xz' -o -name '*rootfs*.img'); do - ROOTFS_IMG_XZ="$file" - echo "Found rootfs image by name: $ROOTFS_IMG_XZ" - break -done - # If not found, use the largest .img.xz file ROOTFS_IMG_XZ="${ROOTFS_IMG_XZ:-$(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_XZ" ] && echo "Using largest .img.xz file as rootfs: $ROOTFS_IMG_XZ" From 82bb8ab8498fe89e567a787d289cf612da5abcee Mon Sep 17 00:00:00 2001 From: samfreund Date: Fri, 10 Oct 2025 08:45:13 -0500 Subject: [PATCH 3/5] conditional image extraction --- mount_rubikpi3.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/mount_rubikpi3.sh b/mount_rubikpi3.sh index e4fcd694..b0c51ddf 100644 --- a/mount_rubikpi3.sh +++ b/mount_rubikpi3.sh @@ -44,27 +44,32 @@ 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="" +# Find the rootfs image - look for the largest .img.xz or .img file +ROOTFS_IMG="" # If not found, use the largest .img.xz file -ROOTFS_IMG_XZ="${ROOTFS_IMG_XZ:-$(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_XZ" ] && echo "Using largest .img.xz file as rootfs: $ROOTFS_IMG_XZ" +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 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 From b5add7777cf2ea6a2e19579ded292500e6b4eff6 Mon Sep 17 00:00:00 2001 From: samfreund Date: Fri, 10 Oct 2025 08:52:46 -0500 Subject: [PATCH 4/5] proper grouping for find --- mount_rubikpi3.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mount_rubikpi3.sh b/mount_rubikpi3.sh index b0c51ddf..e6347eaf 100644 --- a/mount_rubikpi3.sh +++ b/mount_rubikpi3.sh @@ -48,7 +48,7 @@ fi ROOTFS_IMG="" # If not found, use the largest .img.xz file -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}')}" +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 file as rootfs: $ROOTFS_IMG" if [ -z "$ROOTFS_IMG" ] || [ ! -f "$ROOTFS_IMG" ]; then From 95ec180fbd1447a8d2e36b654d1981e65c187dff Mon Sep 17 00:00:00 2001 From: samfreund Date: Fri, 10 Oct 2025 08:52:46 -0500 Subject: [PATCH 5/5] proper grouping for find --- mount_rubikpi3.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mount_rubikpi3.sh b/mount_rubikpi3.sh index e6347eaf..2340b8d4 100644 --- a/mount_rubikpi3.sh +++ b/mount_rubikpi3.sh @@ -49,7 +49,7 @@ ROOTFS_IMG="" # If not found, use the largest .img.xz file 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 file as rootfs: $ROOTFS_IMG" +[ -n "$ROOTFS_IMG" ] && echo "Using largest .img.xz or .img file as rootfs: $ROOTFS_IMG" if [ -z "$ROOTFS_IMG" ] || [ ! -f "$ROOTFS_IMG" ]; then echo "Error: Could not find a suitable rootfs image file"