#!/bin/sh # name : /usr/sbin/updfstab # updfstab for kernel 2.6 # this script is automatically called by hotplug at each plug/unplug event of an usb-storage device. (usb keys, mp3 jukeboxes, digital cameras...) # be sure the drivers are loaded modprobe usb-storage vfat # First remove all updfstab-managed devices from fstab # existing but removed entries are just added again later # mntpoint are not removed (unuseful) grep -v \#serial /etc/fstab > /etc/fstab.updated if diff /etc/fstab /etc/fstab.updated >/dev/null 2>&1; then rm /etc/fstab.updated else if [ -s /etc/fstab.updated ]; then cat /etc/fstab.updated > /etc/fstab #Xdialog --msgbox "removed $p ${mntpoint} from fstab" 20 30 # debug fi rm /etc/fstab.updated fi # wait 5 seconds until something appears timeout=5 # timeout in tenths of second for giving up while true; do # list devices list="`ls /sys/bus/usb/drivers/usb-storage`" if test "$list"; then break; fi sleep 0.1 timeout=$((${timeout}-1)) if [ $timeout -eq 0 ]; then exit; fi done for i in $list; do j="`printf $i | sed 's/:.*//g'`" # exemple : $i="3-2:1.0" -> we extract $j="3-2" # for each device, get infos host="`ls -1 /sys/bus/usb/drivers/usb-storage/$i | grep host`" # used to find the /dev entry manufacturer="`cat /sys/bus/usb/devices/$j/manufacturer | sed 's/[ \/]//g'`" # used to chose a mountpoint product="`cat /sys/bus/usb/devices/$j/product`" # not used (could be used in mnt name) serial="`cat /sys/bus/usb/devices/$j/serial`" # used to recognize the entry in fstab #Xdialog --msgbox "host=$host\nmanufacturer=$manufacturer\nproduct=$product\nserial=$serial" 20 30 # debug # find partitions partitions=`find /dev/scsi/${host} -type b -name "part*"` # for each partition, create a mountpoint and an fstab entry for p in ${partitions}; do # build a mountpoint name if [ `echo ${partitions}|wc -w` -eq 1 ]; then mntpoint="/mnt/${manufacturer}" # if only one partition else mntpoint="/mnt/${manufacturer}_`basename $p`" # if several partitions fi # create the mountpoint and the fstab entry if [ ! -d "${mntpoint}" ]; then mkdir ${mntpoint} #Xdialog --msgbox "created ${mntpoint}" 10 30 # debug fi if ! grep "#serial${serial}" /etc/fstab >/dev/null 2>&1; then echo "$p $mntpoint auto sync,user,noauto,rw,iocharset=utf8 0 0 #serial${serial}" >> /etc/fstab #Xdialog --msgbox "added $p ${mntpoint} in fstab" 10 30 # debug fi done done