|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Extract rootfs.squashfs from a release tarball's rootfs.itb file |
| 4 | +# |
| 5 | +# Usage: extract-squashfs.sh <tarball-or-itb-file> [output-file] |
| 6 | +# |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +usage() { |
| 11 | + cat <<EOF |
| 12 | +Usage: $(basename "$0") <tarball-or-itb-file> [output-file] |
| 13 | +
|
| 14 | +Extract rootfs.squashfs from a release tarball or .itb file. |
| 15 | +
|
| 16 | +Arguments: |
| 17 | + <tarball-or-itb-file> Release tarball (*.tar.gz) or rootfs.itb file |
| 18 | + [output-file] Output squashfs file (default: rootfs.squashfs) |
| 19 | +
|
| 20 | +Examples: |
| 21 | + # From release tarball |
| 22 | + $(basename "$0") infix-x86_64-25.09.0.tar.gz |
| 23 | +
|
| 24 | + # From .itb file directly |
| 25 | + $(basename "$0") output/images/rootfs.itb |
| 26 | +
|
| 27 | + # Custom output location |
| 28 | + $(basename "$0") infix-x86_64-25.09.0.tar.gz /tmp/my-rootfs.squashfs |
| 29 | +
|
| 30 | +The script skips the 4096-byte FIT header to extract the SquashFS image. |
| 31 | +EOF |
| 32 | +} |
| 33 | + |
| 34 | +die() { |
| 35 | + echo "ERROR: $*" >&2 |
| 36 | + exit 1 |
| 37 | +} |
| 38 | + |
| 39 | +# Parse arguments |
| 40 | +case "$1" in |
| 41 | + -h|--help) |
| 42 | + usage |
| 43 | + exit 0 |
| 44 | + ;; |
| 45 | + "") |
| 46 | + usage |
| 47 | + exit 1 |
| 48 | + ;; |
| 49 | +esac |
| 50 | + |
| 51 | +input="$1" |
| 52 | +output="${2:-rootfs.squashfs}" |
| 53 | + |
| 54 | +[ -f "$input" ] || die "File not found: $input" |
| 55 | + |
| 56 | +# Detect if input is a tarball or .itb file |
| 57 | +case "$input" in |
| 58 | + *.tar.gz) |
| 59 | + echo "Extracting rootfs.itb from tarball..." |
| 60 | + itb_file=$(tar -tzf "$input" | grep -m1 'rootfs\.itb$') \ |
| 61 | + || die "No rootfs.itb found in tarball" |
| 62 | + |
| 63 | + echo "Found: $itb_file" |
| 64 | + echo "Extracting SquashFS (skipping 4096-byte FIT header)..." |
| 65 | + |
| 66 | + tar -xzOf "$input" "$itb_file" | dd bs=4096 skip=1 of="$output" 2>/dev/null \ |
| 67 | + || die "Failed to extract SquashFS" |
| 68 | + ;; |
| 69 | + *.itb) |
| 70 | + echo "Extracting SquashFS from .itb file (skipping 4096-byte FIT header)..." |
| 71 | + dd if="$input" of="$output" bs=4096 skip=1 2>/dev/null \ |
| 72 | + || die "Failed to extract SquashFS" |
| 73 | + ;; |
| 74 | + *) |
| 75 | + die "Unsupported file type. Expected *.tar.gz or *.itb" |
| 76 | + ;; |
| 77 | +esac |
| 78 | + |
| 79 | +# Verify output |
| 80 | +if [ -f "$output" ]; then |
| 81 | + size=$(stat --format=%s "$output" 2>/dev/null || stat -f%z "$output") |
| 82 | + file_type=$(file "$output") |
| 83 | + |
| 84 | + # Try to format size nicely, fall back to bytes if numfmt not available |
| 85 | + if command -v numfmt >/dev/null 2>&1; then |
| 86 | + size_str=$(numfmt --to=iec-i --suffix=B "$size") |
| 87 | + else |
| 88 | + size_str="$size bytes" |
| 89 | + fi |
| 90 | + |
| 91 | + echo "Success! Created: $output ($size_str)" |
| 92 | + echo "Type: $file_type" |
| 93 | + |
| 94 | + # Quick sanity check for squashfs magic |
| 95 | + if echo "$file_type" | grep -qi squashfs; then |
| 96 | + echo "✓ Verified: Valid SquashFS filesystem" |
| 97 | + else |
| 98 | + echo "⚠ Warning: Output may not be a valid SquashFS image" |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | +else |
| 102 | + die "Failed to create output file" |
| 103 | +fi |
0 commit comments