Introduced option -dummy and enabled real unmounting
This commit is contained in:
parent
e36596b8d4
commit
81272c80ca
@ -60,6 +60,8 @@ print_usage() {
|
||||
echo "one advisable device is listed, it really gets overwritten by the"
|
||||
echo "file content of the given -image_file. In this case the exit value"
|
||||
echo "is zero if writing succeeded, non-zero else."
|
||||
echo "Option -dummy prevents this kind of real action and rather shows the"
|
||||
echo "unmount and write commands on stdout."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -list_all Print list of all found devices with advice, vendor"
|
||||
@ -90,7 +92,8 @@ print_usage() {
|
||||
echo " is found, then they get listed but no writing"
|
||||
echo " happens. In this case, re-run with one of the"
|
||||
echo " advised device names to get a real write run."
|
||||
echo
|
||||
echo " -dummy Report the -DO_WRITE actions but do not perform"
|
||||
echo " them."
|
||||
echo " -help Print this text to stdout and then end the program."
|
||||
echo "Examples:"
|
||||
echo " $0 -with_sudo -list_all"
|
||||
@ -119,6 +122,7 @@ reset_job() {
|
||||
with_sudo=
|
||||
image_file=
|
||||
do_write=
|
||||
dummy_run=
|
||||
|
||||
# Status
|
||||
sudo_cmd=
|
||||
@ -173,6 +177,9 @@ arg_interpreter() {
|
||||
elif test "$i" = "-image_file"
|
||||
then
|
||||
next_is="image_file"
|
||||
elif test "$i" = "-dummy"
|
||||
then
|
||||
dummy_run=y
|
||||
elif test "$i" = "-DO_WRITE"
|
||||
then
|
||||
do_write=y
|
||||
@ -402,13 +409,16 @@ list_devices() {
|
||||
|
||||
write_image() {
|
||||
|
||||
echo "--- not activated yet ---"
|
||||
|
||||
if test -z "$umount_cmd"
|
||||
then
|
||||
echo "No executable program umount found in: $sudo_x_dir_list" >&2
|
||||
return 6
|
||||
fi
|
||||
if test -n "$dummy_run"
|
||||
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=
|
||||
@ -421,17 +431,37 @@ write_image() {
|
||||
done
|
||||
if test -n "$mounted_devs"
|
||||
then
|
||||
echo "Would do: $sudo_cmd $umount_cmd $mounted_devs"
|
||||
for i in $mounted_devs
|
||||
do
|
||||
if test -n "$dummy_run"
|
||||
then
|
||||
echo " $sudo_cmd $umount_cmd $i"
|
||||
else
|
||||
if $sudo_cmd $umount_cmd "$i"
|
||||
then
|
||||
echo "Unmounted: $i"
|
||||
else
|
||||
echo "FAILURE: Non-zero exit value with: sudo_cmd $umount_cmd $i" >&2
|
||||
return 7
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
if test -z "$dd_cmd"
|
||||
then
|
||||
echo "No executable program dd found in: $sudo_x_dir_list" >&2
|
||||
return 6
|
||||
fi
|
||||
echo "Would do: $sudo_cmd $dd_cmd if='${1}' bs=1M of=/dev/${2} ; sync"
|
||||
|
||||
echo "--- not activated yet ---"
|
||||
if test -n "$dummy_run"
|
||||
then
|
||||
echo " $sudo_cmd $dd_cmd if='${1}' bs=1M of=/dev/${2} ; sync"
|
||||
else
|
||||
echo "--- not activated yet ---"
|
||||
echo "Would do: $sudo_cmd $dd_cmd if='${1}' bs=1M of=/dev/${2} ; sync"
|
||||
echo "--- not activated yet ---"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user