From 9e79f64cae13ddad24d5ac79c3364baa330ae9e7 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 19 Jul 2022 15:57:29 +0200 Subject: [PATCH] Automatically creating mount parent directory in merge_debian_isos --- test/merge_debian_isos | 49 ++++++++++++++++++++++++++++--------- test/merge_debian_isos.sig | Bin 72 -> 72 bytes 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/test/merge_debian_isos b/test/merge_debian_isos index 5aa66137..3b752f2b 100755 --- a/test/merge_debian_isos +++ b/test/merge_debian_isos @@ -27,7 +27,9 @@ usage() { echo "xorriso will be run under sudo, if xorriso-dd-target agrees and" >&2 echo 'the user confirms by input "yes".' >&2 echo >&2 - echo "At least the parent directory of mount_template must already exist." >&2 + echo "At least the parent directory of mount_template must already exist" >&2 + echo 'or has to be given by a plain name without "/" so that it can be' >&2 + echo 'created in the current directory. (I.e. without even "./".)' >&2 echo "All arguments must be single words without using quotation marks." >&2 echo "None of the isoN must be equal to another isoM." >&2 echo >&2 @@ -36,11 +38,16 @@ usage() { echo " ./merged_dists , ./merged_md5sum.txt , ./merged_REAMDE.txt" >&2 echo " ./temp_file" >&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 "It depends on the following programs:" >&2 + echo "if they are needed and do not exist when the script starts. If the" >&2 + echo "parent directory in the mount_template path does not exist and" >&2 + echo 'its path contains no "/" then it gets created and finally removed.' >&2 + echo "The script depends on the following programs:" >&2 echo " awk, basename, cat, chmod, cp, date, dirname, expr, fgrep, grep," >&2 echo " gunzip, gzip, head, ls, md5sum, mkdir, mount, mv, rm, rmdir," >&2 echo " sed, sh, sha256sum, sort, stat, sudo, umount, uniq, xorriso" >&2 + echo "With device writing involving helper script xorriso-dd-target:" >&2 + echo " dd, Linux kernel, lsblk, sleep, tr, uname, wc, whoami," >&2 + echo " xorriso-dd-target" >&2 echo "Recommended are: sha1sum, sha512sum" >&2 echo >&2 echo "Exported non-empty variable MERGE_DATE enforces a particular" >&2 @@ -59,29 +66,23 @@ usage() { 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 " mkdir merge_mount" >&2 echo " $(basename "$0") merged.iso merge_mount/iso "'\' >&2 echo " debian-11.2.0-amd64-DVD-[12345].iso" >&2 - echo " rmdir merge_mount" >&2 echo >&2 echo "Example writing to optical drive /dev/sr0 :" >&2 - echo " mkdir merge_mount" >&2 echo " $(basename "$0") mmc:/dev/sr0 merge_mount/iso "'\' >&2 echo " debian-11.2.0-amd64-DVD-[12345].iso" >&2 - echo " rmdir merge_mount" >&2 echo >&2 echo \ "Example on Linux writing to USB stick with xorriso-dd-target-plug-test:" >&2 echo " wget https://dev.lovelyhq.com/libburnia/libisoburn/raw/master/xorriso-dd-target/xorriso-dd-target" >&2 echo " chmod u+x xorriso-dd-target" >&2 echo ' export XORRISO_DD_TARGET_PATH="$(pwd)"' >&2 - echo " mkdir merge_mount" >&2 echo " $(basename "$0") xorriso-dd-target-plug-test merge_mount/iso "'\' >&2 echo " debian-11.2.0-amd64-DVD-[12345].iso" >&2 echo "This leads to the first two steps of the xorriso-dd-target device" >&2 echo "plug dialog. See: https://wiki.debian.org/XorrisoDdTarget" >&2 echo 'Finally input "yes" is required to authorize xorriso under sudo.' >&2 - echo " rmdir merge_mount" >&2 } check_single_word() { @@ -520,12 +521,21 @@ fi MOUNT_TEMPLATE="$2" check_single_word "$2" "mount_template" || cleanup_and_end 1 x=$(dirname "$MOUNT_TEMPLATE") +mount_parent_to_make= +mount_parent_made= if test -d "$x" then dummy=dummy else - echo "--- The parent directory of '${MOUNT_TEMPLATE}' does not exist." >&2 - cleanup_and_end 1 + # The parent will be temporarily created only if it is a plain leaf name + if echo " $x" | fgrep / >/dev/null + then + echo "--- The parent directory '${x}' of mount_template does not exist" \ + >&2 + echo "--- and contains a '/' character. Will not create it." >&2 + cleanup_and_end 1 + fi + mount_parent_to_make="$x" fi shift 2 @@ -575,6 +585,17 @@ echo "Arguments look acceptable." >&2 echo >&2 echo "Mounting ISO images if not yet mounted ..." >&2 +if test -n "$mount_parent_to_make" +then + if mkdir "$mount_parent_to_make" + then + mount_parent_made="$mount_parent_to_make" + else + echo "--- Cannot create the parent directory of '${MOUNT_TEMPLATE}'." >&2 + cleanup_and_end 1 + fi +fi + mount_count=0 for i in $ISO_LIST do @@ -630,6 +651,12 @@ do MOUNT_LIST="$MOUNT_LIST $mount_point" done + +if test -n "$mount_parent_made" +then + RMDIR_LIST="$RMDIR_LIST $mount_parent_made " +fi + echo "Done." >&2 echo >&2 diff --git a/test/merge_debian_isos.sig b/test/merge_debian_isos.sig index 713ec218a6de07271ca148e998802645f2e89951..7f7bfa29a44385934777847d516c2d68701d6e30 100644 GIT binary patch literal 72 zcmV-O0Jr~$Mg#y60ssaD0%F#;LI4U05b4X`z^lNhR0YWZpr-_Bx)nmV?ev0x!p0Ob eeGoi!`v9PeYb?S76n%c`s}hW?;N5A6F0KjPP98e| literal 72 zcmV-O0Jr~$Mg#y60ssaD0%FqkPXG!D5b4X`z^lNhR4QixppQQ8k#Bxe+BZNSznXj4 eW^X0ap8%dERfV|h?U)li#qz0FMK9)NsU(^D)gOTX