60-runv (4816B)
1 #!/bin/sh 2 # runv.club — MOTD dinâmico (Debian update-motd.d) 3 # 4 # RUNV em verde (ANSI); tagline e rodapé — alinhado a site/public/index.html 5 # e terminal/entre_app.py (RUNV_ASCII_ART / ASCII_TAGLINE). 6 # Estatísticas gerais: runv-status (só pmurad-admin); aqui: lista de comandos + sessões recentes. 7 # 8 # Cores: printf %b com literais \033 (POSIX). Sem echo -e. 9 10 R='\033[0m' 11 G='\033[0;32m' 12 Y='\033[0;33m' 13 B='\033[1m' 14 D='\033[2m' 15 16 # Bloco RUNV (UTF-8) — só este trecho em verde brilhante 17 print_runv_art() { 18 while IFS= read -r line || [ -n "$line" ]; do 19 printf '%b%s%b\n' '\033[1;32m' "$line" '\033[0m' 20 done <<'RUNV_ART' 21 ██████╗ ██╗ ██╗███╗ ██╗██╗ ██╗ 22 ██╔══██╗██║ ██║████╗ ██║██║ ██║ 23 ██████╔╝██║ ██║██╔██╗ ██║██║ ██║ 24 ██╔══██╗╚██╗ ██╔╝██║╚██╗██║╚██╗ ██╔╝ 25 ██║ ██║ ╚████╔╝ ██║ ╚████║ ╚████╔╝ 26 ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═══╝ ╚═══╝ 27 RUNV_ART 28 } 29 30 # MOTD: até 9 utilizadores únicos com sessão recente (last(1)) → grelha 3×3 31 # Histórico wtmp; não é presença em tempo real (runv-status + who para admin). 32 # Cada nome aparece uma vez: ordem = login mais recente daquele user (primeira linha em last). 33 # update-motd.d costuma ter PATH mínimo: tentar /usr/bin/last e /bin/last. 34 print_last_sessions_3x3() { 35 LAST_CMD=$(command -v last 2>/dev/null) || LAST_CMD= 36 [ -z "$LAST_CMD" ] && [ -x /usr/bin/last ] && LAST_CMD=/usr/bin/last 37 [ -z "$LAST_CMD" ] && [ -x /bin/last ] && LAST_CMD=/bin/last 38 if [ -z "$LAST_CMD" ]; then 39 printf ' %b\n' "${D}(comando last indisponível — em Debian 13+ instale o pacote wtmpdb: apt install wtmpdb)${R}" 40 return 41 fi 42 tf=$(mktemp -t runvmotd.XXXXXX 2>/dev/null) || tf=/tmp/runvmotd.$$ 43 trap 'rm -f "$tf"' EXIT HUP INT 44 # Ignora reboot, wtmp, entre/root, contas *-admin; até 9 utilizadores distintos 45 "$LAST_CMD" -w -n 500 2>/dev/null | awk ' 46 /^reboot/ || /^wtmp/ || /^$/ { next } 47 NF < 1 { next } 48 { 49 u = $1 50 if (u == "entre" || u == "root") next 51 if (u ~ /-admin$/) next 52 if (u in seen) next 53 seen[u] = 1 54 print u 55 if (++n >= 9) exit 56 } 57 ' > "$tf" || true 58 59 if ! [ -s "$tf" ]; then 60 printf ' %b\n' "${D}(sem registos recentes em wtmp)${R}" 61 rm -f "$tf" 62 trap - EXIT HUP INT 63 return 64 fi 65 66 printf '\n%bÚltimos acessos recentes%b\n' "${B}" "${R}" 67 printf ' %b(um nome por membro; histórico wtmp; não é quem está online)%b\n' "${D}" "${R}" 68 row=1 69 while [ "$row" -le 3 ]; do 70 read -r c1 || c1='' 71 read -r c2 || c2='' 72 read -r c3 || c3='' 73 printf ' %b%-16s%b %b%-16s%b %b%-16s%b\n' \ 74 "${Y}" "$c1" "${R}" \ 75 "${Y}" "$c2" "${R}" \ 76 "${Y}" "$c3" "${R}" 77 row=$((row + 1)) 78 done < "$tf" 79 rm -f "$tf" 80 trap - EXIT HUP INT 81 } 82 83 print_runv_art 84 printf '\n%s\n' '.club — um computador para compartilhar' 85 86 printf '\n%bComandos úteis%b\n' "${B}" "${R}" 87 # Coluna do nome do comando alinhada (maior: runv-email-alias = 16 chars) 88 printf ' %b%-16s%b %b—%b ajuda e boas práticas do runv.club.\n' "${G}" "runv-help" "${R}" "${D}" "${R}" 89 printf ' %b%-16s%b %b—%b links do site e do mantenedor.\n' "${G}" "runv-links" "${R}" "${D}" "${R}" 90 printf ' %b%-16s%b %b—%b navegador web no terminal.\n' "${G}" "lynx" "${R}" "${D}" "${R}" 91 printf ' %b%-16s%b %b—%b multiplexador de terminal (várias sessões).\n' "${G}" "tmux" "${R}" "${D}" "${R}" 92 printf ' %b%-16s%b %b—%b barra de estado e atalhos sobre tmux/screen.\n' "${G}" "byobu" "${R}" "${D}" "${R}" 93 printf ' %b%-16s%b %b—%b cliente de e-mail no terminal.\n' "${G}" "mutt" "${R}" "${D}" "${R}" 94 printf ' %b%-16s%b %b—%b IRC da rede da casa.\n' "${G}" "chat" "${R}" "${D}" "${R}" 95 printf ' %b%-16s%b %b—%b catálogo dos espaços e serviços da casa.\n' "${G}" "runvers" "${R}" "${D}" "${R}" 96 printf ' %b%-16s%b %b—%b catálogo de jogos do servidor.\n' "${G}" "runv-games" "${R}" "${D}" "${R}" 97 98 printf '\n%bComunidade runv%b\n' "${B}" "${R}" 99 printf ' %b%-16s%b %b—%b perfil local (.plan, .project).\n' "${G}" "runv-profile" "${R}" "${D}" "${R}" 100 printf ' %b%-16s%b %b—%b ver perfil de outro membro.\n' "${G}" "runv-finger" "${R}" "${D}" "${R}" 101 printf ' %b%-16s%b %b—%b listar membros da casa.\n' "${G}" "runv-who" "${R}" "${D}" "${R}" 102 printf ' %b%-16s%b %b—%b mural comunitário no terminal.\n' "${G}" "runv-bulletin" "${R}" "${D}" "${R}" 103 printf ' %b%-16s%b %b—%b pedir ou ver alias user@runv.club.\n' "${G}" "runv-email-alias" "${R}" "${D}" "${R}" 104 105 print_last_sessions_3x3 106 107 printf '\n%s\n' '→ Digite runv-help para começar.'