From 1ab73a8d2a6e1333c9d51da832ead4e250ac5ec5 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 19 Mar 2017 12:10:30 +0100 Subject: [PATCH] new method to detect media change --- sbin/thewhispererindarkness.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 sbin/thewhispererindarkness.sh diff --git a/sbin/thewhispererindarkness.sh b/sbin/thewhispererindarkness.sh new file mode 100755 index 0000000..023d67b --- /dev/null +++ b/sbin/thewhispererindarkness.sh @@ -0,0 +1,27 @@ +#!/bin/sh + + + +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 + #echo $STATE + #echo $EVENT + #echo $DEVPATH + if [ "$STATE" = "DISK_MEDIA_CHANGE=1" ] + then + echo "change detected" + if udisksctl info -b /dev/sda | grep filesystem + then + #echo "filesystem detected" + DEVNAME=$(pathtoname "$DEVPATH") + udisksctl mount --block-device "$DEVNAME" --no-user-interaction + fi + fi +done + +