/etc/udev/rules.d/85-storage-automount.rules :
ENV{DEVTYPE}=="partition", RUN+="/etc/automount/automount.sh", ENV{REMOVE_CMD}="/etc/automount/autoumount.sh"
/etc/automount/automount.sh :
#!/bin/sh # set the mountpoint name according to partition or uuid mount_point=$ID_FS_LABEL if [ -z $mount_point ]; then mount_point=${ID_FS_UUID##*/} fi # if a plugdev group exist, retrieve it's gid set & it as owner of mountpoint plugdev_gid="$(grep plugdev /etc/group|cut -f3 -d:)" if [ -z $plugdev_gid ]; then gid='' else chown root:plugdev $mount_point gid=",gid=$plugdev_gid" fi # create the mountpoint directory in /media/ (if not empty) if [ -n $mount_point ]; then mkdir -p /media/$mount_point # other options (breaks POSIX): noatime,nodiratime,nosuid,nodev mount -t $ID_FS_TYPE \ -o rw,user,uid=0$gid,umask=002,dmask=002,fmask=002 \ $DEVNAME /media/$mount_point /etc/automount/autorun.sh mount $ID_FS_UUID fi
/etc/automount/autoumount.sh :
#!/bin/sh # set the mountpoint name according to partition or device name mount_point=$ID_FS_LABEL if [ -z $mount_point ]; then mount_point=${DEVNAME##*/} fi # remove the mountpoint directory from /media/ (if not empty) if [ -n $mount_point ]; then umount -l /media/$mount_point || \ umount -f /media/$mount_point rm -R /media/$mount_point /etc/automount/autorun.sh umount $ID_FS_UUID fi
example /etc/automount/autorun.sh :
#!/bin/sh #[ "$1" = "mount" ] && [ "$2" = "ABCDEF0123456789" ] && service transmission-daemon restart #[ "$1" = "umount" ] && [ "$2" = "ABCDEF0123456789" ] && service transmission-daemon stop return 0