Skip to content

Instantly share code, notes, and snippets.

@pgaertig
Created July 8, 2017 21:39
Show Gist options
  • Save pgaertig/067be745e6eee7c1fb65869e5b084ad7 to your computer and use it in GitHub Desktop.
Save pgaertig/067be745e6eee7c1fb65869e5b084ad7 to your computer and use it in GitHub Desktop.
Ubuntu experiment to automount VFAT partitions without marking files with executable permission (fmask)
# vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=udevrules:
#
# /etc/udev/rules.d/99-vfat-media-automount.rules
KERNEL!="sd[b-z]*", GOTO="vfat-media-automount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_TYPE}!="vfat", GOTO="vfat-media-automount_end"
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"
IMPORT{program}="/usr/bin/udev_x_user"
ENV{CURRENT_USER}=="", ENV{CURRENT_USER}="root"
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", ENV{mount_options}="$env{mount_options},noatime,gid=1000,dmask=000,fmask=111,utf8", ENV{UDISKS_IGNORE}="1", \
ACTION=="add", ENV{ID_FS_TYPE}=="vfat", RUN+="/bin/mkdir -m 0 -p /media/%E{CURRENT_USER}/%E{dir_name}", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{CURRENT_USER}/%E{dir_name}'"
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{CURRENT_USER}/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{CURRENT_USER}/%E{dir_name}'"
LABEL="vfat-media-automount_end"
#!/bin/sh
#This file prints CURRENT_USER variable export with user of first X11 session
#Put the file under `/usr/bin` and set `a+x` permissions
/usr/bin/who | /bin/grep '(:'`/bin/ls /tmp/.X11-unix/* | /bin/sed 's#/tmp/.X11-unix/X##' | /usr/bin/head -n 1`')' | (/bin/echo -n 'CURRENT_USER=' && /usr/bin/awk '{print $1}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment