Commit | Line | Data |
---|---|---|
fd22859b SK |
1 | #! /usr/bin/awk -f |
2 | ||
3 | /^Controller / { | |
4 | controller = $2 | |
5 | controllers[++ctrl_count] = controller | |
6 | } | |
7 | ||
8 | /^\t[A-Z][A-Za-z]+:/ { | |
9 | key = $1 | |
10 | sub(":$", "", key) | |
7af746e8 | 11 | sub("^\t" $1 " *", "") |
fd22859b SK |
12 | val = $0 |
13 | data[controller, key] = val | |
14 | } | |
15 | ||
16 | END { | |
17 | # Using the 1st seen controller. Should we select specific instead? | |
18 | power_status = data[controllers[1], "Powered"] | |
19 | if (ctrl_count > 0) { | |
20 | if (power_status == "no") { | |
21 | show = "off" | |
22 | } else if (power_status == "yes") { | |
23 | show = "on" | |
24 | } else { | |
25 | print_error("Unexpected bluetooth power status: " power_status) | |
26 | show = "ERROR" | |
27 | } | |
28 | } else { | |
cdbd6083 | 29 | show = "n/a" |
fd22859b SK |
30 | } |
31 | print(show) | |
32 | } | |
33 | ||
34 | function print_error(msg) { | |
35 | print(msg) > "/dev/stderr" | |
36 | } |