all repos — zion-terminal @ main

dotfiles

opt/zion-terminal/bin/zion-motd (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
#!/usr/bin/env bash
# =====================================================================
# ZION TERMINAL - MOTD (painel de inicializacao)
# Cyberdeck criado por Pablo Murad em 2026
# ---------------------------------------------------------------------
# Blocos em caixas (SISTEMA/RECURSOS/LINKS) + boot-sequence com estados
# reais/cache. Consciente de largura e de terminais sem cor/UTF-8.
# Rapido (le cache /run/zion/status). Nao roda em scp/sftp/rsync.
# =====================================================================
export LC_ALL=C
ZION_DIR="/opt/zion-terminal"
. "$ZION_DIR/bin/zion-lib.sh" 2>/dev/null

cols=$(ui_cols)
anim=1; { [ -n "${ZION_NO_ANIM:-}" ] || [ ! -t 1 ] || [ "${TERM:-dumb}" = dumb ]; } && anim=0
dumb=0; { [ "${TERM:-dumb}" = dumb ] || [ -n "${NO_COLOR:-}" ]; } && dumb=0   # cor controlada pelo tema

# --- Boot-sequence com estados reais (<=1,5s) ----------------------
if [ "$anim" = 1 ]; then
  bs() { printf '  %b%-16s%b %b\n' "$ZDISC" "$1" "$ZR" "$(ui_state "$2")"; sleep 0.05; }
  printf '  %b%s BOOT SEQUENCE%b\n' "$ZP$ZB" "$ZSYM" "$ZR"
  # Nucleo: estamos rodando
  bs "Nucleo" ok
  # Armazenamento: root montado + uso
  if mount | grep -q ' / '; then dp=$(zion_disco_pct); [ "$dp" -ge 90 ] && bs "Armazenamento" warn || bs "Armazenamento" ok; else bs "Armazenamento" crit; fi
  # Rede: rota default
  ip route show default 2>/dev/null | grep -q . && bs "Rede" ok || bs "Rede" warn
  # Tailscale: cache
  case "$(zion_cache_get TS_ESTADO)" in conectado) bs "Tailscale" ok;; parado) bs "Tailscale" warn;; *) bs "Tailscale" nd;; esac
  # SSH
  [ "$(systemctl is-active ssh 2>/dev/null)" = active ] && bs "SSH" ok || bs "SSH" warn
  # Termico
  t=$(zion_temp_c); if [ "$t" -ge 80 ]; then bs "Termico" crit; elif [ "$t" -ge 65 ]; then bs "Termico" warn; else bs "Termico" ok; fi
  printf '  %bLINK ESTABELECIDO%b — %bBEM-VINDO, PABLO%b\n\n' "$ZOK$ZB" "$ZR" "$ZA" "$ZR"
fi

# --- Logo por largura ----------------------------------------------
logo() {
  local f
  if [ "${TERM:-dumb}" = dumb ]; then f="$ZION_DIR/assets/ascii/logo-completa-sem-cor.txt"
  elif [ "$cols" -ge 64 ]; then f="$ZION_DIR/assets/ascii/logo-completa.txt"
  elif [ "$cols" -ge 42 ]; then f="$ZION_DIR/assets/ascii/logo-media.txt"
  else f="$ZION_DIR/assets/ascii/logo-compacta.txt"; fi
  [ -r "$f" ] && { printf '%b' "$ZP$ZB"; sed 's/^/  /' "$f"; printf '%b' "$ZR"; } || printf '  %b%s ZION TERMINAL%b\n' "$ZP$ZB" "$ZSYM" "$ZR"
}
logo
printf '  %bCyberdeck criado por Pablo Murad em 2026%b\n\n' "$ZA" "$ZR"

