#!/bin/bash env >> /tmp/udev.test # Only run through this script if we're adding a device. If we're # removing one, then exit. if [ "$ACTION" != 'add' ] ; then exit fi export PATH=/bin:/sbin:/usr/bin:/usr/sbin LocalDisplay=':0' FileManager="/opt/kde/bin/konqueror" # Get the username of whoever is at the local X11 display. # If we don't find one, then exit. X11User=`who | grep $LocalDisplay | cut -f 1 -d ' '` if [ -z "$X11User" ] ; then exit fi # Get the name of the symlink that will be created for this device. DevicePath=/dev/`udevinfo -q symlink -p /sys$DEVPATH` # This is because a udev event gets fired for BOTH /dev/ubc and /dev/ubc1. # Since we only want the actual USB drive partition, we check that there's # a number in the device name. if [ -z `echo $DEVNAME | grep '[0-9]'` ] ; then exit fi # Loop through the /etc/auto.* files that hold the directories where auto- # mounted filesystems will be mounted. for autofile in /etc/auto.* do # Look for a directory entry for our device symlink. FSDir=`grep "$DevicePath" $autofile | cut -f 1 -d ' '` # If we find one... if [ ! -z $FSDir ] ; then # ...then look for the base mount point in /etc/auto.master. BaseDir=`grep "$autofile" /etc/auto.master | cut -f 1 -d ' '` # If we find the base mount point, then we can build the full # mount path and launch the file manager. if [ ! -z "$BaseDir" ] ; then MountDir=$BaseDir/$FSDir/ export DISPLAY=$LocalDisplay if [ -e /home/$X11User/.bash_profile ] ; then source /home/$X11User/.bash_profile fi # We use nice to keep the system from eating a bunch of cycles # just opening the file manager. # Note that we set $HOME so the file manager can read its # configuration file from the right place. export HOME=/home/$X11User nice -n 5 su $X11User -c "$FileManager $MountDir &> /dev/null" & exit fi fi done