#!/usr/bin/env bash
set -uo pipefail
for u in wg-quick@wg20 wg-quick@wg21 silvervpn-nodeagent xray silvervpn-nft; do printf '%-24s %s\n' "$u" "$(systemctl is-active "$u")"; done
wg show wg20 | head -5; wg show wg21
curl -fsS http://127.0.0.1:5050/health; echo
if [[ -n "${SSR_OUTPUTS:-}" ]]; then
  jq -n --arg wg "$(cat /etc/wireguard/server_public.key 2>/dev/null)" --arg mg "$(wg pubkey < /etc/wireguard/mgmt_private.key 2>/dev/null)" \
    --arg h "$(curl -fsS http://127.0.0.1:5050/health >/dev/null 2>&1 && echo true || echo false)" \
    '{wgPublicKey:$wg, mgmtPublicKey:$mg, healthy:($h=="true")}' > "$SSR_OUTPUTS"
fi
