| 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 | { |
| 7 | delete msg |
| 8 | msg_parse(msg, $0) |
| 9 | } |
| 10 | |
| 11 | msg["node"] == Node && \ |
| 12 | msg["module"] == "khatus_sensor_devices" && \ |
| 13 | msg["type"] == "data" && \ |
| 14 | msg["key"] == "add" && \ |
| 15 | msg["val"] ~ /[0-9]$/ { |
| 16 | mount_device(msg["val"]) |
| 17 | } |
| 18 | |
| 19 | function 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) |
| 37 | msg_out_alert_low("successfully-mounted", path_dev " to " path_mnt) |
| 38 | if (Execute_On_Mount) { |
| 39 | system(Execute_On_Mount " '" path_mnt "'") |
| 40 | } |
| 41 | } else { |
| 42 | msg_out_alert_hi("unexpected-success-line", line) |
| 43 | } |
| 44 | } |
| 45 | } else { |
| 46 | msg_out_alert_hi("failed-to-mount-device", path) |
| 47 | } |
| 48 | } |