# Media automounting
#SUBSYSTEM=="block", ACTION=="add" RUN+="/etc/udev/scripts/mount.sh"
#SUBSYSTEM=="block", ACTION=="remove" RUN+="/etc/udev/scripts/mount.sh"
# put all removable devices in group "plugdev"
KERNEL=="sd*[!0-9]", ATTR{removable}=="1", GROUP="plugdev"
KERNEL=="sd*[0-9]", ATTRS{removable}=="1", GROUP="plugdev"
KERNEL=="mmcblk0*[2-9]", GROUP="plugdev"
KERNEL=="mmcblk1", GROUP="plugdev"
KERNEL=="mmcblk1*[0-9]", GROUP="plugdev"
KERNEL!="mmcblk[0-1]p[0-9]", GOTO="sd_cards_auto_mount_end"
# 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}="%k"
# Global mount options
ACTION=="add", ENV{mount_options}="noatime"
# Filesystem specific options
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=83,umask=0000,fmask=0000,dmask=0000,dirsync"
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
ACTION=="remove", RUN+="/usr/bin/pumount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
LABEL="sd_cards_auto_mount_end"
KERNEL!="sd[a-z][0-9]", GOTO="usb_auto_mount_end"
# 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}="%k"
# Global mount options
ACTION=="add", ENV{mount_options}="noatime"
# Filesystem specific options
ACTION=="add", IMPORT{program}="/sbin/blkid -o udev -p %N"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=83,umask=0000,fmask=0000,dmask=0000,dirsync"
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"
ACTION=="remove", RUN+="/usr/bin/pumount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"
LABEL=usb_auto_mount_end"