Code: Select all
#!/bin/sh
#
# Script to properly mount USB FAT16/32.
#
# I only use one USB key at the time, so the script
# umounts everything in /media/usb* on purpose.
# It is possible to specify a different device.
if [ ! -z $1 ]; then
echo "you specified a device"
check=$(fdisk -l | grep FAT | grep $1 | awk '{print $1}')
if [ ! -z $check ]; then
device=$1
else
echo "no FAT16/32 on "$1
exit 1
fi
else
# get device i.e. /dev/sdb1
device=$(fdisk -l | grep FAT | grep sdb | awk '{print $1}')
fi
# log device
echo "found USB FAT16/32 on $device"
# create /media/usb if needed
if [ ! -d "/media/usb" ]; then
mkdir -p /media/usb
fi
# umount possible automounted devices
umount /media/usb* 2>/dev/null
# mount
mount -t vfat $device /media/usb -o async,uid=1000,gid=1000,utf8,dmask=027,fmask=137
# log done
echo "$device mounted on /media/usb"