From 3869788bac47907ceee437f7c52d37a4cdc5815b Mon Sep 17 00:00:00 2001 From: Michael Chus Date: Wed, 1 Apr 2026 07:24:05 +0300 Subject: [PATCH] fix(iso): validate memtest with xorriso fallback --- iso/builder/build.sh | 55 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/iso/builder/build.sh b/iso/builder/build.sh index c180a29..400a991 100755 --- a/iso/builder/build.sh +++ b/iso/builder/build.sh @@ -111,6 +111,45 @@ resolve_iso_version() { resolve_audit_version } +iso_list_files() { + iso_path="$1" + + if command -v bsdtar >/dev/null 2>&1; then + bsdtar -tf "$iso_path" + return $? + fi + + if command -v xorriso >/dev/null 2>&1; then + xorriso -indev "$iso_path" -find / -type f -print 2>/dev/null | sed 's#^/##' + return $? + fi + + return 127 +} + +iso_extract_file() { + iso_path="$1" + iso_member="$2" + + if command -v bsdtar >/dev/null 2>&1; then + bsdtar -xOf "$iso_path" "$iso_member" + return $? + fi + + if command -v xorriso >/dev/null 2>&1; then + xorriso -osirrox on -indev "$iso_path" -cat "/$iso_member" 2>/dev/null + return $? + fi + + return 127 +} + +require_iso_reader() { + command -v bsdtar >/dev/null 2>&1 && return 0 + command -v xorriso >/dev/null 2>&1 && return 0 + memtest_fail "ISO reader is required for validation/debug (expected bsdtar or xorriso)" "${1:-}" +} + dump_memtest_debug() { phase="$1" lb_dir="${2:-}" @@ -174,13 +213,13 @@ dump_memtest_debug() { if [ -n "$iso_path" ] && [ -f "$iso_path" ]; then echo "-- ISO memtest files --" - bsdtar -tf "$iso_path" | grep 'memtest' | sed 's/^/ /' || echo " (no memtest files in ISO)" + iso_list_files "$iso_path" | grep 'memtest' | sed 's/^/ /' || echo " (no memtest files in ISO)" echo "-- ISO GRUB memtest lines --" - bsdtar -xOf "$iso_path" boot/grub/grub.cfg 2>/dev/null | grep -n 'Memory Test\|memtest' || echo " (no memtest lines in boot/grub/grub.cfg)" + iso_extract_file "$iso_path" boot/grub/grub.cfg 2>/dev/null | grep -n 'Memory Test\|memtest' || echo " (no memtest lines in boot/grub/grub.cfg)" echo "-- ISO isolinux memtest lines --" - bsdtar -xOf "$iso_path" isolinux/live.cfg 2>/dev/null | grep -n 'Memory Test\|memtest' || echo " (no memtest lines in isolinux/live.cfg)" + iso_extract_file "$iso_path" isolinux/live.cfg 2>/dev/null | grep -n 'Memory Test\|memtest' || echo " (no memtest lines in isolinux/live.cfg)" fi echo "=== end memtest debug: ${phase} ===" @@ -206,20 +245,20 @@ validate_iso_memtest() { echo "=== validating memtest in ISO ===" [ -f "$iso_path" ] || memtest_fail "ISO not found for validation: $iso_path" "$iso_path" - command -v bsdtar >/dev/null 2>&1 || memtest_fail "bsdtar is required for ISO validation" "$iso_path" + require_iso_reader "$iso_path" - bsdtar -tf "$iso_path" | grep -q '^boot/memtest86+x64\.bin$' || { + iso_list_files "$iso_path" | grep -q '^boot/memtest86+x64\.bin$' || { memtest_fail "memtest BIOS binary missing in ISO: boot/memtest86+x64.bin" "$iso_path" } - bsdtar -tf "$iso_path" | grep -q '^boot/memtest86+x64\.efi$' || { + iso_list_files "$iso_path" | grep -q '^boot/memtest86+x64\.efi$' || { memtest_fail "memtest EFI binary missing in ISO: boot/memtest86+x64.efi" "$iso_path" } grub_cfg="$(mktemp)" isolinux_cfg="$(mktemp)" - bsdtar -xOf "$iso_path" boot/grub/grub.cfg > "$grub_cfg" || memtest_fail "failed to extract boot/grub/grub.cfg from ISO" "$iso_path" - bsdtar -xOf "$iso_path" isolinux/live.cfg > "$isolinux_cfg" || memtest_fail "failed to extract isolinux/live.cfg from ISO" "$iso_path" + iso_extract_file "$iso_path" boot/grub/grub.cfg > "$grub_cfg" || memtest_fail "failed to extract boot/grub/grub.cfg from ISO" "$iso_path" + iso_extract_file "$iso_path" isolinux/live.cfg > "$isolinux_cfg" || memtest_fail "failed to extract isolinux/live.cfg from ISO" "$iso_path" grep -q 'Memory Test (memtest86+)' "$grub_cfg" || { memtest_fail "GRUB menu entry for memtest is missing" "$iso_path"