KERNEL!="sd[a-z][0-9]", GOTO="end" # Import FS infos IMPORT{program}="/sbin/blkid -o udev -p %N" # Get a label if present, otherwise specify one ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}" ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k" ENV{mpd_home}="/data/music/" ENV{mpc}="/usr/bin/mpc" # Global mount options ACTION=="add", ENV{mount_options}="relatime" # Filesystem-specific mount options ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002" # Mount the device ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}", RUN+="/usr/bin/ln -s /media/%E{dir_name} %E{mpd_home}usb" RUN+="%E{mpc} -w update usb", RUN+="%E{mpc} clear", RUN+="%E{mpc} add usb", RUN+="%E{mpc} play" # Clean up after removal ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}",RUN+="%E{mpc} clear", RUN+="%E{mpc} update usb", RUN+="/usr/bin/rm %E{mpd_home}usb", RUN+="/bin/rmdir /media/%E{dir_name}" # Exit LABEL="end"