mirror of
https://github.com/linuxboot/heads.git
synced 2025-02-04 10:11:02 +00:00
152689d5d5
Currently Heads relies on a hard-coded config value to determine which USB disk to mount. This can be problematic when trying to distribute a pre-built version of Heads that can work on multiple disk configurations. I've modified the USB mounting script so that it attempts to detect all USB boot disks present on the system, pick sane defaults, and prompt the user when there are multiple choices. I've also removed the USB configuration option from config-gui.sh as this config option is no longer used.
94 lines
2.5 KiB
Bash
Executable File
94 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Mount a USB device
|
|
. /etc/functions
|
|
|
|
enable_usb
|
|
|
|
if ! lsmod | grep -q usb_storage; then
|
|
insmod /lib/modules/usb-storage.ko \
|
|
|| die "usb_storage: module load failed"
|
|
sleep 5
|
|
fi
|
|
|
|
if [ ! -d /media ]; then
|
|
mkdir /media
|
|
fi
|
|
|
|
stat -c %N /sys/block/sd* | grep usb | cut -f1 -d ' ' | sed "s/[']//g;s|/sys/block|/dev|" > /tmp/usb_block_devices
|
|
if [ -z `cat /tmp/usb_block_devices` ]; then
|
|
if [ -x /bin/whiptail ]; then
|
|
whiptail --title 'USB Drive Missing' \
|
|
--msgbox "Insert your USB drive and press Enter to continue." 16 60
|
|
else
|
|
echo "+++ USB Drive Missing! Insert your USB drive and press Enter to continue."
|
|
read
|
|
fi
|
|
sleep 1
|
|
stat -c %N /sys/block/sd* | grep usb | cut -f1 -d ' ' | sed "s/[']//g;s|/sys/block|/dev|" > /tmp/usb_block_devices
|
|
if [ -z `cat /tmp/usb_block_devices` ]; then
|
|
if [ -x /bin/whiptail ]; then
|
|
whiptail $CONFIG_ERROR_BG_COLOR --title 'ERROR: USB Drive Missing' \
|
|
--msgbox "USB Drive Missing! Aborting mount attempt.\n\nPress Enter to continue." 16 60
|
|
else
|
|
echo "!!! ERROR: USB Drive Missing! Aborting mount. Press Enter to continue."
|
|
fi
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Check for the common case: a single USB disk with one partition
|
|
if [ `cat /tmp/usb_block_devices | wc -l` -eq 1 ]; then
|
|
USB_MOUNT_DEVICE=`cat /tmp/usb_block_devices`
|
|
if [ `ls -1 ${USB_MOUNT_DEVICE}* | wc -l` -eq 2 ]; then
|
|
USB_MOUNT_DEVICE=`ls -1 ${USB_MOUNT_DEVICE}* | tail -n1`
|
|
fi
|
|
# otherwise, let the user pick
|
|
else
|
|
> /tmp/usb_disk_list
|
|
for i in `cat /tmp/usb_block_devices`; do
|
|
ls $i* >> /tmp/usb_disk_list
|
|
done
|
|
|
|
if [ -x /bin/whiptail ]; then
|
|
MENU_OPTIONS=""
|
|
n=0
|
|
while read option
|
|
do
|
|
n=`expr $n + 1`
|
|
option=$(echo $option | tr " " "_")
|
|
MENU_OPTIONS="$MENU_OPTIONS $n ${option}"
|
|
done < /tmp/usb_disk_list
|
|
|
|
MENU_OPTIONS="$MENU_OPTIONS a Abort"
|
|
whiptail --clear --title "Select your USB disk" \
|
|
--menu "Choose your USB disk [1-$n, a to abort]:" 20 120 8 \
|
|
-- $MENU_OPTIONS \
|
|
2>/tmp/whiptail
|
|
|
|
option_index=$(cat /tmp/whiptail)
|
|
else
|
|
echo "+++ Select your USB disk:"
|
|
n=0
|
|
while read option
|
|
do
|
|
n=`expr $n + 1`
|
|
echo "$n. $option"
|
|
done < /tmp/usb_disk_list
|
|
|
|
read \
|
|
-p "Choose your USB disk [1-$n, a to abort]: " \
|
|
option_index
|
|
fi
|
|
|
|
if [ "$option_index" = "a" ]; then
|
|
exit 1
|
|
fi
|
|
USB_MOUNT_DEVICE=`head -n $option_index /tmp/usb_disk_list | tail -1`
|
|
fi
|
|
|
|
if [ "$1" = "rw" ]; then
|
|
mount -o rw $USB_MOUNT_DEVICE /media
|
|
else
|
|
mount -o ro $USB_MOUNT_DEVICE /media
|
|
fi
|