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 |
Initial commit
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/automount-clean | 9 | ||||
-rwxr-xr-x | scripts/automountd | 19 |
2 files changed, 28 insertions, 0 deletions
diff --git a/scripts/automount-clean b/scripts/automount-clean new file mode 100755 index 0000000..eff3cc9 --- /dev/null +++ b/scripts/automount-clean @@ -0,0 +1,9 @@ +#!/bin/sh + +while sleep 10; do + find "/media/$USER" -mindepth 1 -maxdepth 1 -printf "%P\n" | while read -r mount; do + [ -n "$(lsblk | grep -F "$mount")" ] && continue + sudo fusermount -u "/media/$USER/$mount" + rmdir -v "/media/$USER/$mount" + done +done 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 |