#!/bin/bash # /usr/sbin/do-hotmnt # since this gets invoked by the kernel (as root) from /etc/hotplug.d/usb/usb-stub.hotplug it can be # placed anywhere. # All the echos are just for verbosity. Note that the first thing we have to do is take a nap. # This hook gets run right away, even before the drivers have registered. # Hooking in like this avoids having to poll constantly. But because of the danger of # the user unplugging the device without unmounting it first, it might be good to # put some kind of loop/sleep process going that would run bdflush every few seconds # on just that device. echo "We've made it to do-hotmnt!" >> /var/log/messages sleep 6 echo INTERFACE=$INTERFACE |grep 8 >> /var/log/messages echo ACTION=$ACTION >> /var/log/messages echo DEVICE=$DEVICE >> /var/log/messages # INTERFACE=8/*/* means we have a SCSI disk sda. #if [[ "`echo $INTERFACE |grep 8`" != "" ]] ; then if [[ $ACTION = "add" ]] ; then for disk in a b c d ; do echo "Checking for sd$disk..." >> /var/log/messages # This is not the real way to do an automount. I'm just checking /var/log/messages as an example # Real code would run fdisk -l, blkid and whatever else comparing with your currently mounted temp mounts # or whatever. if [[ `cat /var/log/messages |grep "sd$disk:"` != "" ]] ; then echo "found USB hard disk sd$disk in the log" >> /var/log/messages # then loop through partition numbers and compare with the ouptut of blkid # and other key lists or whatever for part in 1 2 3 4 5 6 7 8 ; do echo "Checking for sd$disk$part..." >> /var/log/messages if [[ `blkid |grep "sd$disk$part"` ]] ; then echo "Found partition sd$disk$part in blkid" >> /var/log/messages if [ `fdisk -l |grep sd$disk$part` != "" ]] ; then echo "Found partition sd$disk$part already mounted?" >> /var/log/messages else echo "Partition sd$disk$part is unmounted?" >> /var/log/messages # crudely we find an unmounted partition. The 'proper' thing, I guess, would be to have # a PID file for each device and/or partition. The usb.agent in /etc/hotplug apparently looks # for a PID file( or tries to create one?) in /var/run/usb which matches DEVICE, but I haven't # seen or gotten this to work so far. fi fi done fi done fi #fi echo "exiting do-hotmnt" >> /var/log/messages