2017-04-02 03:02:00 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Mount a USB device
|
2017-12-06 08:04:27 +00:00
|
|
|
. /etc/functions
|
|
|
|
|
|
|
|
enable_usb
|
2017-04-02 03:02:00 +00:00
|
|
|
|
2017-04-05 23:20:53 +00:00
|
|
|
if ! lsmod | grep -q usb_storage; then
|
2019-04-15 22:05:03 +00:00
|
|
|
insmod /lib/modules/usb-storage.ko \
|
|
|
|
|| die "usb_storage: module load failed"
|
|
|
|
sleep 5
|
2017-04-03 21:09:54 +00:00
|
|
|
fi
|
2017-04-02 03:02:00 +00:00
|
|
|
|
|
|
|
if [ ! -d /media ]; then
|
2019-04-15 22:05:03 +00:00
|
|
|
mkdir /media
|
2017-04-02 03:02:00 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-15 22:05:03 +00:00
|
|
|
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
|
|
|
|
|
2019-04-16 19:55:00 +00:00
|
|
|
USB_MOUNT_DEVICE=""
|
2019-04-15 22:05:03 +00:00
|
|
|
# Check for the common case: a single USB disk with one partition
|
|
|
|
if [ `cat /tmp/usb_block_devices | wc -l` -eq 1 ]; then
|
2019-04-16 19:55:00 +00:00
|
|
|
USB_BLOCK_DEVICE=`cat /tmp/usb_block_devices`
|
|
|
|
# Subtract out block device
|
|
|
|
let USB_NUM_PARTITIONS=`ls -1 ${USB_BLOCK_DEVICE}* | wc -l`-1
|
|
|
|
if [ ${USB_NUM_PARTITIONS} -eq 0 ]; then
|
|
|
|
USB_MOUNT_DEVICE=${USB_BLOCK_DEVICE}
|
|
|
|
elif [ ${USB_NUM_PARTITIONS} -eq 1 ]; then
|
|
|
|
USB_MOUNT_DEVICE=`ls -1 ${USB_BLOCK_DEVICE}* | tail -n1`
|
2019-04-15 22:05:03 +00:00
|
|
|
fi
|
2019-04-16 19:55:00 +00:00
|
|
|
fi
|
2019-04-15 22:05:03 +00:00
|
|
|
# otherwise, let the user pick
|
2019-04-16 19:55:00 +00:00
|
|
|
if [ -z ${USB_MOUNT_DEVICE} ]; then
|
2019-04-15 22:05:03 +00:00
|
|
|
> /tmp/usb_disk_list
|
|
|
|
for i in `cat /tmp/usb_block_devices`; do
|
2019-04-16 19:55:00 +00:00
|
|
|
# remove block device from list if numeric partitions exist, since not bootable
|
|
|
|
let USB_NUM_PARTITIONS=`ls -1 $i* | wc -l`-1
|
|
|
|
if [ ${USB_NUM_PARTITIONS} -eq 0 ]; then
|
2020-06-25 07:46:11 +00:00
|
|
|
echo $(blkid | grep $i | grep -o 'LABEL=".*"' | cut -f2 -d '"') $i >> /tmp/usb_disk_list
|
2019-04-16 19:55:00 +00:00
|
|
|
else
|
2020-06-24 07:44:50 +00:00
|
|
|
for j in $(ls $i* | tail -${USB_NUM_PARTITIONS}); do
|
2020-06-25 07:46:11 +00:00
|
|
|
echo $(blkid | grep $j | grep -o 'LABEL=".*"' | cut -f2 -d '"') $j >> /tmp/usb_disk_list
|
2020-06-24 07:44:50 +00:00
|
|
|
done
|
2019-04-16 19:55:00 +00:00
|
|
|
fi
|
2019-04-15 22:05:03 +00:00
|
|
|
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
|
2020-06-24 07:44:50 +00:00
|
|
|
USB_MOUNT_DEVICE=`head -n $option_index /tmp/usb_disk_list | tail -1 | sed 's/\ .*$//'`
|
2019-04-15 22:05:03 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "rw" ]; then
|
|
|
|
mount -o rw $USB_MOUNT_DEVICE /media
|
2017-07-17 16:24:15 +00:00
|
|
|
else
|
2019-04-15 22:05:03 +00:00
|
|
|
mount -o ro $USB_MOUNT_DEVICE /media
|
2017-07-17 16:24:15 +00:00
|
|
|
fi
|