From a6ab055153d86887a8c9873433c3b0288d217b4d Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 2 Dec 2019 10:56:15 +0100 Subject: [PATCH] Small fixes of problems found while writing documentation --- xorriso-dd-target/xorriso-dd-target | 89 +++++++++++++++-------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/xorriso-dd-target/xorriso-dd-target b/xorriso-dd-target/xorriso-dd-target index 0dbd97ef..210174b0 100755 --- a/xorriso-dd-target/xorriso-dd-target +++ b/xorriso-dd-target/xorriso-dd-target @@ -74,7 +74,7 @@ print_usage() { echo " The found device is then shown with advice, vendor," echo " and model. Option -DO_WRITE is obeyed if given." echo " -list_all Print list of all found devices with advice, vendor" - echo " and model, One per line. Ignore any device names." + echo " and model. One per line. Ignore any device names." echo " Ignore -DO_WRITE." echo " -with_vendor_model Print vendor and model with each submitted device." echo @@ -89,7 +89,6 @@ print_usage() { echo " any further filesystem type is acceptable on that" echo " device. Else only ISO 9660 and VFAT are accepted." echo " -with_sudo Run '$lsblk_cmd -o FSTYPE' by sudo." - echo " If so, consider to enable this without password." echo " If no filesystems are detected and the program" echo " has no superuser power, the device is not advised." echo " If -DO_WRITE is given, run umount and dd by sudo." @@ -230,11 +229,11 @@ arg_interpreter() { have_su_power=y elif test -n "$with_sudo" then - echo "Testing sudo to possibly get password prompting done now:" + echo "Testing sudo to possibly get password prompting done now:" >&2 if sudo $lsblk_cmd -h >/dev/null then - echo "sudo $lsblk_cmd seems ok." - echo + echo "sudo $lsblk_cmd seems ok." >&2 + echo >&2 sudo_cmd=sudo have_su_power=y else @@ -247,13 +246,13 @@ arg_interpreter() { ## Trying to find the desired device by watching plug-in effects plug_in_watcher() { found_devices= - echo - echo "Caused by option -plug_test: Attempt to find the desired device" - echo "by watching it appear after being plugged in." - echo - echo "Step 1:" - echo "Please make sure that the desired target device is plugged _out_ now." - echo "Press the Enter key when ready." + echo >&2 + echo "Caused by option -plug_test: Attempt to find the desired device" >&2 + echo "by watching it appear after being plugged in." >&2 + echo >&2 + echo "Step 1:" >&2 + echo "Please make sure that the desired target device is plugged _out_ now." >&2 + echo "Press the Enter key when ready." >&2 read dummy old_device_list=' '$($lsblk_cmd -d -n -o NAME | grep -v '^sr[0-9]' | grep -v '^fd[0-9]' | tr '\n\r' ' ')' ' @@ -261,12 +260,12 @@ plug_in_watcher() { # <<< Their presence in new_device_list will let them appear as fresh plugs # old_device_list=' '$(echo -n $old_device_list | sed -e 's/sd[e-f]//')' ' - echo "Found and noted as _not_ desired: $old_device_list" - echo - echo "Step 2:" - echo "Please plug in the desired target device and then press the Enter key." + echo "Found and noted as _not_ desired: $old_device_list" >&2 + echo >&2 + echo "Step 2:" >&2 + echo "Please plug in the desired target device and then press the Enter key." >&2 read dummy - echo -n "Waiting up to 10 seconds for a new device to be listed ..." + echo -n "Waiting up to 10 seconds for a new device to be listed ..." >&2 end_time="$(expr $(date +'%s') + 10)" while test $(date +'%s') -le "$end_time" do @@ -274,7 +273,7 @@ plug_in_watcher() { if test "$old_device_list" = "$new_device_list" then sleep 1 - echo -n '.' + echo -n '.' >&2 else for i in $new_device_list do @@ -287,7 +286,7 @@ plug_in_watcher() { done fi done - echo + echo >&2 if test -z "$found_devices" then echo "SORRY: No new candidate device was found." >&2 @@ -296,24 +295,24 @@ plug_in_watcher() { num=$(echo $found_devices | wc -w) if test "$num" -gt 1 then - echo "SORRY: More than one new candidate device appeared: $found_devices" + echo "SORRY: More than one new candidate device appeared: $found_devices" >&2 return 9 fi - echo "Found and noted as desired device: $found_devices" + echo "Found and noted as desired device: $found_devices" >&2 if test -n "$devs" then - echo "(-plug_test is overriding device list given by arguments: $devs )" + echo "(-plug_test is overriding device list given by arguments: $devs )" >&2 fi if test -n "$list_all" then - echo "(-plug_test is overriding -list_all)" + echo "(-plug_test is overriding -list_all)" >&2 list_all= fi devs_named=y with_vendor_model=y show_reasons=y devs=$(echo -n $found_devices) - echo + echo >&2 return 0 } @@ -520,6 +519,21 @@ write_image() { echo "No executable program umount found in: $sudo_x_dir_list" >&2 return 6 fi + + echo "Looking for mount points of $2:" + partitions=$($lsblk_cmd -n -p -o NAME /dev/"$2" | grep -v '^'/dev/"$2"'$' \ + | sed -e 's/[^a-zA-Z0-9_+@:.,/-]//g' | tr '\n\r' ' ') + mounted_devs= + for i in /dev/"$2" $partitions + do + # Show the found mount lines and add their device paths to list + mount_line=$(mount | grep '^'"$i"' ') + if test -n "$mount_line" + then + echo " $mount_line" + mounted_devs="$mounted_devs $i" + fi + done if test -n "$dummy_force" then echo "AGAINST THE ADVICE BY THIS PROGRAM, a daring user could do:" @@ -528,17 +542,6 @@ write_image() { then echo "Would do if not -dummy:" fi - - partitions=$($lsblk_cmd -n -p -o NAME /dev/"$2" | grep -v '^'/dev/"$2"'$' \ - | sed -e 's/[^a-zA-Z0-9_+@:.,/-]//g' | tr '\n\r' ' ') - mounted_devs= - for i in /dev/"$2" $partitions - do - if mount | grep '^'"$i"' ' >/dev/null - then - mounted_devs="$mounted_devs $i" - fi - done if test -n "$mounted_devs" then for i in $mounted_devs @@ -573,6 +576,8 @@ write_image() { echo "--- not activated yet ---" fi + # >>> ??? Erase possible GPT backup table at end of device ? + if test -n "$dummy_force" then echo "BE SMART. BE CAUTIOUS. BEWARE." @@ -606,7 +611,7 @@ then num_devs=$(echo $devs| wc -w) if test -n "$dummy_force" -a "$num_devs" -ne 1 then - echo "SORRY: Refusing -dummy_force with not exactly one device." >&2 + echo "SORRY: Refusing -dummy_force with not exactly one device given." >&2 exit 10 fi if test -n "$dummy_force" -a -n "$dummy_run" -a "$num_cand" -ne 1 @@ -629,19 +634,19 @@ then if test -n "$do_plug_test" then echo - echo "Step 3:" + echo "Step 3:" >&2 if test -n "$dummy_run" then - echo "This would be the last chance to abort. Press Enter to see -dummy report." + echo "This would be the last chance to abort. Press Enter to see -dummy report." >&2 else - echo "Last chance to abort. Press Enter to start REAL WRITING." + echo "Last chance to abort. Press Enter to start REAL WRITING." >&2 fi read dummy fi write_image "$image_file" $candidates exit $? else - echo "Would write to /dev/$candidates if an -image_file were given." >&2 + echo "Would write to /dev/$candidates if an -image_file were given." exit 0 fi elif test "$num_cand" -gt 1 @@ -651,7 +656,7 @@ then with_vendor_model=y devs="$candidates" list_devices >&2 - echo "HINT: Unplug the unwanted devices from the machine," + echo "HINT: Unplug the unwanted devices from the machine," >&2 echo " or work with option -plug_test," >&2 echo " or add the desired name out of {$(echo $candidates | sed -e 's/ /,/g')} as additional argument." >&2 exit 3 @@ -662,7 +667,7 @@ then else echo "NO CANDIDATE FOR TARGET DEVICE FOUND !" >&2 fi - echo "Overall available devices:" + echo "Overall available devices:" >&2 list_all=y show_reasons=y with_vendor_model=y