simplified read loop

master
root 7 years ago
parent 1ab73a8d2a
commit c9c6bf2506

@ -1,25 +1,17 @@
#!/bin/sh #!/bin/sh
stdbuf -oL -- udevadm monitor --udev -p /sys/block/sda | while read -r -- STATE _ _ _ _
pathtoname() {
udevadm info -p /sys/"$1" | awk -v FS== '/DEVNAME/ {print $2}'
}
stdbuf -oL -- udevadm monitor --udev -p /sys/block/sda | while read -r -- STATE _ EVENT DEVPATH _
do do
#echo $STATE
#echo $EVENT
#echo $DEVPATH
if [ "$STATE" = "DISK_MEDIA_CHANGE=1" ] if [ "$STATE" = "DISK_MEDIA_CHANGE=1" ]
then then
echo "change detected" echo "change detected"
if udisksctl info -b /dev/sda | grep filesystem if udisksctl info -b /dev/sda | grep filesystem
then then
#echo "filesystem detected" echo "floppy in (fs detected)"
DEVNAME=$(pathtoname "$DEVPATH") udisksctl mount --block-device /dev/sda --no-user-interaction
udisksctl mount --block-device "$DEVNAME" --no-user-interaction else
echo "floppy out (no fs detected)"
fi fi
fi fi
done done

Loading…
Cancel
Save