mount-usb: replace fixed timeout with drive detection

Rather than wait a fixed 5s for the usb storage kernel modules
to load, and the user to insert a drive, check for new USB drives
inserted every 1s with a 5s timeout.

Signed-off-by: Matt DeVillier <matt.devillier@puri.sm>
This commit is contained in:
Matt DeVillier 2020-01-14 17:07:53 -06:00
parent 59b65d1069
commit a2d50a10f7
No known key found for this signature in database
GPG Key ID: 2BBB776A35B978FD

View File

@ -5,9 +5,16 @@
enable_usb
if ! lsmod | grep -q usb_storage; then
insmod /lib/modules/usb-storage.ko \
count=$(ls /dev/sd* 2>/dev/null | wc -l)
timeout=0
echo "Scanning for USB storage devices..."
insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \
|| die "usb_storage: module load failed"
sleep 5
while [[ $count == $(ls /dev/sd* 2>/dev/null | wc -l) ]]; do
[[ $timeout -ge 4 ]] && break
sleep 1
timeout=$(($timeout+1))
done
fi
if [ ! -d /media ]; then