mirror of
https://github.com/linuxboot/heads.git
synced 2025-02-20 09:16:21 +00:00
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:
parent
f7c4cae903
commit
ba4fcefcea
@ -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
|
||||
|
@ -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' ')
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user