Excluding loop devices from being considered

This commit is contained in:
Thomas Schmitt 2019-12-06 09:25:50 +01:00
parent 98c301e7b9
commit 3ac5dba1c7

View File

@ -261,6 +261,17 @@ arg_interpreter() {
fi fi
} }
## Obtain a blank separated list of top-level names which do not look like
## CD, floppy, RAM dev, or loop device.
collect_devices() {
"$lsblk_cmd" -d -n -o NAME \
| grep -v '^sr[0-9]' \
| grep -v '^fd[0-9]' \
| grep -v '^zram[0-9]' \
| grep -v '^loop[0-9]' \
| tr '\n\r' ' '
}
## Trying to find the desired device by watching plug-in effects ## Trying to find the desired device by watching plug-in effects
plug_in_watcher() { plug_in_watcher() {
found_devices= found_devices=
@ -274,7 +285,7 @@ plug_in_watcher() {
echo "and then unplug it." >&2 echo "and then unplug it." >&2
echo "Press the Enter key when ready." >&2 echo "Press the Enter key when ready." >&2
read dummy read dummy
old_device_list=' '$("$lsblk_cmd" -d -n -o NAME | grep -v '^sr[0-9]' | grep -v '^fd[0-9]' | tr '\n\r' ' ')' ' old_device_list=' '$(collect_devices)' '
# <<< Mock-up to save USB socket wear-off by erasing items from old_device_list # <<< Mock-up to save USB socket wear-off by erasing items from old_device_list
# <<< Their presence in new_device_list will let them appear as fresh plugs # <<< Their presence in new_device_list will let them appear as fresh plugs
@ -289,7 +300,7 @@ plug_in_watcher() {
end_time="$(expr $(date +'%s') + 10)" end_time="$(expr $(date +'%s') + 10)"
while test $(date +'%s') -le "$end_time" while test $(date +'%s') -le "$end_time"
do do
new_device_list=' '$("$lsblk_cmd" -d -n -o NAME | grep -v '^sr[0-9]' | grep -v '^fd[0-9]' | tr '\n\r' ' ')' ' new_device_list=' '$(collect_devices)' '
if test "$old_device_list" = "$new_device_list" if test "$old_device_list" = "$new_device_list"
then then
sleep 1 sleep 1
@ -345,8 +356,7 @@ list_devices() {
if test -z "$devs" if test -z "$devs"
then then
# Obtain list of top-level names which do not look like CD, floppy, RAM dev # Obtain list of top-level names which do not look like CD, floppy, RAM dev
devs=$("$lsblk_cmd" -d -n -o NAME | grep -v '^sr[0-9]' \ devs=$(collect_devices)
| grep -v '^fd[0-9]' | grep -v '^zram[0-9]')
fi fi
not_advised=0 not_advised=0
@ -692,7 +702,12 @@ then
write_image "$image_file" $candidates write_image "$image_file" $candidates
exit $? exit $?
else else
echo "Would write to /dev/$candidates if an -image_file were given." if test -n "$dummy_run"
then
echo "Would simulate writing to /dev/$candidates if an -image_file were given."
else
echo "Would write to /dev/$candidates if an -image_file were given."
fi
exit 0 exit 0
fi fi
elif test "$num_cand" -gt 1 elif test "$num_cand" -gt 1