From 7d595814058c66a3b429453a8d54ec15d0160152 Mon Sep 17 00:00:00 2001 From: Marcelo Santos <117441129+marcelo-m7@users.noreply.github.com> Date: Sun, 31 Aug 2025 11:07:45 +0100 Subject: [PATCH] chore(maintenance): align codebase & docs to Monynha standards --- .gitattributes | 1 + .github/workflows/lint_test.yml | 1 + .pre-commit-config.yaml | 8 +- CODEOWNERS | 1 + CODE_OF_CONDUCT.md | 4 + CONTRIBUTING.md | 19 +++++ Makefile | 2 +- README.md | 111 ++++++++++--------------- README.pt-BR.md | 67 +++++++++++++++ SECURITY.md | 4 + VERSION | 1 + bin/mona | 20 +++-- docs/architecture.md | 9 ++ docs/cli-usage.md | 7 ++ docs/contributing.md | 17 ++++ lib/common.sh | 44 +++++----- lib/log.sh | 27 ++++++ modules/base/base.sh | 8 +- modules/coolify/bootstrap.sh | 11 +-- modules/docker/install.sh | 19 +++-- modules/installer/docker.sh | 3 +- modules/installer/github.sh | 3 +- modules/installer/wizard.sh | 3 +- modules/network/nmcli.sh | 9 +- modules/observability/cadvisor.sh | 3 +- modules/observability/node_exporter.sh | 19 ++--- 26 files changed, 282 insertions(+), 139 deletions(-) create mode 100644 .gitattributes create mode 100644 CODEOWNERS create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 README.pt-BR.md create mode 100644 SECURITY.md create mode 100644 VERSION create mode 100644 docs/architecture.md create mode 100644 docs/cli-usage.md create mode 100644 docs/contributing.md create mode 100644 lib/log.sh mode change 100644 => 100755 modules/base/base.sh mode change 100644 => 100755 modules/docker/install.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.github/workflows/lint_test.yml b/.github/workflows/lint_test.yml index cff3c37..564ee24 100644 --- a/.github/workflows/lint_test.yml +++ b/.github/workflows/lint_test.yml @@ -1,6 +1,7 @@ name: lint_test on: push: + branches: [main] pull_request: jobs: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 94ce7d4..55cb146 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_install_hook_types: [pre-commit, pre-push] -default_stages: [commit, push] +default_stages: [pre-commit, pre-push] repos: - repo: local hooks: @@ -18,9 +18,9 @@ repos: entry: ec language: system pass_filenames: false - - id: bats - name: bats + - id: make-test + name: make test entry: make test language: system pass_filenames: false - stages: [push] + stages: [pre-push] diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..ebc242b --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @Monynha-Softwares diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..f8938e5 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,4 @@ +# Code of Conduct + +This project follows the [Contributor Covenant](https://www.contributor-covenant.org/). +By participating, you are expected to uphold this code. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..27192ea --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,19 @@ +# Contributing + +Thank you for considering contributing! + +## Development setup + +```bash +make install-dev +``` + +## Style & tests + +* Format: `make fmt` +* Lint: `make lint` +* Test: `make test` + +Please run the above before submitting a PR. + +See [docs/contributing.md](docs/contributing.md) for more details. diff --git a/Makefile b/Makefile index f8c4ea8..182d088 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ fmt: shfmt -w bin modules recipes tests lint: - shellcheck -x bin/mona modules/**/*.sh + bash -O globstar -c 'shellcheck -x bin/mona modules/**/*.sh' shfmt -d bin modules recipes tests test: diff --git a/README.md b/README.md index 09bb365..971eb92 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,73 @@ -# MonaRepo — Monynha Softwares +# MonaRepo TUI -**Version:** v0.1.0 +[![CI](https://github.com/Monynha-Softwares/MonaRepoTui/actions/workflows/lint_test.yml/badge.svg)](https://github.com/Monynha-Softwares/MonaRepoTui/actions/workflows/lint_test.yml) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) -A base monorepo (Bash-first) to automate VM/server bootstrap with an optional TUI powered by [`bashsimplecurses`](https://github.com/metal3d/bashsimplecurses). -Use this as the starting point for Codex/agents to extend modules and recipes. +Base tooling for Monynha server automation with an optional TUI. + +## TL;DR + +```bash +git clone https://github.com/Monynha-Softwares/MonaRepoTui.git monarepo && cd monarepo +make install-dev +sudo ./bin/mona +``` ## Features -- Single entrypoint: `bin/mona` — interactive TUI (↑/↓, Enter, Q) with a heart header ❤ -- Flows: Quick Start, Distro Upgrade, Network (Netplan), Users & SSH, Hostname/hosts, Run Recipe -- Dry-run mode (`--dry-run`) to preview actions -- CI ready (ShellCheck + BATS), Makefile targets -- Cloud-init template for first-boot provisioning +- Bash modules & recipes +- Interactive TUI +- Dry-run mode +- CI ready (shfmt, shellcheck, bats) -## Getting Started +## Install -```bash -# clone -git clone monarepo && cd monarepo +Clone the repo and install dev deps: -# install development dependencies and git hooks +```bash +git clone https://github.com/Monynha-Softwares/MonaRepoTui.git +cd MonaRepoTui make install-dev +``` -# run full test suite -make test +## Quickstart + +Run the TUI (root recommended): -# run TUI (recommended with sudo/root) +```bash sudo ./bin/mona ``` -### Local hooks - -This repository uses [pre-commit](https://pre-commit.com/) hooks. Formatting -(`shfmt`) and linting (`shellcheck`, `editorconfig-checker`) run on every -commit. The BATS tests run automatically on `git push`. Hooks are installed by -`make install-dev`. You can manually trigger them for all files with: +## Usage ```bash -pre-commit run --all-files +./bin/mona --help ``` -### Run CI tasks locally +## Development -The same checks used in GitHub Actions can be executed locally: +Format and lint: ```bash +make fmt make lint -make test ``` -### Non-interactive/CI flags -- `--version` : prints version and exits -- `--help` : prints help and exits -- `--dry-run` : prints actions instead of applying -- `MONA_NONINTERACTIVE=1` : single-shot non-interactive mode (no curses, no actions) - -### Directory Layout +## Testing -``` -bin/ # entrypoints -lib/ # shared helpers (future work for agents) -modules/ # idempotent modules (base, docker, ...) -recipes/ # orchestration of modules per "role" -templates/ # cloud-init and systemd -tests/ # bats tests -ui/ # optional bashsimplecurses submodule (or runtime fetch) -.github/workflows/ci.yml +```bash +make test ``` -## Cloud-init quick start -Use `templates/cloud-init/user-data.yaml` as user-data for new VMs. It clones your repo into `/opt/monarepo` and runs a recipe. - ## Contributing -- Lint Shell: `make lint` (ShellCheck) -- Tests: `make test` (BATS) -- Keep modules idempotent: **probe → apply → verify** -- Prefer `apply` helper (respects `--dry-run`). - -## License -MIT — see [LICENSE](LICENSE). +See [CONTRIBUTING.md](CONTRIBUTING.md) and [docs/contributing.md](docs/contributing.md). +## Security +See [SECURITY.md](SECURITY.md). -## Included Recipes (examples) -- `recipes/coolify-node.sh` — base + docker + coolify bootstrap (network/dirs) -- `recipes/monitoring-node.sh` — base + docker + node_exporter + cAdvisor -- `recipes/supabase-node.sh` — base + docker (hook para Supabase) - -## Project Installer (Wizard) -Use the TUI option **“Instalar/Configurar Projeto (GitHub/Docker)”** to: -- List or select a GitHub repo (Monynha-Softwares by default) and clone it -- Or pull/run a Docker image quickly -- Then MonaRepo detects common post‑clone actions (e.g., copy `.env.example`, `docker compose up -d`, `npm/pnpm/yarn install`, `make setup`, `supabase start`) and lets you run them step‑by‑step while logging output. +## License +MIT © Monynha Softwares -Logs are stored in `~/.mona/logs` (or `$MONA_LOG_DIR`). `--dry-run` prints commands without executing. +### Monynha Way +Inclusive, accessible and developer‑first. -### Installer extras (v0.4.0) -- **GitHub PAT**: set `GITHUB_TOKEN` to avoid rate limits and access private repos. -- **Interactive `.env`**: when a project has `.env.example`, choose “Criar .env interativo” to fill values key-by-key. -- **Docker Compose advanced**: auto-detects `docker compose` (plugin) or `docker-compose`; offers `pull`, `up -d --remove-orphans`, `ps`, `logs -f`. -- **TUI README viewer** (experimental): set `MONA_USE_TUI_READER=1` to view README inside the TUI; otherwise falls back to `less`. +[Leia em Português](README.pt-BR.md) diff --git a/README.pt-BR.md b/README.pt-BR.md new file mode 100644 index 0000000..314acce --- /dev/null +++ b/README.pt-BR.md @@ -0,0 +1,67 @@ +# MonaRepo TUI + +[![CI](https://github.com/Monynha-Softwares/MonaRepoTui/actions/workflows/lint_test.yml/badge.svg)](https://github.com/Monynha-Softwares/MonaRepoTui/actions/workflows/lint_test.yml) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) + +Ferramenta base da Monynha para automação de servidores com TUI opcional. + +## Resumo + +```bash +git clone https://github.com/Monynha-Softwares/MonaRepoTui.git monarepo && cd monarepo +make install-dev +sudo ./bin/mona +``` + +## Funcionalidades +- Módulos Bash e receitas +- TUI interativo +- Modo dry-run +- CI pronta (shfmt, shellcheck, bats) + +## Instalação + +```bash +git clone https://github.com/Monynha-Softwares/MonaRepoTui.git +cd MonaRepoTui +make install-dev +``` + +## Início rápido + +```bash +sudo ./bin/mona +``` + +## Uso + +```bash +./bin/mona --help +``` + +## Desenvolvimento + +```bash +make fmt +make lint +``` + +## Testes + +```bash +make test +``` + +## Contribuindo +Veja [CONTRIBUTING.md](CONTRIBUTING.md) e [docs/contributing.md](docs/contributing.md). + +## Segurança +Consulte [SECURITY.md](SECURITY.md). + +## Licença +MIT © Monynha Softwares + +### Jeito Monynha +Inclusivo, acessível e focado em DX. + +[Read in English](README.md) diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..289cfc1 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,4 @@ +# Security Policy + +If you discover a security issue, please email security@monynha.dev or open a private issue. +We will respond as soon as possible. diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..1d0ba9e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.4.0 diff --git a/bin/mona b/bin/mona index 7b6312a..31e8b8d 100755 --- a/bin/mona +++ b/bin/mona @@ -1,6 +1,7 @@ #!/usr/bin/env bash # MonaRepo — Interactive TUI bootstrapper -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # Determine repo root early so other scripts can source helpers safely export MONA_BIN_PATH="$(readlink -f "$0")" @@ -9,7 +10,7 @@ export MONA_DIR="$(cd "$(dirname "$MONA_BIN_PATH")/.." && pwd)" # shellcheck source=../lib/common.sh . "$MONA_DIR/lib/common.sh" -VERSION="0.4.0" +VERSION="$(cat "$MONA_DIR/VERSION")" # ------------------------------ Globals ------------------------------------ export MONA_DRY_RUN="${MONA_DRY_RUN:-false}" @@ -31,8 +32,8 @@ Env: EOF } -for a in "$@"; do - case "$a" in +while [[ $# -gt 0 ]]; do + case "$1" in --help) show_help exit 0 @@ -41,9 +42,16 @@ for a in "$@"; do echo "$VERSION" exit 0 ;; - --dry-run) MONA_DRY_RUN=true ;; - *) ;; + --dry-run) + MONA_DRY_RUN=true + ;; + *) + log_error "Flag desconhecida: $1" + show_help + exit 1 + ;; esac + shift done MONA_TMP_DIR="${TMPDIR:-/tmp}/mona" diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..fc74225 --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,9 @@ +# Architecture + +``` +bin/ # entrypoint scripts +lib/ # shared helpers +modules/ # idempotent modules +recipes/ # orchestration of modules +tests/ # BATS tests +``` diff --git a/docs/cli-usage.md b/docs/cli-usage.md new file mode 100644 index 0000000..9eeba46 --- /dev/null +++ b/docs/cli-usage.md @@ -0,0 +1,7 @@ +# CLI Usage + +```bash +./bin/mona --help +./bin/mona --version +MONA_NONINTERACTIVE=1 ./bin/mona --version +``` diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..7df9dfc --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,17 @@ +# Contributing Guide + +## Setup + +```bash +make install-dev +``` + +## Workflow + +1. Create a focused branch. +2. Format: `make fmt` +3. Lint: `make lint` +4. Test: `make test` +5. Commit using Conventional Commits. + +Obrigado! diff --git a/lib/common.sh b/lib/common.sh index 48a3a84..f64ac53 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -1,14 +1,16 @@ #!/usr/bin/env bash # Common helpers for MonaRepo -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' -log() { printf "[mona] %s\n" "$*"; } -warn() { printf "[mona:warn] %s\n" "$*"; } >&2 -err() { printf "[mona:err] %s\n" "$*"; } >&2 -needs_root(){ [[ $EUID -eq 0 ]] || { err "Execute como root (sudo)."; exit 1; }; } -color(){ local c="$1"; shift; printf "\e[%sm%s\e[0m" "$c" "$*"; } +# shellcheck source=log.sh +. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/log.sh" -pm_detect(){ +needs_root() { + [[ $EUID -eq 0 ]] || { log_error "Execute como root (sudo)."; exit 1; } +} + +pm_detect() { if command -v apt-get >/dev/null 2>&1; then echo apt; return; fi if command -v dnf >/dev/null 2>&1; then echo dnf; return; fi if command -v yum >/dev/null 2>&1; then echo yum; return; fi @@ -17,27 +19,27 @@ pm_detect(){ echo unknown } -pkg_install(){ +pkg_install() { local pkgs=("$@") pm pm=$(pm_detect) - log "Instalando pacotes via $pm: ${pkgs[*]}" + log_info "Instalando pacotes via $pm: ${pkgs[*]}" [[ "${MONA_DRY_RUN:-false}" == "true" ]] && return 0 case "$pm" in - apt) apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y "${pkgs[@]}";; - dnf) dnf install -y "${pkgs[@]}";; - yum) yum install -y "${pkgs[@]}";; - pacman) pacman -Sy --noconfirm "${pkgs[@]}";; - zypper) zypper --non-interactive install --no-recommends "${pkgs[@]}";; - *) err "Gerenciador de pacotes não suportado"; return 1;; + apt) apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y "${pkgs[@]}" ;; + dnf) dnf install -y "${pkgs[@]}" ;; + yum) yum install -y "${pkgs[@]}" ;; + pacman) pacman -Sy --noconfirm "${pkgs[@]}" ;; + zypper) zypper --non-interactive install --no-recommends "${pkgs[@]}" ;; + *) log_error "Gerenciador de pacotes não suportado"; return 1 ;; esac } -apply(){ - if [[ "${MONA_DRY_RUN:-false}" == "true" ]]; then - log "(dry-run) $*" - else +apply() { + if [[ "${MONA_DRY_RUN:-false}" == "true" ]]; then + log_info "(dry-run) $*" + else eval "$*" - fi + fi } -pause_any(){ read -r -p $'Pressione Enter para voltar ao menu…\n' _ || true; } +pause_any() { read -r -p $'Pressione Enter para voltar ao menu…\n' _ || true; } diff --git a/lib/log.sh b/lib/log.sh new file mode 100644 index 0000000..52aa4be --- /dev/null +++ b/lib/log.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +IFS=$'\n\t' + +_color_enabled=1 +if [[ -n "${NO_COLOR:-}" || "${MONA_NONINTERACTIVE:-0}" == "1" ]]; then + _color_enabled=0 +fi + +_log() { + local color="$1" msg="$2" + if [[ $_color_enabled -eq 1 && -n "$color" ]]; then + printf "[mona] %s\n" "$(printf '\e[%sm%s\e[0m' "$color" "$msg")" + else + printf "[mona] %s\n" "$msg" + fi +} + +log_info() { _log "" "$*"; } +log_warn() { _log 33 "$*" >&2; } +log_error() { _log 31 "$*" >&2; } +log_success() { _log 32 "$*"; } + +# Backwards compatibility +log() { log_info "$@"; } +warn() { log_warn "$@"; } +err() { log_error "$@"; } diff --git a/modules/base/base.sh b/modules/base/base.sh old mode 100644 new mode 100755 index 789b33e..d742898 --- a/modules/base/base.sh +++ b/modules/base/base.sh @@ -1,20 +1,20 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' +# shellcheck source=../../lib/common.sh +. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" run_base() { - # timezone + basic packages if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone Europe/Lisbon || true fi - # basic security and ssh hardening if [[ -f /etc/ssh/sshd_config ]]; then sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config || true sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config || true systemctl reload ssh || systemctl reload sshd || true fi - # firewall if command -v ufw >/dev/null 2>&1; then ufw allow OpenSSH || true ufw --force enable || true diff --git a/modules/coolify/bootstrap.sh b/modules/coolify/bootstrap.sh index f73dd4f..6689bea 100755 --- a/modules/coolify/bootstrap.sh +++ b/modules/coolify/bootstrap.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" @@ -13,15 +14,15 @@ run_coolify_bootstrap() { if command -v docker >/dev/null 2>&1; then if ! docker network ls --format '{{.Name}}' | grep -qx "coolify"; then apply "docker network create coolify" - log "Docker network 'coolify' criada." + log_success "Docker network 'coolify' criada." else - log "Docker network 'coolify' já existe." + log_info "Docker network 'coolify' já existe." fi else - warn "Docker não encontrado. Execute módulo docker/install antes." + log_warn "Docker não encontrado. Execute módulo docker/install antes." fi # sysctl tuning opcional (descomentado caso precise) # apply "sysctl -w net.ipv4.ip_forward=1" - log "Coolify bootstrap concluído (pastas + network)." + log_info "Coolify bootstrap concluído (pastas + network)." } diff --git a/modules/docker/install.sh b/modules/docker/install.sh old mode 100644 new mode 100755 index e07c366..55b2735 --- a/modules/docker/install.sh +++ b/modules/docker/install.sh @@ -1,29 +1,30 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' +# shellcheck source=../../lib/common.sh +. "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" run_docker_install() { if command -v docker >/dev/null 2>&1; then - echo "[mona] Docker já instalado." + log_info "Docker já instalado." return 0 fi if command -v apt-get >/dev/null 2>&1; then install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ -https://download.docker.com/linux/ubuntu $( + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $( . /etc/os-release - echo $VERSION_CODENAME - ) stable" \ - >/etc/apt/sources.list.d/docker.list + echo \"$VERSION_CODENAME\" + ) stable" >/etc/apt/sources.list.d/docker.list apt-get update -y apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin usermod -aG docker "${SUDO_USER:-$USER}" || true systemctl enable --now docker || true - echo "[mona] Docker instalado (apt)." + log_success "Docker instalado (apt)." return 0 fi - echo "[mona:warn] Implementar instalação Docker para esta distro." + log_warn "Implementar instalação Docker para esta distro." return 1 } diff --git a/modules/installer/docker.sh b/modules/installer/docker.sh index e49db67..d9252dc 100755 --- a/modules/installer/docker.sh +++ b/modules/installer/docker.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" diff --git a/modules/installer/github.sh b/modules/installer/github.sh index c4867c6..f818dca 100755 --- a/modules/installer/github.sh +++ b/modules/installer/github.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" diff --git a/modules/installer/wizard.sh b/modules/installer/wizard.sh index b649ad7..6efaf35 100755 --- a/modules/installer/wizard.sh +++ b/modules/installer/wizard.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" # shellcheck source=github.sh diff --git a/modules/network/nmcli.sh b/modules/network/nmcli.sh index cab87d1..189952d 100755 --- a/modules/network/nmcli.sh +++ b/modules/network/nmcli.sh @@ -1,18 +1,19 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" configure_nmcli() { needs_root if ! command -v nmcli >/dev/null 2>&1; then - err "nmcli não encontrado. Instale NetworkManager ou use Netplan." + log_error "nmcli não encontrado. Instale NetworkManager ou use Netplan." return 1 fi read -r -p "Interface (ex.: eth0): " ifc || true [[ -n "${ifc:-}" ]] || { - err "Interface inválida" + log_error "Interface inválida" return 1 } @@ -27,5 +28,5 @@ configure_nmcli() { apply "nmcli con mod \"$ifc\" ipv4.method manual ipv4.addresses \"$addr\" ipv4.gateway \"$gw\" ipv4.dns \"$dns\" || nmcli con add type ethernet ifname \"$ifc\" con-name \"$ifc\" ipv4.method manual ipv4.addresses \"$addr\" ipv4.gateway \"$gw\" ipv4.dns \"$dns\"" fi apply "nmcli con up \"$ifc\"" - log "Configuração NMCLI aplicada para $ifc." + log_info "Configuração NMCLI aplicada para $ifc." } diff --git a/modules/observability/cadvisor.sh b/modules/observability/cadvisor.sh index 32fe1f7..0b32d12 100755 --- a/modules/observability/cadvisor.sh +++ b/modules/observability/cadvisor.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" diff --git a/modules/observability/node_exporter.sh b/modules/observability/node_exporter.sh index 0e14e1e..95636d0 100755 --- a/modules/observability/node_exporter.sh +++ b/modules/observability/node_exporter.sh @@ -1,26 +1,21 @@ #!/usr/bin/env bash -set -euo pipefail +set -Eeuo pipefail +IFS=$'\n\t' # shellcheck source=../../lib/common.sh . "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)/lib/common.sh" run_node_exporter() { needs_root if ! command -v docker >/dev/null 2>&1; then - err "Docker não instalado. Rode modules/docker/install.sh" + log_error "Docker não instalado. Rode modules/docker/install.sh" return 1 fi local name="node-exporter" if ! docker ps -a --format '{{.Names}}' | grep -qx "$name"; then - apply "docker run -d --restart unless-stopped \ - --name $name \ - --net host \ - --pid host \ - -v /:/host:ro,rslave \ - prom/node-exporter:latest \ - --path.rootfs=/host" - log "Container $name criado." + apply "docker run -d --restart unless-stopped --name \"$name\" --net host --pid host -v /:/host:ro,rslave prom/node-exporter:latest --path.rootfs=/host" + log_success "Container $name criado." else - apply "docker start $name || true" - log "Container $name iniciado." + apply "docker start \"$name\" || true" + log_info "Container $name iniciado." fi }