23/06/2009
Using halevt to automount media and make them appear on ROX desktop
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>
File: eject.hal
4) Create /usr/bin/rox.panelput.pl perl script. The script is written very simplistically to be easily understandable and changable.
File: rox.panelput.pl
5) Start halevt from fluxbox startup..make sure ~/.fluxbox/startup file contains at least the following, changing YOURUSERNAME to the one appropriate:
/usr/local/bin/rox.panelput.pl Restore
killall -9 halevt; halevt -f -u YOURUSERNAME -g plugdev &
/usr/bin/rox -p pinboard
6) go to ROX options and change ‘eject command’ to use eject.hal
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.
References: http://forums.gentoo.org/viewtopic-t-731555-highlight-halevt.html
Filed by kargig at 01:10 under Linux
Tags: automount, bash, desktop, Gentoo, halevt, icons, mount, perl, pinboard, portage, rox
16 Comments | 16,080 views
tired just to read this post 😛
why don’t you use a decent window manager that needs just hal to be present 😀
Can you tell me a window manager (not a Desktop Environment) that can mount icons on the desktop ? There isn’t. Because no window manager manages the “desktop”. So you probably wanted to say: “why don’t you use a decent DESKTOP ENVIRONMENT that needs just hal to be present 😀 “…
That’s like comparing oranges to cars.
Anyway, I guess what you had in mind was the “lightweight” fork of gnome called XFCE which is built upon gnome’s libs…Riiiiight. If I were to use a DM instead of a WM I would use LXDE. XFCE is too bloated for me and it depends way too much on gnome which is currently even more bloated than KDE. Since gnome is in a very wrong path, XFCE follows it, whether it wants it or not. Unless XFCE builds it’s own set up libraries it’s just a “gnome-light”. IMHO LXDE is much more innovative than XFCE was/is.
Well I’d be glad if you showed me a DE which only depends on HAL and can appear icons on the desktop.
Anyway, I don’t really use fluxbox + ROX. I initially created the fluxbox + ROX combination for iloog in order for the livecd to have a “desktop with icons”. Then I added ivman + my custom scripts to the combination to have icons for automatically mounted devices. Now I changed the ivman config with halevt config and the bash version of rox.panelput with a perl one.
This post contains the configs + the scripts in full source. The config is halevt’s default with modifications to use rox.panelput.pl instead of just halevt-mount. The script is not thaaaat big, it’s just written in a very “python” way. It’s not an oneliner either though…but it surely can become one…it’s perl 😛
Anyway…Linux is all about the art of doing stuff your own way…If we were to have everything made for us by others, whatever bloated, we would all use …. XXXX (and XXXX is surely neither gnome nor kde nor anything linux related)
xfce has nothing to do with gnome libs. it depends only on gtk. just like lxde.
the desktop icons are handled by xfwm (the wm) so my answer was accurate 😛
for instance enlightenment is also a wm (a little unstable though) that can handle desktop icons and removable devices.
on http://www.xfce.org/projects/ it says:
Desktop Manager (http://www.xfce.org/projects/xfdesktop/)
This program sets the background image and provides a root window menu, desktop icons or minimized icons and a windows list.
Window Manager (http://www.xfce.org/projects/xfwm4/)
It manages the placement of application windows on the screen, provides window decorations and manages workspaces or virtual desktops.
So, I was correct. At least for xfce. Enlightment is an exception in the window managers world. D16 did not have desktop icon support while E17 has. So enlightment was a WM only and is now a WM/DE hybrid mix. You can still have enlightment E17 as a WM only so it’s not considered a DE.
using a lightweight wm has its cons and its pros. from my point of view i can sacrifice just a little more from my ram just in order to have some things working out of the box. easy access to removable devices is one of these things. 😉
This error appears when I run halevt with configurations and files of your post:
______________________________________________
minino@MiniNo:~/.halevt$ halevt
/home/minino/.halevt/HalevtConfigActions.xml:10: parser error : xmlParseEntityDecl: entity MOUNTABLE not terminated
<halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.f
^
/home/minino/.halevt/HalevtConfigActions.xml:10: parser error : internal error
<halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.f
^
/home/minino/.halevt/HalevtConfigActions.xml:10: parser error : DOCTYPE improperly terminated
<halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.f
^
/home/minino/.halevt/HalevtConfigActions.xml:10: parser error : Start tag expected, '<' not found
<halevt:Configuration version="0.1" xmlns:halevt="http://www.environnement.ens.f
^
parse_config.c:374 (halevt_parse_config) Document not parsed successfully
manager.c:346 (main) Configuration file /home/minino/.halevt/HalevtConfigActions.xml parsing failed
minino@MiniNo:~/.halevt$
———————————————
I am in a Debian stable. I had to install boolstuff libs from Sid without errors of dependencies, but I don't know if it could be important here.
Where could be the problem?
I think HalevtConfigActions.xml has not a well formed xml format. It has extrange characters that halevt doen’t understand (neither firefox).
Ok, I think lines that starts with
Sorry, but dillo doen’t work very well here.
lines that starts with
And I don’t know if these lines are incompletes or cuts for some reason.
Arrrgh!
halevt:Device match…
There were some typos in the xml. I have uploaded a new HalevtConfigActions.xml file and tested it. I think it works just fine now.
Sorry for the delay but I was away from home the last 3-4 days.
The script rox.panelput.pl is not working with halevt version 0.1.3. (They have changed something in the way they keep track of the mounted devices, so the path $HOME/.halevt/mounted/devices no longer exists). I’m using instead this little script (rox.panelput.sh):
#!/bin/sh
rox –RPC << EOF
$2
`basename $2`
EOF
with this eject.hal (it’s just the same but with all occurrences of rox.panelput.pl changed to rox.panelput.sh) :
#!/bin/bash
if [ -z $1 ]; then
echo “Usage: eject.hal ”
exit
else
echo “$1” | egrep “^/dev”
if [ “$?” == “0” ]; then
#echo “Device First, find mount point”
TOSCAN=`echo “$1” | sed -e ‘s/ /\\\\\\\40/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.sh 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/ /\\\\\\\40/g’`
TOUMOUNT=`grep “$TOSCAN” /proc/mounts | cut -d” ” -f1`
/usr/local/bin/rox.panelput.sh Remove “$1” nowait
halevt-umount “$1”
halevt-umount -s
if [ “$DISC” == “true” ]; then
/usr/bin/eject -p “$TOUMOUNT” &>/dev/null
fi
fi
fi
And this HalevtConfigActions.xml:
<!DOCTYPE halevt:Configuration [
]>
<!– blank CD/DVD
–>
<!–
This rule matches removable devices which have volume.policy.should_mount true
or don't have volume.policy.should_mount false.
Upon insertion, they are mounted and recorded by halevt-mount.
-m 002 sets the umask of mount to 002 when pmount is used system-wide
to mount the device. This allows regular users to read the device.
!–>
<!–
When a device get a mount point, it is passed to halevt-mount which can
record it. The property that changes is volume.is_mounted, and the action is
executed when the value of volume.is_mounted becomes true.
!–>
<!–
Example of a use of OnInit. At startup all the devices are matched and the exec
comand is run for those that match. Here we match all the removable devices
that aren't already mounted and mount and register them.
!–>
And that’s it. It works just fine for me. Tanks a lot for your work.
I have only tested it with the latest halevt version (0.1.4). I’ll try and check it also on 0.1.3 and see what needs fixing…thnx for letting me know.
Hello, I’m trying to use your guide on Ubuntu 9.10 but I can not make it work.
I’m using the binary Rox 2.10 and halevt 0.1.3-3 (and also your scripts).
I really like Rox but I don’t have your same skills and knowledge, you could create a guide for newbie?
Thanks in advice,
Danielsan
(forgive my English, I used an automatic translator)
I forgot to write that use Openbox as WM
[…] I found this blog post which helped explain a lot about the process. I did have to compile my own […]