Implement device auto-mounter
authorSiraaj Khandkar <siraaj@khandkar.net>
Sat, 25 Aug 2018 17:25:36 +0000 (13:25 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Sat, 25 Aug 2018 17:29:10 +0000 (13:29 -0400)
bin/khatus_actuate_device_add_to_automount [new file with mode: 0755]
sanity_check

diff --git a/bin/khatus_actuate_device_add_to_automount b/bin/khatus_actuate_device_add_to_automount
new file mode 100755 (executable)
index 0000000..2c30f9f
--- /dev/null
@@ -0,0 +1,50 @@
+#! /usr/bin/awk -f
+
+BEGIN {
+     FS = msg_fs ? msg_fs : "|"
+    OFS = msg_fs ? msg_fs : "|"
+    Kfs = key_fs ? key_fs : ":"
+    Module = "khatus_actuate_device_add_to_automount"
+}
+
+$1 == "OK" && \
+$2 == "khatus_sensor_devices" && \
+$3 == "add" && \
+$4 ~ /[0-9]$/ {
+    mount_device($4)
+}
+
+function mount_device(path,    cmd, line, lines, line_count, status, i,
+                               path_dev, path_mnt) {
+    cmd="udisksctl mount --block-device " path " --no-user-interaction; echo $?"
+    while(cmd | getline line) {
+        lines[++line_count] = line
+    }
+    close(cmd)
+    status = lines[line_count]
+    line_count--
+    if (status == 0) {
+        for (i=1; i<=line_count; i++) {
+            line = lines[i]
+            if (line ~ /^Mounted /) {
+                split(line, parts, " +")
+                path_dev=parts[2]
+                path_mnt=line
+                sub("^Mounted " path_dev " at ", "", path_mnt)
+                sub("\.$", "", path_mnt)
+                alert("low", "successfully-mounted", path_dev " to " path_mnt)
+            } else {
+                alert("hi", "unexpected-success-line", line)
+            }
+        }
+    } else {
+        alert("hi", "failed-to-mount-device", path)
+    }
+}
+
+function alert(priority, subject, body) {
+    # priority : "low" | "med" | "hi"
+    # subject  : no spaces
+    # body     : anything
+    print("OK", Module, "alert", priority, subject, body)
+}
index fdcb394..c0d105b 100755 (executable)
@@ -8,9 +8,10 @@
         -v Opt_Mpd_Song_Max_Chars=10 \
         -v Opt_Net_Interfaces_To_Show=wlp3s0 \
         -v Opt_Pulseaudio_Sink=0 \
-        -v GC_Interval=10 \
+        -v GC_Interval=300 \
     ) \
     >(stdbuf -o L ./bin/khatus_monitor_energy) \
     >(stdbuf -o L ./bin/khatus_monitor_errors) \
     >(stdbuf -o L ./bin/khatus_monitor_devices) \
+    >(stdbuf -o L ./bin/khatus_actuate_device_add_to_automount) \
 > /dev/null
This page took 0.0234799999999999 seconds and 4 git commands to generate.