Normalize alert msg
[khatus.git] / 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
6$1 == "OK" && \
7$2 == "khatus_sensor_devices" && \
8$3 == "add" && \
9$4 ~ /[0-9]$/ {
10 mount_device($4)
11}
12
13function mount_device(path, cmd, line, lines, line_count, status, i,
14 path_dev, path_mnt) {
15 cmd="udisksctl mount --block-device " path " --no-user-interaction; echo $?"
16 while(cmd | getline line) {
17 lines[++line_count] = line
18 }
19 close(cmd)
20 status = lines[line_count]
21 line_count--
22 if (status == 0) {
23 for (i=1; i<=line_count; i++) {
24 line = lines[i]
25 if (line ~ /^Mounted /) {
26 split(line, parts, " +")
27 path_dev=parts[2]
28 path_mnt=line
29 sub("^Mounted " path_dev " at ", "", path_mnt)
30 sub("\.$", "", path_mnt)
e103315c 31 msg_out_ok_alert("low", "successfully-mounted", path_dev " to " path_mnt)
1fb22bdb
SK
32 if (Execute_On_Mount) {
33 system(Execute_On_Mount " '" path_mnt "'")
34 }
dffa7e60 35 } else {
e103315c 36 msg_out_ok_alert("hi", "unexpected-success-line", line)
dffa7e60
SK
37 }
38 }
39 } else {
e103315c 40 msg_out_ok_alert("hi", "failed-to-mount-device", path)
dffa7e60
SK
41 }
42}
This page took 0.025596 seconds and 4 git commands to generate.