With the recent addition of halevt in Gentoo’s portage it is now relatively easy to automatically mount media like USB sticks and CD/DVD discs on /media.
What I wanted to do was to emulate my previous set of configs and scripts that ivman used to create icons of automatically mounted media on ROX desktop (called pinboard). I am using ROX pinboard on top of my favorite window manager, fluxbox.
The idea is that halevt is started by the fluxbox startup config file and when a new device is attached to the computer, halevt config calls a script that creates an icon on the ROX pinboard using ROX rpc. When a device needs to be removed ROX pinboard is configured to call a special eject command that checks for a couple of things before unmounting the device and calling the script to remove the icon from ROX pinboard.
Apart from automatically mounting/unmounting of devices I have also added a nice option in the halevt config to unmount and eject the CD/DVD drive when the eject button on the device is used and of course when the CD/DVD is not in use. That emulates a bit the windows behavior that so many users have gotten used to.
Since the script used by halevt involves a lot of file reading/writing and parsing I thought it would be wise to convert my old rox.panelput bash script to perl. And I was correct, the speed difference, even for such simple tasks is more than noticeable.
The installation process. Please take notice of the user executing the commands, $ is for normal user, # is for root:
0) create /usr/local/bin/ path and put it in your shell’s PATH
# mkdir /usr/local/bin
$ echo "export PATH=$PATH:/usr/local/bin/" >> ~/.bashrc
1) install halevt
# echo "sys-apps/halevt ~x86" >> /etc/portage/package.keywords
# emerge halevt
2) create ~/.halevt/HalevtConfigActions.xml in your home directory:
File: HalevtConfigActions.xml (right click->Save-as)
3) Create /usr/bin/eject.hal. Take notice that the script uses bash and not dash!
#!/bin/bash if [ -z $1 ]; then echo "Usage: eject.hal <device>" exit else echo "$1" | egrep "^/dev" if [ "$?" == "0" ]; then #echo "Device First, find mount point" TOSCAN=`echo "$1" | sed -e 's/ /\\\\\\\\040/g'` TOUMOUNT=`grep "$TOSCAN" /proc/mounts | cut -d" " -f2` UDI=`hal-find-by-property --key volume.mount_point --string "$TOUMOUNT"` DISC=`hal-get-property --udi "$UDI" --key volume.is_disc` /usr/local/bin/rox.panelput.pl Remove "$TOUMOUNT" halevt-umount "$1" halevt-umount -s if [ "$DISC" == "true" ]; then /usr/bin/eject -p "$1" &>/dev/null fi else #echo "Mount Point First, find device" UDI=`hal-find-by-property --key volume.mount_point --string "$1"` DISC=`hal-get-property --udi "$UDI" --key volume.is_disc` TOSCAN=`echo "$1" | sed -e 's/ /\\\\\\\\040/g'` TOUMOUNT=`grep "$TOSCAN" /proc/mounts | cut -d" " -f1` /usr/local/bin/rox.panelput.pl Remove "$1" nowait halevt-umount "$1" halevt-umount -s if [ "$DISC" == "true" ]; then /usr/bin/eject -p "$TOUMOUNT" &>/dev/null fi fi fi </device>
4) Create /usr/bin/rox.panelput.pl perl script. The script is written very simplistically to be easily understandable and changable.
5) Start halevt from fluxbox startup..make sure ~/.fluxbox/startup file contains at least the following, changing YOURUSERNAME to the one appropriate:
killall -9 halevt; halevt -f -u YOURUSERNAME -g plugdev &
/usr/bin/rox -p pinboard
That should be all. Upon fluxbox restart halevt should start and when you plug in your usb the set of scripts will create an icons on ROX pinboard for you.