# --- Metricas ------------------------------------------------------
W=$(( cols - 8 )); [ "$W" -gt 46 ] && W=46; [ "$W" -lt 26 ] && W=26
so=$(. /etc/os-release; echo "Debian $VERSION_ID")
temp=$(zion_temp_c); tst=ok; [ "$temp" -ge 65 ] && tst=warn; [ "$temp" -ge 80 ] && tst=crit
tcor=$ZOK; [ "$tst" = warn ] && tcor=$ZWARN; [ "$tst" = crit ] && tcor=$ZCRIT
dp=$(zion_disco_pct); dcor=$(zion_nivel_pct "$dp")
rp=$(zion_ram_pct); rcor=$(zion_nivel_pct "$rp")
ts=$(zion_cache_get TS_ESTADO); [ -z "$ts" ] && ts=$(zion_ts_estado)
net=$(zion_cache_get INTERNET); [ -z "$net" ] && net=$(zion_internet)
falhas=$(zion_falhas)

ui_box_top "SISTEMA" "$W"
ui_box_kv "Host"   "$(hostname)" "$W"
ui_box_kv "Sistema" "$so" "$W"
ui_box_kv "Kernel" "$(uname -r | cut -d- -f1)" "$W"
ui_box_kv "Uptime" "$(zion_uptime)" "$W"
ui_box_bot "$W"

ui_box_top "RECURSOS" "$W"
ui_box_kv "CPU"    "$(zion_cpu_pct)%" "$W"
ui_box_kv "RAM"    "$(zion_ram_str)" "$W" "$rcor"
ui_box_kv "Disco"  "${dp}%" "$W" "$dcor"
ui_box_line "$(printf '%b%-11s%b %b%s C%b  %b' "$ZDISC" "Temperatura" "$ZR" "$tcor" "$temp" "$ZR" "$(ui_state "$tst")")" "$W"
ui_box_bot "$W"

# LINKS (mostra IP so quando cabe)
lanip=$(zion_ip_local); tsip=$(zion_ip_ts)
ipsuf() { [ "$W" -ge 38 ] && printf '  %s' "$1"; }
ui_box_top "LINKS" "$W"
ui_box_line "$(printf '%b%-11s%b %b%s' "$ZDISC" "LAN" "$ZR" "$([ -n "$lanip" ] && ui_state ok || ui_state off)" "$(ipsuf "${lanip:-—}")")" "$W"
ui_box_line "$(printf '%b%-11s%b %b' "$ZDISC" "Internet" "$ZR" "$([ "$net" = disponivel ] && ui_state ok || ui_state off)")" "$W"
ui_box_line "$(printf '%b%-11s%b %b%s' "$ZDISC" "Tailscale" "$ZR" "$([ "$ts" = conectado ] && ui_state ok || ui_state off)" "$(ipsuf "${tsip:-—}")")" "$W"
ui_box_line "$(printf '%b%-11s%b %b' "$ZDISC" "SSH" "$ZR" "$([ "$(systemctl is-active ssh 2>/dev/null)" = active ] && ui_state ok || ui_state warn)")" "$W"
ui_box_bot "$W"

# --- Alertas (so quando houver) ------------------------------------
alertas=()
[ "$falhas" -gt 0 ] && alertas+=("$falhas servico(s) com falha — veja: zion saude")
[ "$tst" = crit ] && alertas+=("temperatura critica: ${temp} C")
[ "$net" != disponivel ] && alertas+=("sem internet")
if [ ${#alertas[@]} -gt 0 ]; then
  printf '\n'; for a in "${alertas[@]}"; do ui_warn "$a"; done
fi

# --- Instrucao final -----------------------------------------------
tag="Rede pronta. Terminal operacional."
printf '\n'
if [ "$anim" = 1 ]; then printf '  %b' "$ZP"; for ((i=0;i<${#tag};i++)); do printf '%s' "${tag:$i:1}"; sleep 0.005; done; printf '%b\n' "$ZR"
else printf '  %b%s%b\n' "$ZP" "$tag" "$ZR"; fi
printf '  %bDigite %b»Z» zion%b%b para abrir o painel.%b\n\n' "$ZGRY" "$ZA" "$ZR" "$ZGRY" "$ZR"