#!/usr/bin/env bash # ZION TERMINAL - Topologia ASCII do tailnet # Cyberdeck criado por Pablo Murad em 2026 export LC_ALL=C . /opt/zion-terminal/bin/zion-lib.sh 2>/dev/null [ "$1" = "--help" ] && { echo "Uso: zion mapa — desenha o tailnet em arvore (peers online/offline, SO, exit nodes)."; exit 0; } command -v tailscale >/dev/null || { echo "Tailscale nao instalado."; exit 1; } self=$(hostname) printf '%b TAILNET — mapa%b\n' "$ZP$ZB" "$ZR"; zion_regua 50 printf ' %b(%s)%b %b%s%b %s\n' "$ZA" "este" "$ZR" "$ZP$ZB" "$self" "$ZR" "$(zion_ip_ts)" printf ' %b│%b\n' "$ZMUT" "$ZR" mapfile -t peers < <(tailscale status 2>/dev/null | awk '/^100\./ && $2!="'"$self"'"{print $0}') n=${#peers[@]}; i=0 for line in "${peers[@]}"; do i=$((i+1)); ip=$(echo "$line" | awk '{print $1}'); name=$(echo "$line" | awk '{print $2}') so=$(echo "$line" | awk '{print $4}'); rest=$(echo "$line" | grep -o 'offline') [ "$i" -eq "$n" ] && ramo="└─" || ramo="├─" if [ -n "$rest" ]; then cor=$ZMUT; st="offline"; else cor=$ZOK; st="online"; fi printf ' %b%s%b %b%-16s%b %b%-8s%b %b%s%b\n' "$ZMUT" "$ramo" "$ZR" "$cor" "$name" "$ZR" "$ZGRY" "$so" "$ZR" "$cor" "$st" "$ZR" done zion_regua 50 online=$(printf '%s\n' "${peers[@]}" | grep -vc offline) printf ' %b%d peers · %d online · exit nodes: %s%b\n' "$ZGRY" "$n" "$online" \ "$(tailscale status 2>/dev/null | grep -c 'offers exit node' 2>/dev/null || echo '?')" "$ZR"