usb-scan/mount: Improve USB handling

Currently, /media is mounted once per boot, which causes issues
if a user need to change USB sticks, or unknowning performs an
operation that mounts /media and then needs to access a different
USB stick later (eg, updating the firmware).

To mitigate this, always unmount /media if mounted before scanning
for USB devices, so the user can choose the correct device at the
time of its use.

Additionally, add a unique exit code for user abort so we're not
treating it the same as a failure, and use it to prevent unnecessary
GUI prompts when cancelling selection of a USB device.

Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
This commit is contained in:
Matt DeVillier 2020-07-10 13:00:13 -05:00
parent f7c4cae903
commit ba4fcefcea
No known key found for this signature in database
GPG Key ID: 2BBB776A35B978FD
3 changed files with 16 additions and 14 deletions

View File

@ -100,7 +100,7 @@ if [ -z ${USB_MOUNT_DEVICE} ]; then
fi
if [ "$option_index" = "a" ]; then
exit 1
exit 5
fi
USB_MOUNT_DEVICE=`head -n $option_index /tmp/usb_disk_list | tail -1`
fi

View File

@ -2,6 +2,7 @@
# Scan for USB installation options
set -e -o pipefail
. /etc/functions
. /etc/gui_functions
. /tmp/config
# Unmount any previous boot device
@ -11,10 +12,8 @@ if grep -q /boot /proc/mounts ; then
fi
# Mount the USB boot device
if ! grep -q /media /proc/mounts ; then
mount-usb "$CONFIG_USB_BOOT_DEV" \
|| die "Unable to mount /media"
fi
mount_usb || die "Unable to mount /media"
# Get USB boot device
USB_BOOT_DEV=$(grep "/media" /etc/mtab | cut -f 1 -d' ')

View File

@ -3,17 +3,20 @@
mount_usb()
{
# Unmount any previous USB device
if grep -q /media /proc/mounts ; then
umount /media || die "Unable to unmount /media"
fi
# Mount the USB boot device
if ! grep -q /media /proc/mounts ; then
mount-usb && USB_FAILED=0 || USB_FAILED=1
mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 )
if [ $USB_FAILED -ne 0 ]; then
whiptail --title 'USB Drive Missing' \
--msgbox "Insert your USB drive and press Enter to continue." 16 60
mount-usb && USB_FAILED=0 || ( [ $? -eq 5 ] && exit 1 || USB_FAILED=1 )
if [ $USB_FAILED -ne 0 ]; then
whiptail --title 'USB Drive Missing' \
--msgbox "Insert your USB drive and press Enter to continue." 16 60
mount-usb && USB_FAILED=0 || USB_FAILED=1
if [ $USB_FAILED -ne 0 ]; then
whiptail $CONFIG_ERROR_BG_COLOR --title 'ERROR: Mounting /media Failed' \
--msgbox "Unable to mount USB device" 16 60
fi
whiptail $CONFIG_ERROR_BG_COLOR --title 'ERROR: Mounting /media Failed' \
--msgbox "Unable to mount USB device" 16 60
exit 1
fi
fi
}