#!/bin/bash # Copyright Daniel Dechelotte 2004 # Distributed under the terms of the GNU General Public License # modifie par Eric Gerbier (eric.gerbier@free.fr) # avec une contribution de Dominique Launay # version 1.3 du 13/03/2004 if [ "x$ACTION" != "xadd" ]; then exit 0 fi USBSTORAGE_CONF_FILE=/etc/hotplug/usb/usb-storage.conf if [ ! -f $USBSTORAGE_CONF_FILE ]; then exit 0 fi NAME_SPEC="periph" MOUNT_SPEC="montage" USE_DEFAULT_MOUNTPOINTS=yes FOUND_NAME= ## IFS=/ echo $PRODUCT | read vendID prodID devID vendID=$(echo $PRODUCT | cut -f1 -d/) prodID=$(echo $PRODUCT | cut -f2 -d/) devID=$(echo $PRODUCT | cut -f3 -d/) # making vendID and prodID length to be 4 lengID=`expr length $vendID` vendID2=$vendID while [ $lengID -lt 4 ] do vendID2="0"$vendID2 lengID=`expr length $vendID2` done lengID=`expr length $prodID` prodID2=$prodID while [ $lengID -lt 4 ] do prodID2="0"$prodID2 lengID=`expr length $prodID2` done logger -i -t usb-storage-custom "PRODUCT=$PRODUCT" while read command name vend prod garbage ; do if [ "x$command" != "x$NAME_SPEC" ]; then continue fi if [ "x$garbage" != "x" ]; then echo "Ignoring trailing [$garbage] at the end of $NAME_SPEC line in $USBSTORAGE_CONF_FILE" >&2 fi # remove hexa prefix vend=$( echo $vend | sed 's/^0x0*//' ) prod=$( echo $prod | sed 's/^0x0*//' ) if [ "x$vend" = "x$vendID" -a "x$prod"="x$prodID" ]; then FOUND_NAME="$name" logger -i -t usb-storage-custom "found periph $name vendID=$vendID prodID=$prodID" break fi done < $USBSTORAGE_CONF_FILE if [ "x$FOUND_NAME" = "x" -a "x$USE_DEFAULT_MOUNTPOINTS" != "xyes" ]; then logger -i -t usb-storage-custom "Device not found in $USBSTORAGE_CONF_FILE. Exiting" exit 1 fi FOUND_DEVICE= for i in /proc/scsi/usb-storage-[0-9]; do out1=$( grep "Attached: Yes" $i/[0-9] ) if [ -n "$out1" ] then out2=$( grep -E "GUID: 0?${vendID2}0?${prodID2}" $i/[0-9] ) logger -i -t usb-storage-custom "$i : $out2" if [ -n "$out2" ] then #num=$( ls $i ) num=$( echo $i | cut -f3 -d- ) num_device=$( echo $num | tr "0-9" "a-j" ) FOUND_DEVICE=/dev/sd$num_device logger -i -t usb-storage-custom "found device $num $FOUND_DEVICE" # force a read fdisk -l $FOUND_DEVICE > /dev/null 2>&1 # control out3=$( grep $num_device /proc/partitions ) if [ -n "$out3" ] then logger -i -t usb-storage-custom "good device $FOUND_DEVICE (found in /proc/partitions)" else logger -i -t usb-storage-custom "bad device $FOUND_DEVICE (not found in /proc/partitions)" fi break fi fi done if [ "x$FOUND_DEVICE" = "x" ]; then logger -i -t usb-storage-custom "Could not deduce device for $FOUND_NAME" exit 1 fi if [ "x$FOUND_NAME" != "x" ]; then while read command name mount_point device options; do if [ "x$command" != "x$MOUNT_SPEC" ]; then continue fi if [ "x$name" != "x$FOUND_NAME" ]; then continue fi logger -i -t usb-storage-custom "found conf : $name $mount_point $device $options" if [ "x$device" = "x" ]; then $device="_DEV_1" fi if [ ! -d $mount_point ]; then mkdir -p $mount_point fi if [ -n "$options" ] then mount_option="-osync,$options" else mount_option="-osync" fi mount $mount_option $FOUND_DEVICE${device/_DEV_} $mount_point rep=$? logger -i -t usb-storage-custom "mount $mount_option $FOUND_DEVICE${device/_DEV_} $mount_point ; retour $rep" echo "umount $mount_point" >> $REMOVER chmod 544 $REMOVER done < $USBSTORAGE_CONF_FILE else mount_point=/mnt/${FOUND_DEVICE/\/dev\//}1 if [ ! -d $mount_point ]; then mkdir -p $mount_point fi mount -osync ${FOUND_DEVICE}1 $mount_point rep=$? logger -i -t usb-storage-custom "mount ${FOUND_DEVICE}1 $mount_point; retour $rep" echo "umount $mount_point" >> $REMOVER chmod 544 $REMOVER fi