Files
box/bin/netvm-accounts.sh
T

31 lines
1.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# netvm-accounts.sh — operator view: login registry joined with live node state.
# Secret-free: reads ACCOUNTS.md (structure) + live topology (state).
set -euo pipefail
NETVM_BIN="$(cd "$(dirname "$0")" && pwd)"
REPO="$(dirname "$NETVM_BIN")"
. "$NETVM_BIN/netvm-names.sh"
# registry rows: only the table under "## Registry", skip header/separator
registry() {
awk '/^## Registry/{f=1;next} f && /^\|/ && !/profile\/node/ && !/---/' "$REPO/ACCOUNTS.md"
}
live() { # <node> -> "up <egress>" or "down"
local out
out=$(sudo -n "$NETVM_BIN/netvm-topology.sh" 2>/dev/null | grep "^node=${1} " || true)
if [ -z "$out" ]; then echo "down"
else echo "up $(echo "$out" | grep -oP 'egress=\K[^ ]*')"; fi
}
registry | while IFS='|' read -r _ login _ profile purpose auth rest; do
login=$(echo "$login" | xargs); profile=$(echo "$profile" | xargs)
auth=$(echo "$auth" | xargs); purpose=$(echo "$purpose" | xargs)
[ -n "$profile" ] && [ "$profile" != "—" ] || continue
netvm_names "$profile"
st=$(live "$profile")
printf '%-8s login=%-8s auth=%-16s %-22s cdp=http://%s:%s\n' \
"$profile" "$login" "$auth" "($purpose)" "$PEER_IP" "$CDP_PORT"
printf '%-8s node state: %s\n' "" "$st"
done