Prerequisites: Read the COPYING.LIB file and accept its
terms.

These scripts run with rootly powers and are hot of the
press - use with caution.  Only use these scripts if
you users are trustworthy and your system is secure from 
intruders.  While these scripts attempt to deal with many
issues related to using usb drive issues - it is still possible
that randomly plugging and unplugging usb drives without 
shutting down programs using them may cause data loss and 
file system corruption on the drives concerned.

0) Requirements
   i) hotplug agent (installed by default in Redhat 7.2)
  ii) sudo (shipped with Redhat) (http://www.courtesan.com/sudo/)
 iii) sg3_utils for identifying scsi devices on hotplug
      (sg3_utils can be found at http://www.torque.net/sg/u_index.html
       install sgmap somewhere on your path - eg /usr/local/bin) 
  iv) disktype needed for ext2, ext3, and ntfs user/group detection 
      (disktype can be found at http://disktype.sourceforge.net  
       install it on your path - eg /usr/local/bin)
  
1) Install and customise the usb-umount.conf script in /usr/local/etc
     cp usb-mount.conf /usr/local/etc/

     edit usb-mount.conf script for your system.
 
2) Install the usb-umount script in /usr/local/bin
     cp usb-mount /usr/local/bin/
     ln -s /usr/local/bin/usb-mount /usr/local/bin/usb-umount
     chmod a+x /usr/local/bin/usb-mount

     edit the top usb-mount script for your system. 
     (If people want to mail me reasonably generic configs for
     their Linux distro's I'll include them in the samples
     directory.)
 
3) Backup the existing usb.agent
     cp /etc/hotplug/usb.agent /etc/hotplug/usb.agent.backup

4) Add an add and remove action to /etc/hotplug/usb.agent
   (see the example in the image/etc/hotplug/usb.agent file)

   i)  find the 'add)' action and add a line such as:

      [ -x /usr/local/bin/usb-mount ] && /usr/local/bin/usb-mount

   ii) find the 'remove)' action and add a line such as: 

      [ -x /usr/local/bin/usb-umount ] && /usr/local/bin/usb-umount

   I've included my Redat 9 based example usb.agent in samples/ 

5) Setup a /etc/sudoers entry for /usr/local/bin/usb-mount 
   and /usr/local/bin/usb-umount, such as

      ALL	viking2=NOPASSWD: /usr/local/bin/usb-mount
      ALL	viking2=NOPASSWD: /usr/local/bin/usb-umount

   Replace viking2 with your hostname. Note that these two
   lines grant passwordless execution of these two commands as
   root - all my users are trustworthy, so I'm happy to do
   this.

6) Test by plugging in a device.  Check your desktop for 
   a new icon.  Inspect /var/log/messages for feedback.  
   Use the mount command to see if anything was mounted.   

7) Optionally install the two man pages somewhere like
   /usr/local/share/man/man8 and /usr/local/share/man/man5.


Michael Hamilton
michael@actrix.gen.nz 
May 2003

Credits and change log:
   See top of usb-mount script or the CHANGELOG file.
   Some email addresses have be withheld by request.
   If you submit a fix or enhancement please state whether
   you wish to have your email address withheld to avoid any
   possibility of spam.
