#!/bin/sh # /etc/hotplug.d/usb/usb-stub.hotplug # This an example of how to get a 'hook' into a USB event. # You may need to create the directory /etc/hotplug.d/usb # Then place this file inside the directory and make sure it's executable # the name doesn't matter and all the echos are just verbosity for # debugging. The main thing is to run your external script if certain # conditions are met. The example script here is /usr/sbin/do-hotmnt # We have to export any of the variables we need to exec and background # the new process so this hook can exit. # ACTION DEVICE and INTERFACE are probably all we need (maybe DEVFS) # The only ACTION cases supported by the USB driver are 'add' and 'remove' # If you need to handle events when the usb-storage module is loaded, put them # in /etc/hotplug/usb-storage cd /etc/hotplug . ./hotplug.functions # uncomment to activate hotplug messaging. You can also use 'mesg' # DEBUG=yes export DEBUG debug_mesg "arguments ($*) env (`env`)" # you can use some kind of logging the /var/log/messages or elsewhere #echo "Hello from /etc/hotplug.d/usb/usb-stub.hotplug" >> /var/log/messages # since this hook is run by the kernel as root, we try to get out of here as soon # as possible. We start a separate process (do-hotmnt) to handle events from # the usb-storage driver and automatically mount and unmount the partitions # on the device case $ACTION in add) # Stub #echo "Adding:" >> /var/log/messages #echo "DEVICE=$DEVICE" >> /var/log/messages #echo "ACTION=$ACTION" >> /var/log/messages #echo "PRODUCT=$PRODUCT" >> /var/log/messages #echo "INTERFACE=$INTERFACE" >> /var/log/messages #echo "TYPE is: $TYPE" >> /var/log/messages #echo "DEVFS=$DEVFS" >> /var/log/messages #echo "LABEL=$LABEL" >> /var/log/messages # echo "REMOVER is: $REMOVER" >> /var/log/messages #echo "SUBSYSTEM is: $SUBSYSTEM" >> /var/log/messages #echo "DEVPATH is: $DEVPATH" >> /var/log/messages # echo "PHYSDEVDRIVER is: $PHYSDEVDRIVER" >> /var/log/messages # INETRFACE 8 and TYPE 0/0/0 means we are a usb-strorage device. # anything else is ignored if [ "`echo $INTERFACE |grep "8/*"`" != "" -a "`echo $TYPE|grep "0/*"`" != "" ] ; then #echo "This is a USB mass storage device using SCSI emulation" >> /var/log/messages # use the execute bit on rc.usbwatch as an on/off switch #if [[ -x /etc/rc.d/rc.usbwatch ]] ; then echo "Automounting USB mass storage device $DEVICE" >> /var/log/messages export $INTERFACE $TYPE $PRODUCT $ACTION $DEVICE CALLER="USBWATCH" /usr/sbin/do-hotmount & #fi fi ;; remove) # Stub #echo "Removing: $DEVICE" >> /var/log/messages #echo "SUBSYSTEM is: $SUBSYSTEM" >> /var/log/messages #echo "DEVPATH is: $DEVPATH" >> /var/log/messages #echo "DEVICE=$DEVICE" >> /var/log/messages #echo "PHYSDEVDRIVER is: $PHYSDEVDRIVER" >> /var/log/messages #echo "ACTION=$ACTION" >> /var/log/messages #echo "PRODUCT=$PRODUCT" >> /var/log/messages #echo "INTERFACE=$INTERFACE" >> /var/log/messages #echo "TYPE is: $TYPE" >> /var/log/messages #echo "DEVFS is: $DEVFS" >> /var/log/messages #echo "REMOVER is: $REMOVER" >> /var/log/messages if [ "`echo $INTERFACE |grep "8/*"`" != "" -a "`echo $TYPE|grep "0/*"`" != "" ] ; then #echo "This is a USB mass storage device using SCSI emulation" >> /var/log/messages #if [[ -x /etc/rc.d/rc.usbwatch ]] ; then echo "Removing USB mass storage device $DEVICE" >> /var/log/messages #echo "Removing: $DEVICE" >> /var/log/messages export $INTERFACE $TYPE $PRODUCT $ACTION $DEVICE CALLER="USBWATCH" /usr/sbin/do-hotmount & #fi fi ;; register) # let usb.agent take care of registering and unregistering ? # No, these ACTIONs are not supported here... echo "ACTION=$ACTION" >> /var/log/messages echo "DEVICE=$DEVICE" >> /var/log/messages true ;; unregister) echo "ACTION=$ACTION" >> /var/log/messages echo "DEVICE=$DEVICE" >> /var/log/messages true ;; *) echo "ACTION=$ACTION" >> /var/log/messages echo "DEVICE=$DEVICE" >> /var/log/messages ;; esac