PaulBredbury wrote:A udev rule is 1 line, not 100. There's dozens if not hundreds of previous threads about it.
The udev rule is one line here:
SUBSYSTEM=="block", ACTION=="add", RUN+="/usr/local/bin/mount-device.sh /dev/%k"
the script to run it I guess is this:
#!/bin/sh
DEVICE="$1"
GID=`grep plugdev /etc/group | cut -d: -f 3`
if [ "$DEVICE" = "" ] ; then exit 1 ; fi
# wait a moment till' hal has information about the device
sleep 2
HAL_UDI=`hal-find-by-property --key block.device --string "$DEVICE"`
function get_hal_label {
CUR_UDI=$1
LABEL=""
COUNTER=0;
while [ -z "$LABEL" -a $COUNTER -lt 4 ]; do
LABEL=`hal-get-property --key volume.label --udi "$CUR_UDI" 2>/dev/null`
if [ -z "$LABEL" ]; then
LABEL=`hal-get-property --key storage.serial --udi "$CUR_UDI" 2>/dev/null`
fi
CUR_UDI=`hal-get-property --key info.parent --udi "$CUR_UDI" 2>/dev/null`
let COUNTER=COUNTER+1
done
if [ -z $LABEL ]; then
LABEL=${DEVICE##/dev/}
fi
}
function get_hal_removable {
CUR_UDI=$1
REMOVABLE=""
COUNTER=0
while [ -z "$REMOVABLE" -a $COUNTER -lt 4 ]; do
REMOVABLE=`hal-get-property --key storage.removable --udi "$CUR_UDI" 2>/dev/null`
if [ -z "$REMOVABLE" ]; then
BUS=`hal-get-property --key storage.bus --udi "$CUR_UDI" 2>/dev/null`
if [ "$BUS" = "usb" ]; then
REMOVABLE="true"
fi
fi
CUR_UDI=`hal-get-property --key info.parent --udi "$CUR_UDI" 2>/dev/null`
let COUNTER=COUNTER+1
done
if [ -z "$REMOVABLE" ]; then
logger "assuming $HAL_UDI is removable for safety reasons"
REMOVABLE="true"
fi
}
if [ -z "$HAL_UDI" ]; then # can't find device in hal db
logger "hald didn't know about $DEVICE"
LABEL=${DEVICE##/dev/}
else # device found in hal db.
get_hal_label "$HAL_UDI"
get_hal_removable "$HAL_UDI"
fi
logger "Mounting HAL_UDI $HAL_UDI as $DEVICE to $LABEL (removable: $REMOVABLE)"
SYNC_OPT=""
if [ $REMOVABLE = "true" ]; then
SYNC_OPT="--sync"
fi
pmount --umask 007 $SYNC_OPT "$DEVICE" "$LABEL"
# if you do not want to use pmount (why should you?)
#MOUNTPOINT=/media/${LABEL}
#mkdir -p "$MOUNTPOINT" &&
#touch "$MOUNTPOINT"/.created_by_pmount &&
#mount "$DEVICE" "$MOUNTPOINT" -o gid=$GID,umask=007 ||
#rm "$MOUNTPOINT"/.created_by_pmount &&
#rmdir "$MOUNTPOINT"
coming from this guide here:
http://gentoo-wiki.com/UDEV
I just want to make sure it's correct in the fact that every time I plug my usbstick it it gets the same mount point so I can stick it in fstab and have an icon in system:/media. Now the icon that is their now doesn't work so I was wondering if someone knew if my fstab is correct in loading the usbstick which is here:
/dev/cdrom /mnt/cdrom auto noauto,user 0 0
/dev/fd0 /mnt/floppy auto noauto 0 0
/dev/sde1 /mnt/usb auto noauto,user 0 0