#!/usr/bin/env bash # ZION TERMINAL - Autoteste (POST) # 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 doctor — verifica subsistemas e mostra checklist OK/FALHA. Codigo de saida = nº de falhas."; exit 0; } falhas=0 chk() { if [ "$2" -eq 0 ]; then printf ' %b[ OK ]%b %-26s %b%s%b\n' "$ZOK" "$ZR" "$1" "$ZGRY" "$3" "$ZR"; else printf ' %b[FALHA]%b %-26s %b%s%b\n' "$ZCRIT" "$ZR" "$1" "$ZWARN" "$3" "$ZR"; falhas=$((falhas+1)); fi; } ui_header "AUTOTESTE (POST)" systemctl is-active ssh >/dev/null 2>&1; chk "Servico SSH ativo" $? "$(systemctl is-enabled ssh 2>/dev/null)" systemctl is-active tailscaled >/dev/null 2>&1; chk "Servico Tailscale ativo" $? "$(systemctl is-enabled tailscaled 2>/dev/null)" tailscale status >/dev/null 2>&1; chk "Tailscale conectado" $? "$(zion_ip_ts)" getent hosts deb.debian.org >/dev/null 2>&1; chk "Resolucao DNS" $? "" [ "$(zion_internet)" = disponivel ]; chk "Internet" $? "$(zion_internet)" temp=$(zion_temp_c); [ "$temp" -lt 80 ]; chk "Temperatura < 80C" $? "${temp}C" [ "$(zion_disco_pct)" -lt 90 ]; chk "Disco < 90%" $? "$(zion_disco_pct)%" [ "$(zion_ram_pct)" -lt 90 ]; chk "RAM < 90%" $? "$(zion_ram_pct)%" [ "$(zion_falhas)" -eq 0 ]; chk "Servicos sem falha" $? "$(zion_falhas) falhas" [ -x /usr/local/bin/zion ]; chk "Comando 'zion' instalado" $? "" [ -x /opt/zion-terminal/bin/zion-motd ]; chk "MOTD instalado" $? "" [ -r /opt/zion-terminal/lib/zion-ui.sh ]; chk "Biblioteca de UI" $? "" grep -q rotate /boot/orangepiEnv.txt 2>/dev/null; chk "Rotacao de tela" $? "paisagem" ui_rule if [ "$falhas" -eq 0 ]; then printf ' %b%s TODOS OS SISTEMAS OPERACIONAIS%b\n' "$ZOK$ZB" "$ZSYM" "$ZR" else printf ' %b%s %d VERIFICACAO(OES) COM FALHA%b\n' "$ZCRIT$ZB" "$ZSYM" "$falhas" "$ZR"; fi exit "$falhas"