Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a label symlink to plugged device #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 00_remove_model_symlink → 00_remove_symlinks
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ set -e
ls /var/run/usbmount | while read name; do
if test "`readlink \"/var/run/usbmount/$name\" || :`" = "$UM_MOUNTPOINT"; then
rm -f "/var/run/usbmount/$name"
break
fi
done

Expand Down
28 changes: 28 additions & 0 deletions 10_create_label_symlink
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# This script creates the model name symlink in /var/run/usbmount.
# Copyright (C) 2005 Martin Dickopp
#
# This file is free software; the copyright holder gives unlimited
# permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
set -e

# Get label or exit if no label
LABEL=`e2label $UM_DEVICE` || exit 0

# Replace spaces with underscores, remove special characters in label
LABEL=`echo "$LABEL" | sed 's/ /_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g'`

# Exit if label is empty.
test -n "$LABEL" || exit 0

# If the symlink does not yet exist, create it.
test -e "/var/run/usbmount/$LABEL" || ln -sf "$UM_MOUNTPOINT" "/var/run/usbmount/$LABEL"

exit 0
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ in, the first available mountpoint is automatically selected.

If the device plugged provides a model name, a symbolic link at
`/var/run/usbmount/MODELNAME` pointing to the mountpoint is automatically
created. When the device is not present anymore in the system (e.g.,
created.

If the device plugged has a label (e2label), a symbolic link at
`/var/run/usbmount/LABEL` pointing to the mountpoint is automatically
created.

When the device is not present anymore in the system (e.g.,
after it has been unplugged), usbmount deletes the symbolic links that
were created.

Expand Down
5 changes: 3 additions & 2 deletions debian/install
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
00_create_model_symlink etc/usbmount/mount.d
00_remove_model_symlink etc/usbmount/umount.d
10_create_label_symlink etc/usbmount/mount.d
00_remove_symlinks etc/usbmount/umount.d
usbmount usr/share/usbmount
usbmount.conf etc/usbmount
90-usbmount.rules lib/udev/rules.d
usbmount@.service lib/systemd/system
usbmount@.service lib/systemd/system