d1a56aa2cca0db8d6b3eb5addf282011c6f0f218
[khatus.git] / src / awk / exe / actuate_device_add_to_automount.awk
1 BEGIN {
2 # Typically some file manager (thunar, pcmanfm, etc.), but can be whatever.
3 Execute_On_Mount = Execute_On_Mount ? Execute_On_Mount : ""
4 }
5
6 $1 == "OK" && \
7 $2 == "khatus_sensor_devices" && \
8 $3 == "add" && \
9 $4 ~ /[0-9]$/ {
10 mount_device($4)
11 }
12
13 function 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)
31 msg_out_ok_alert("low", "successfully-mounted", path_dev " to " path_mnt)
32 if (Execute_On_Mount) {
33 system(Execute_On_Mount " '" path_mnt "'")
34 }
35 } else {
36 msg_out_ok_alert("hi", "unexpected-success-line", line)
37 }
38 }
39 } else {
40 msg_out_ok_alert("hi", "failed-to-mount-device", path)
41 }
42 }
This page took 0.051756 seconds and 3 git commands to generate.