Implement device auto-mounter
[khatus.git] / bin / khatus_actuate_device_add_to_automount
CommitLineData
dffa7e60
SK
1#! /usr/bin/awk -f
2
3BEGIN {
4 FS = msg_fs ? msg_fs : "|"
5 OFS = msg_fs ? msg_fs : "|"
6 Kfs = key_fs ? key_fs : ":"
7 Module = "khatus_actuate_device_add_to_automount"
8}
9
10$1 == "OK" && \
11$2 == "khatus_sensor_devices" && \
12$3 == "add" && \
13$4 ~ /[0-9]$/ {
14 mount_device($4)
15}
16
17function mount_device(path, cmd, line, lines, line_count, status, i,
18 path_dev, path_mnt) {
19 cmd="udisksctl mount --block-device " path " --no-user-interaction; echo $?"
20 while(cmd | getline line) {
21 lines[++line_count] = line
22 }
23 close(cmd)
24 status = lines[line_count]
25 line_count--
26 if (status == 0) {
27 for (i=1; i<=line_count; i++) {
28 line = lines[i]
29 if (line ~ /^Mounted /) {
30 split(line, parts, " +")
31 path_dev=parts[2]
32 path_mnt=line
33 sub("^Mounted " path_dev " at ", "", path_mnt)
34 sub("\.$", "", path_mnt)
35 alert("low", "successfully-mounted", path_dev " to " path_mnt)
36 } else {
37 alert("hi", "unexpected-success-line", line)
38 }
39 }
40 } else {
41 alert("hi", "failed-to-mount-device", path)
42 }
43}
44
45function alert(priority, subject, body) {
46 # priority : "low" | "med" | "hi"
47 # subject : no spaces
48 # body : anything
49 print("OK", Module, "alert", priority, subject, body)
50}
This page took 0.022617 seconds and 4 git commands to generate.