Improve overview and experiment naming
[khatus.git] / x2 / src / awk / exe / actuate_device_add_to_automount.awk
CommitLineData
dffa7e60 1BEGIN {
1fb22bdb
SK
2 # Typically some file manager (thunar, pcmanfm, etc.), but can be whatever.
3 Execute_On_Mount = Execute_On_Mount ? Execute_On_Mount : ""
dffa7e60
SK
4}
5
81336934
SK
6{
7 delete msg
8 msg_parse(msg, $0)
9}
10
11msg["node"] == Node && \
12msg["module"] == "khatus_sensor_devices" && \
13msg["type"] == "data" && \
14msg["key"] == "add" && \
15msg["val"] ~ /[0-9]$/ {
16 mount_device(msg["val"])
dffa7e60
SK
17}
18
19function mount_device(path, cmd, line, lines, line_count, status, i,
20 path_dev, path_mnt) {
21 cmd="udisksctl mount --block-device " path " --no-user-interaction; echo $?"
22 while(cmd | getline line) {
23 lines[++line_count] = line
24 }
25 close(cmd)
26 status = lines[line_count]
27 line_count--
28 if (status == 0) {
29 for (i=1; i<=line_count; i++) {
30 line = lines[i]
31 if (line ~ /^Mounted /) {
32 split(line, parts, " +")
33 path_dev=parts[2]
34 path_mnt=line
35 sub("^Mounted " path_dev " at ", "", path_mnt)
36 sub("\.$", "", path_mnt)
8482fea6 37 msg_out_alert_low("successfully-mounted", path_dev " to " path_mnt)
1fb22bdb
SK
38 if (Execute_On_Mount) {
39 system(Execute_On_Mount " '" path_mnt "'")
40 }
dffa7e60 41 } else {
8482fea6 42 msg_out_alert_hi("unexpected-success-line", line)
dffa7e60
SK
43 }
44 }
45 } else {
8482fea6 46 msg_out_alert_hi("failed-to-mount-device", path)
dffa7e60
SK
47 }
48}
This page took 0.020037 seconds and 4 git commands to generate.