From 34981b1278610d3f31da90f57fdf1378d6012074 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Fri, 17 Jun 2022 10:22:27 +0200 Subject: [PATCH] Switched test/merge_debian_isos to /bin/sh, added signal handling, fixed harmless flaws found by shellcheck, added more sanity checks, enabled XORRISO=dummy for test runs without ISO production --- test/merge_debian_isos | 164 +++++++++++++++++++++++++++---------- test/merge_debian_isos.sig | Bin 72 -> 72 bytes 2 files changed, 122 insertions(+), 42 deletions(-) diff --git a/test/merge_debian_isos b/test/merge_debian_isos index e28fb015..2714bb7c 100755 --- a/test/merge_debian_isos +++ b/test/merge_debian_isos @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Copyright 2022 Thomas Schmitt , libburnia project. # Provided under BSD license: Use, modify, and distribute as you like. @@ -22,9 +22,9 @@ usage() { echo "Further it creates and finally removes directories mount_template*" >&2 echo "if they are needed and do not exist when the script starts." >&2 echo "It depends on the following programs:" >&2 - echo " awk, basename, bash, cat, chmod, cp, dirname, expr, fgrep, grep," >&2 - echo " gunzip, gzip, head, ls, mkdir, mount, mv, rm, rmdir, sha256sum," >&2 - echo " sed, sort, stat, sudo, umount, xorriso" >&2 + echo " awk, basename, cat, chmod, cp, dirname, expr, fgrep, grep," >&2 + echo " gunzip, gzip, head, ls, mkdir, mount, mv, rm, rmdir, sed, sh," >&2 + echo " sha256sum, sort, stat, sudo, umount, xorriso" >&2 echo "Recommended are: md5sum, sha1sum, sha512sum" >&2 echo >&2 echo "Exported non-empty variable MERGE_DATE enforces a particular" >&2 @@ -34,9 +34,10 @@ usage() { echo "such directory is found and thus no need to set MERGE_FOR_DIST." >&2 echo "Exported non-empty variable XORRISO overrides command xorriso." >&2 echo "This may be needed if installed xorriso is older than 1.4.2." >&2 + echo 'If XORRISO is set to "dummy" then no new ISO will emerge.' >&2 echo >&2 echo "Example using GNU xorriso-1.5.4 instead of /usr/bin/xorriso:" >&2 - echo " export XORRISO="'$HOME'"/xorriso-1.5.4/xorriso/xorriso" >&2 + echo " export XORRISO="'"$HOME"'"/xorriso-1.5.4/xorriso/xorriso" >&2 echo " mkdir merge_mount" >&2 echo " $(basename "$0") merged.iso merge_mount/iso "'\' >&2 echo " debian-11.2.0-amd64-DVD-[12345].iso" >&2 @@ -51,15 +52,28 @@ check_single_word() { then empty=0 else - echo "--- Argument $2 is not a single word:" >&2 - echo "--- '${1}'" >&2 + if test "$2" = "dists" + then + echo "WARNING: A file name in /dists is not a single word:" >&2 + echo " '${1}'" >&2 + else + echo "--- Argument $2 is not a single word:" >&2 + echo "--- '${1}'" >&2 + fi return 1 fi done if test "$empty" = 1 then - echo "--- Argument $2 is empty or entirely white space:" >&2 - echo "--- '${1}'" >&2 + if test "$2" = "dists" + then + echo "WARNING: A file name in /dists is empty or entirely white space:" \ + >&2 + echo " '${1}'" >&2 + else + echo "--- Argument $2 is empty or entirely white space:" >&2 + echo "--- '${1}'" >&2 + fi return 1 fi return 0 @@ -70,10 +84,34 @@ UMOUNT_LIST= RMDIR_LIST= TEMPFILE_LIST="merged_dists merged_md5sum.txt merged_README.txt temp_file" +finish_cleanup() { + if test -n "$1" + then + echo >&2 + if test "$1" -gt 0 + then + echo "--- Merge run aborted !" >&2 + else + echo "Merge run ended with success indication." >&2 + fi + exit "$1" + fi + return 0 +} + # Cleanup temporary files, mount points and made directories +cleanup_ran=0 + cleanup_and_end() { # Remove trap - trap EXIT + trap - INT TERM QUIT EXIT + + if test "$cleanup_ran" = 1 + then + finish_cleanup "$1" + return 0 + fi + cleanup_ran=1 echo >&2 echo "Cleaning up temporary files and mount points ..." 2>&1 @@ -122,26 +160,18 @@ cleanup_and_end() { echo "--- Cleanup could not be fully completed." >&2 fi - if test -n "$1" - then - echo >&2 - if test "$1" -gt 0 - then - echo "--- Merge run aborted !" >&2 - else - echo "Merge run ended with success indication." >&2 - fi - exit "$1" - fi + # Might exit + finish_cleanup "$1" return $ret } -## Check arguments - # +++ No cleanup_and_end before TEMPFILE_LIST is verified to be missing +++ + +## Check arguments and dependencies + if test "$#" -lt 4 then usage @@ -151,6 +181,53 @@ fi echo >&2 echo "$(basename "$0") starting with $(expr $# - 2) ISO image files ..." >&2 +dep="awk basename cat chmod cp dirname expr fgrep grep" +dep="$dep gunzip gzip head ls mkdir mount mv rm rmdir sed" +dep="$dep sha256sum sort stat sudo umount" +missing=0 +for i in $dep +do + if type "$i" >/dev/null 2>&1 + then + dummy=dummy + else + echo "--- Missing a helper program: $i" 2>&1 + missing=1 + fi +done +if test -z "$XORRISO" +then + XORRISO=xorriso +fi +if test "$XORRISO" = dummy +then + echo 'NOTE: Variable XORRISO is set to "dummy".' >&2 + echo ' Will not perform xorriso run but only show its arguments.' >&2 +elif "$XORRISO" -no_rc -version >/dev/null 2>&1 +then + if "$XORRISO" -no_rc -help 2>/dev/null | fgrep '"replay"' >/dev/null 2>&1 + then + dummy=dummy + else + echo '--- Help text of xorriso program '"$XORRISO"' lacks word "replay".' \ + 2>&1 + echo "--- It will fail when trying to make the new ISO bootable." 2>&1 + echo " Consider to get and compile GNU xorriso from" 2>&1 + echo " https://www.gnu.org/software/xorriso" 2>&1 + echo " and to export variable XORRISO with the binary's path." 2>&1 + echo >&2 + missing=1 + fi +else + echo "--- Test run of xorriso program failed: $XORRISO -no_rc -version" 2>&1 + missing=1 +fi +if test "$missing" = 1 +then + echo "--- Merge run aborted !" >&2 + exit 5 +fi + existing_tempfiles= for i in $TEMPFILE_LIST do @@ -169,7 +246,7 @@ then fi # +++ From here on: Always call cleanup_and_end to perform exit +++ -trap cleanup_and_end EXIT +trap cleanup_and_end INT TERM QUIT EXIT RESULT_ISO="$1" check_single_word "$2" "result_iso" || cleanup_and_end 1 @@ -342,7 +419,7 @@ extract_checksum_paths() { cat "$1" | \ while true do - read x || break + read -r x || break if test "$x" = "MD5Sum:" || test "$x" = "SHA1:" \ || test "$x" = "SHA256:" || test "$x" = "SHA512:" then @@ -365,7 +442,7 @@ extract_release_head() { cat "$1" | \ while true do - read x || break + read -r x || break if test "$x" = "MD5Sum:" || test "$x" = "SHA1:" \ || test "$x" = "SHA256:" || test "$x" = "SHA512:" then @@ -381,8 +458,14 @@ echo >&2 echo "Determining Debian release in first ISO ..." >&2 dist= -for i in $(ls -1d "$mount_point_1"/dists/*) +for i in "$mount_point_1"/dists/* do + if check_single_word "$i" "dists" + then + dummy=dummy + else +continue + fi if test -d "$i" then if test -L "$i" @@ -390,7 +473,7 @@ do continue fi test -n "$dist" && dist="$dist " - dist="${dist}$(basename $i)" + dist="${dist}$(basename "$i")" fi done if test -z "$dist" @@ -446,7 +529,7 @@ then MERGE_DATE=$(date +'%Y%m%d-%H:%M') fi printf 'Result of a run of %s at %s\r\n' \ - "$(basename $0)" "$MERGE_DATE" >temp_file + "$(basename "$0")" "$MERGE_DATE" >temp_file printf 'Package pools and Packages lists were merged.\r\n' >>temp_file printf 'The other files stem from the first input ISO.\r\n' >>temp_file printf '\r\n' >>temp_file @@ -564,7 +647,7 @@ do continue fi list_path=$(echo "$file" | sed -e 's/^merged_dists\/'"$dist"'\///') - printf ' %s %8ld %s\n' "$sum" "$size" "$list_path" + printf ' %s %8d %s\n' "$sum" "$size" "$list_path" done fi done >>temp_file @@ -582,7 +665,6 @@ for mount_point in $MOUNT_LIST do if test "$mount_point" = "$mount_point_1" then - dummy=dummy echo "Planned as imported package pool : ${mount_point}/pool" >&2 else echo "Planned for merging into package pool: ${mount_point}/pool" >&2 @@ -590,17 +672,14 @@ do fi done -if test -z "$XORRISO" +if test "$XORRISO" = dummy then - XORRISO=xorriso -fi - -x=$(type -p "$XORRISO") -if test -z "$x" -then - echo "Running as xorriso program: $XORRISO" >&2 + echo >&2 + echo 'NOTE: Variable XORRISO is set to "dummy".' >&2 + echo ' Will not perform xorriso run but only show its arguments:' >&2 + XORRISO=echo else - echo "Running as xorriso program: $x" >&2 + echo "Running as xorriso program: $XORRISO" >&2 fi echo >&2 @@ -621,9 +700,10 @@ if "$XORRISO" \ -padding included \ -compliance no_emul_toc then - echo "Run of xorriso program completed without error indication." >&2 + test "$XORRISO" = echo || \ + echo "Run of xorriso program ended without error indication." >&2 else - echo "--- Run of xorriso program ended with problem indication." >&2 + echo "--- Run of xorriso program ended with error indication." >&2 cleanup_and_end 4 fi diff --git a/test/merge_debian_isos.sig b/test/merge_debian_isos.sig index bc03c6b1da98eb608cc421689f885e7bc106b1ae..df8a7822b2b7b095d3857cc932e4157aca4850a2 100644 GIT binary patch literal 72 zcmV-O0Jr~$Mg#y60ssaD0%EI}9RLam5b4X`z^lNhRKgzspFqEwCcSDnsXpAG=dpQI e4h6w%eE^*h3=gp`sV_#z8uW} literal 72 zcmV-O0Jr~$Mg#y60ssaD0%EE=)c^_!5b4X`z^lNhR24)3nE?vx