Skip to content

Instantly share code, notes, and snippets.

@korjavin
Forked from kstep/99-automount.rules
Last active August 29, 2015 14:24
Show Gist options
  • Save korjavin/a30ad6820b9f4907548c to your computer and use it in GitHub Desktop.
Save korjavin/a30ad6820b9f4907548c to your computer and use it in GitHub Desktop.
ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", DRIVERS=="usb-storage", GOTO="automount_go"
ACTION=="remove", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", DRIVERS=="usb-storage", RUN{program}+="/bin/rmdir /media/%E{AUTOMOUNT_NAME}"
GOTO="automount_end"
LABEL="automount_go"
PROGRAM="/usr/local/bin/automount-helper.py $number", GROUP="disk", TAG+="systemd", ENV{AUTOMOUNT_NAME}="$result{1}", ENV{SYSTEMD_WANTS}="usb-mount@$result{2}.service"
LABEL="automount_end"
#!/usr/bin/python2
import os
import sys
import re
automount_name = (
os.environ.get('ID_FS_LABEL') or
os.environ.get('ID_FS_UUID') or
('%s_%s_%s' % (os.environ.get('ID_VENDOR'), os.environ.get('ID_MODEL'), sys.argv[1])))
while os.path.ismount('/media/%s' % automount_name):
automount_name += '_'
service_name = '%s /media/%s' % (os.environ['ID_FS_UUID'], automount_name)
print(automount_name)
print(re.sub(r'[^a-zA-Z0-9_]',
lambda p: hex(ord(p.group(0))).replace('0x', '\\x'),
service_name))
[Unit]
Description=Automount for %i
[Service]
Type=forking
ExecStart=/bin/sh -c "exec /bin/mount -o x-mount.mkdir,gid=disk,umask=0002,nodev,nosuid,noexec,noatime,nodiratime UUID=%I"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment