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
1 changed files with 20 additions and 5 deletions

View File

@ -261,6 +261,17 @@ arg_interpreter() {
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
plug_in_watcher() {
found_devices=
@ -274,7 +285,7 @@ plug_in_watcher() {
echo "and then unplug it." >&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' ' ')' '
old_device_list=' '$(collect_devices)' '
# <<< 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
@ -289,7 +300,7 @@ plug_in_watcher() {
end_time="$(expr $(date +'%s') + 10)"
while test $(date +'%s') -le "$end_time"
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"
then
sleep 1
@ -345,8 +356,7 @@ list_devices() {
if test -z "$devs"
then
# 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]' \
| grep -v '^fd[0-9]' | grep -v '^zram[0-9]')
devs=$(collect_devices)
fi
not_advised=0
@ -692,7 +702,12 @@ then
write_image "$image_file" $candidates
exit $?
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
fi
elif test "$num_cand" -gt 1