Friday, October 2, 2009

Auto-mount with halevt

halevt is good piece of software but by default it mounts disks in a way very inconvenient for me - that is mount points are like '/media/disk' '/media/disk-1/ '/media/disk-2' and so on. In order to help myself find disks more easily I've reconfigured halevt and created a script. Now I have /media/Cruzer-d4ba-1 and /media/Cruzer-a5e1-1 mountpoints for my two Sandisk USB sticks. And there are SD_Reader-a6a1-1, SD_Reader-a6a1-2, SD_Reader-a6a1-3 (three partitions) for the SD card I've inserted into a reader. A mountpoint name is composed by concatenating storage model name, short version of storage serial id and partition number. This is done by the following script (~/bin/halevt-mount-helper):
#!/bin/sh

STORAGE=`hal-get-property --udi "$1" --key block.storage_device`
PARTITION=`hal-get-property --udi "$1" --key volume.partition.number`
UUID=`hal-get-property --udi "$STORAGE" --key storage.serial | md5sum | head -c 4`
MODEL=`hal-get-property --udi "$STORAGE" --key storage.model | sed 's/ /_/g' | sed 's/^USB_//g'`

MPOINT="$MODEL-$UUID-$PARTITION"

halevt-mount -u "$1" -p "$MPOINT" -o sync -m 007
The script is used by configuring halevt with the following line instead of the default "halevt:insertion" line in halevt configuration file (/etc/halevt/halevt.xml or ~/.halevt/halevt.xml):
   <halevt:insertion exec="halevt-mount-helper $hal.udi$">

More security with ZSH

Don't save commands in history while a secure device is mounted. The mounted device must have .secure file in order to disable history file while the device mounted.

zshaddhistory() {
DIRS=`cat /proc/mounts | rgrep -P '(fuse|ext3|ext2|ext4|fat)' | cut -f2 -d' '`
FLAG=`for dir in ${=DIRS} ; do test -f "$dir/.secure" && echo secure; done`
echo $FLAG | grep secure 2>/dev/null >/dev/null && return -1 || return 0
}