aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-support/udisks/files/automount.sh
blob: 3e4b24b5f68c00e93f385c7fd4d9d231fce9b806 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

pathtoname() {
	udevadm info -p /sys/"$1" | awk -v FS== '/DEVNAME/ {print $2}'
}

MOUNT_OPTIONS="ro,sync"

rmdir /media/* &> /dev/null || true
for DEVNAME in $(udisks --enumerate-device-files|grep -e sd[a-z][0-9]); do
	udisks --mount-options $MOUNT_OPTIONS --mount $DEVNAME
done

stdbuf -oL -- udevadm monitor --udev -s block | while read -r -- _ _ event devpath _; do
	if [ "$event" = add ]; then
		DEVNAME=$(pathtoname "$devpath")
		udisks --mount-options $MOUNT_OPTIONS --mount $DEVNAME
	fi
done