65 lines
1.6 KiB
Bash
65 lines
1.6 KiB
Bash
#!/bin/sh
|
|
# Usage: ./duediligence.sh [/path/to/config.json]
|
|
set -eu
|
|
|
|
CFG="${1:-/tmp/config.json}"
|
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
echo '{"error":"jq not found in PATH"}'
|
|
exit 2
|
|
fi
|
|
|
|
if [ ! -f "$CFG" ]; then
|
|
# Still emit JSON so Ansible can parse the error
|
|
printf '{"error":"config not found: %s"}\n' "$CFG"
|
|
exit 2
|
|
fi
|
|
|
|
jq -c '
|
|
def classify(n):
|
|
if n==0 then "NO_VAPS"
|
|
elif n==1 then "ONE_VAP"
|
|
elif n==2 then "TWO_VAPS"
|
|
else "MORE_THAN_TWO_VAPS" end;
|
|
|
|
def radio_summary($r):
|
|
( .wireless.radios[$r] // {} ) as $rad
|
|
| ( $rad.vaps // [] ) as $v
|
|
| {
|
|
radio_enabled: ($rad.enabled // false),
|
|
radio_mode: ($rad.mode // "unknown"),
|
|
vaps_total: ($v | length),
|
|
indices: ( $v | to_entries | map(.key) ),
|
|
enabled_ap_indices:
|
|
( $v
|
|
| to_entries
|
|
| map(select(.value.mode=="ap" and (.value.enabled==true)) | .key)
|
|
),
|
|
classification: classify($v | length),
|
|
vaps:
|
|
( $v
|
|
| to_entries
|
|
| map({
|
|
index: .key,
|
|
mode: (.value.mode // "null"),
|
|
enabled: (.value.enabled // false),
|
|
lbd: (.value.lbd // null),
|
|
zone: (.value.network.zone // null),
|
|
ssid: (.value.ssid // "")
|
|
})
|
|
)
|
|
};
|
|
|
|
{
|
|
file: input_filename,
|
|
radios: {
|
|
wifi0: radio_summary("wifi0"),
|
|
wifi1: radio_summary("wifi1"),
|
|
wlan0: radio_summary("wlan0")
|
|
},
|
|
global: {
|
|
preferred5G: (.wireless.lbd.preferred5G // null)
|
|
}
|
|
}
|
|
' "$CFG"
|