diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2024-11-21 13:54:38 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2024-11-21 13:54:38 +0530 |
commit | 6a16bbdcdb40406592e47ee8d489f857837e5c96 (patch) | |
tree | 8d1a9f72115a106657e059f56e5b47df1a92f483 /scripts/automountd |
Initial commit
Diffstat (limited to 'scripts/automountd')
-rwxr-xr-x | scripts/automountd | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/automountd b/scripts/automountd new file mode 100755 index 0000000..7276922 --- /dev/null +++ b/scripts/automountd @@ -0,0 +1,19 @@ +#!/bin/sh + +pathtoname() { + udevadm info -p /sys/"$1" | awk -v FS== '/DEVNAME/ {print $2}' +} + +stdbuf -oL -- udevadm monitor --udev -s block | while read -r -- _ _ event devpath _; do + if [ "$event" = add ]; then + devname=$(pathtoname "$devpath") + # udisksctl mount --block-device "$devname" --no-user-interaction + + target="$(lsblk -no LABEL "$devname")" + [ -z "$target" ] && target="$(lsblk -no UUID "$devname")" + [ -z "$target" ] && continue + sudo mount -v --mkdir "$devname" "/media/root/$target" + mkdir -pv "/media/master/$target" + sudo bindfs -u $(id -u) -g $(id -g) "/media/root/$target" "/media/master/$target" + fi +done |