#!/bin/bash -login # This program is used to manage USB devices using the usbwatch binary # to display icons and xmessage to also show text updates. PRG_USER=`whoami` if ! [[ -d $HOME/.usbwatch ]] ; then mkdir -p $HOME/.usbwatch cp /etc/X11/usbwatch/usbwatchrc.default $HOME/.usbwatch/usbwatchrc cp /etc/X11/usbwatch/links/usbwatch-idle.lnk $HOME/.usbwatch/usbwatch.lnk cp /etc/X11/usbwatch/prog.prefs $HOME/.usbwatch/prog.prefs fi if [[ "`pgrep -u $PRG_USER usbwatch`" = "" ]] ; then rm -f $HOME/.usbwatch/usbwatch.lnk cp /etc/X11/usbwatch/links/usbwatch-idle.lnk $HOME/.usbwatch/usbwatch.lnk else pkill -u $PRG_USER usbwatch 2> /dev/null rm -f $HOME/.usbwatch/usbwatch.lnk cp /etc/X11/usbwatch/links/usbwatch-idle.lnk $HOME/.usbwatch/usbwatch.lnk fi # sleep .5 # The only way to get rights to mount and unmount is to run the final # program from this script and not exit . We set a trap for SIGINT (-2) # and use that to keep the icons refreshed. When an event is triggered # by usb-hotmount or the device handler, they send an interrupt to # usbwatch on the users desktop. This way avoids contantly polling # and preserves the login environment of the user. MY_PID=$$ trap_int() { sleep .5 usbwatch &> /dev/null } while [ -d /proc/$MY_PID ] ; do trap trap_int 2 # note that leaving out this initial start of the program means that the loop waits for # an INT signal before starting the program above. usbwatch &> /dev/null done