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

This commit is contained in:
Thomas Schmitt 2022-06-17 10:22:27 +02:00
parent 65c63cc1cf
commit 34981b1278
2 changed files with 122 additions and 42 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# Copyright 2022 Thomas Schmitt <scdbackup@gmx.net> , libburnia project. # Copyright 2022 Thomas Schmitt <scdbackup@gmx.net> , libburnia project.
# Provided under BSD license: Use, modify, and distribute as you like. # 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 "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 "if they are needed and do not exist when the script starts." >&2
echo "It depends on the following programs:" >&2 echo "It depends on the following programs:" >&2
echo " awk, basename, bash, cat, chmod, cp, dirname, expr, fgrep, grep," >&2 echo " awk, basename, cat, chmod, cp, dirname, expr, fgrep, grep," >&2
echo " gunzip, gzip, head, ls, mkdir, mount, mv, rm, rmdir, sha256sum," >&2 echo " gunzip, gzip, head, ls, mkdir, mount, mv, rm, rmdir, sed, sh," >&2
echo " sed, sort, stat, sudo, umount, xorriso" >&2 echo " sha256sum, sort, stat, sudo, umount, xorriso" >&2
echo "Recommended are: md5sum, sha1sum, sha512sum" >&2 echo "Recommended are: md5sum, sha1sum, sha512sum" >&2
echo >&2 echo >&2
echo "Exported non-empty variable MERGE_DATE enforces a particular" >&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 "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 "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 "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 >&2
echo "Example using GNU xorriso-1.5.4 instead of /usr/bin/xorriso:" >&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 " mkdir merge_mount" >&2
echo " $(basename "$0") merged.iso merge_mount/iso "'\' >&2 echo " $(basename "$0") merged.iso merge_mount/iso "'\' >&2
echo " debian-11.2.0-amd64-DVD-[12345].iso" >&2 echo " debian-11.2.0-amd64-DVD-[12345].iso" >&2
@ -51,15 +52,28 @@ check_single_word() {
then then
empty=0 empty=0
else else
echo "--- Argument $2 is not a single word:" >&2 if test "$2" = "dists"
echo "--- '${1}'" >&2 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 return 1
fi fi
done done
if test "$empty" = 1 if test "$empty" = 1
then then
echo "--- Argument $2 is empty or entirely white space:" >&2 if test "$2" = "dists"
echo "--- '${1}'" >&2 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 return 1
fi fi
return 0 return 0
@ -70,10 +84,34 @@ UMOUNT_LIST=
RMDIR_LIST= RMDIR_LIST=
TEMPFILE_LIST="merged_dists merged_md5sum.txt merged_README.txt temp_file" 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 temporary files, mount points and made directories
cleanup_ran=0
cleanup_and_end() { cleanup_and_end() {
# Remove trap # 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 >&2
echo "Cleaning up temporary files and mount points ..." 2>&1 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 echo "--- Cleanup could not be fully completed." >&2
fi fi
if test -n "$1" # Might exit
then finish_cleanup "$1"
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 $ret return $ret
} }
## Check arguments
# +++ No cleanup_and_end before TEMPFILE_LIST is verified to be missing +++ # +++ No cleanup_and_end before TEMPFILE_LIST is verified to be missing +++
## Check arguments and dependencies
if test "$#" -lt 4 if test "$#" -lt 4
then then
usage usage
@ -151,6 +181,53 @@ fi
echo >&2 echo >&2
echo "$(basename "$0") starting with $(expr $# - 2) ISO image files ..." >&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= existing_tempfiles=
for i in $TEMPFILE_LIST for i in $TEMPFILE_LIST
do do
@ -169,7 +246,7 @@ then
fi fi
# +++ From here on: Always call cleanup_and_end to perform exit +++ # +++ 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" RESULT_ISO="$1"
check_single_word "$2" "result_iso" || cleanup_and_end 1 check_single_word "$2" "result_iso" || cleanup_and_end 1
@ -342,7 +419,7 @@ extract_checksum_paths() {
cat "$1" | \ cat "$1" | \
while true while true
do do
read x || break read -r x || break
if test "$x" = "MD5Sum:" || test "$x" = "SHA1:" \ if test "$x" = "MD5Sum:" || test "$x" = "SHA1:" \
|| test "$x" = "SHA256:" || test "$x" = "SHA512:" || test "$x" = "SHA256:" || test "$x" = "SHA512:"
then then
@ -365,7 +442,7 @@ extract_release_head() {
cat "$1" | \ cat "$1" | \
while true while true
do do
read x || break read -r x || break
if test "$x" = "MD5Sum:" || test "$x" = "SHA1:" \ if test "$x" = "MD5Sum:" || test "$x" = "SHA1:" \
|| test "$x" = "SHA256:" || test "$x" = "SHA512:" || test "$x" = "SHA256:" || test "$x" = "SHA512:"
then then
@ -381,8 +458,14 @@ echo >&2
echo "Determining Debian release in first ISO ..." >&2 echo "Determining Debian release in first ISO ..." >&2
dist= dist=
for i in $(ls -1d "$mount_point_1"/dists/*) for i in "$mount_point_1"/dists/*
do do
if check_single_word "$i" "dists"
then
dummy=dummy
else
continue
fi
if test -d "$i" if test -d "$i"
then then
if test -L "$i" if test -L "$i"
@ -390,7 +473,7 @@ do
continue continue
fi fi
test -n "$dist" && dist="$dist " test -n "$dist" && dist="$dist "
dist="${dist}$(basename $i)" dist="${dist}$(basename "$i")"
fi fi
done done
if test -z "$dist" if test -z "$dist"
@ -446,7 +529,7 @@ then
MERGE_DATE=$(date +'%Y%m%d-%H:%M') MERGE_DATE=$(date +'%Y%m%d-%H:%M')
fi fi
printf 'Result of a run of %s at %s\r\n' \ 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 '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 'The other files stem from the first input ISO.\r\n' >>temp_file
printf '\r\n' >>temp_file printf '\r\n' >>temp_file
@ -564,7 +647,7 @@ do
continue continue
fi fi
list_path=$(echo "$file" | sed -e 's/^merged_dists\/'"$dist"'\///') 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 done
fi fi
done >>temp_file done >>temp_file
@ -582,7 +665,6 @@ for mount_point in $MOUNT_LIST
do do
if test "$mount_point" = "$mount_point_1" if test "$mount_point" = "$mount_point_1"
then then
dummy=dummy
echo "Planned as imported package pool : ${mount_point}/pool" >&2 echo "Planned as imported package pool : ${mount_point}/pool" >&2
else else
echo "Planned for merging into package pool: ${mount_point}/pool" >&2 echo "Planned for merging into package pool: ${mount_point}/pool" >&2
@ -590,17 +672,14 @@ do
fi fi
done done
if test -z "$XORRISO" if test "$XORRISO" = dummy
then then
XORRISO=xorriso echo >&2
fi echo 'NOTE: Variable XORRISO is set to "dummy".' >&2
echo ' Will not perform xorriso run but only show its arguments:' >&2
x=$(type -p "$XORRISO") XORRISO=echo
if test -z "$x"
then
echo "Running as xorriso program: $XORRISO" >&2
else else
echo "Running as xorriso program: $x" >&2 echo "Running as xorriso program: $XORRISO" >&2
fi fi
echo >&2 echo >&2
@ -621,9 +700,10 @@ if "$XORRISO" \
-padding included \ -padding included \
-compliance no_emul_toc -compliance no_emul_toc
then 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 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 cleanup_and_end 4
fi fi

Binary file not shown.