-
-
Save korjavin/a30ad6820b9f4907548c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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