From 6bd9f6427b08e8eb32b3202401c7fcabd61352df Mon Sep 17 00:00:00 2001 From: Guido Longoni Date: Thu, 22 Jan 2026 14:04:47 +0100 Subject: [PATCH] aggiornamenti installazione e README --- AGENTS.md | 41 ++++++++++++++++++++++++++++++++++ README.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++- featlib/curl.sh | 12 ++++++---- featlib/docker.sh | 10 ++++----- featlib/npm.sh | 3 +++ featlib/pip.sh | 3 +++ grezzo.sh | 26 +++++++++++++++++++-- 7 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 AGENTS.md mode change 100755 => 100644 README.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..8d1d143 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,41 @@ +# Repository Guidelines + +## Project Structure & Module Organization + +- `grezzo.sh` is the core library with shared helpers (e.g., `feat_needed`, `feat_missing`). +- `featlib/` contains feature installers, one tool per file (`pip.sh`, `docker.sh`, `npm.sh`, `rustup.sh`, `curl.sh`). +- `featlib/poetry/` holds Poetry-specific feature scripts (e.g., `django.sh`). +- Entry-point scripts live at the repo root (e.g., `python.sh`, `node_pip_docker_rust.sh`). + +## Build, Test, and Development Commands + +There is no build system; scripts are executed directly from the repo root. + +- `bash python.sh` installs Python tooling via `pip`/`pyenv`. +- `bash node_pip_docker_rust.sh` installs Node, Pip/Poetry, Docker, and Rust tooling. +- `bash grezzo.sh` can be sourced by other scripts; it is not meant to be run standalone. + +These scripts may call `sudo` and can modify shell configuration files (e.g., `$HOME/.bashrc.before`). + +## Coding Style & Naming Conventions + +- Language: Bash; keep the `#! /bin/bash --` shebang. +- Indentation: prefer 4 spaces (match existing files). +- Functions follow the pattern `feat_add_*`, `feat_needed`, and `*_feat_needed`. +- Use `this_script_path` to resolve relative includes and avoid `cd` assumptions. + +## Testing Guidelines + +No automated tests are present. Validate changes by running the relevant script end-to-end on a test machine and confirming installed tools are available (e.g., `docker --version`, `python --version`). + +## Commit & Pull Request Guidelines + +- Commit messages are short, descriptive, and currently in Italian (see `git log` examples like “aggiornamenti …”, “piccola modifica”). +- Do not add signatures or personal tags in commit messages. +- PRs should describe the target platforms (apt/pacman/apk/yum/zypper) and any system changes made (packages installed, files edited, required restarts). +- Include repro commands and any manual verification performed. + +## Security & Configuration Tips + +- Scripts can install packages system-wide and add APT repositories/keys; review changes carefully. +- Prefer testing in a VM or container and document any OS-specific behavior. diff --git a/README.md b/README.md old mode 100755 new mode 100644 index c3bda0f..2ce84bc --- a/README.md +++ b/README.md @@ -1,3 +1,58 @@ # grezzo -Vedremo man mano che cos'è... Per ora è un tool di supporto all'installazione di librerie e al deployment di software \ No newline at end of file +Tool Bash per installare e garantire la presenza di tooling di sviluppo in modo dichiarativo: +tu dici cosa vuoi, grezzo si occupa di farlo comparire, includendo dipendenze e policy opinionated. + +## Idee chiave + +- Dichiarativo “al top”, imperativo “sotto al cofano”: si usano `feat_needed` e gli installer `feat_add_*`. +- Include-once: ogni script in `featlib/` si carica una sola volta. +- Policy opinionated: priorita' su Mint, Debian, Ubuntu, Arch; poi altri Linux. + +## Struttura + +- `grezzo.sh`: core (helper comuni e `feat_needed`). +- `featlib/`: installer per singole feature (es. `pip.sh`, `docker.sh`, `npm.sh`). +- `featlib/poetry/`: estensioni Poetry (es. `django.sh`). +- Script di esempio nella root (es. `python.sh`, `node_pip_docker_rust.sh`). + +## Come si usa + +Scrivi uno script dichiarativo con le feature che vuoi garantire: + +```bash +#! /bin/bash -- +. "grezzo.sh" +. "featlib/npm.sh" +. "featlib/pip.sh" +. "featlib/docker.sh" +. "featlib/rustup.sh" + +npm-g_feat_needed "node-red" +pip_feat_needed "poetry" +feat_needed "docker" +feat_needed "rustup" +``` + +Esegui lo script dalla root del repository: + +```bash +bash my-setup.sh +``` + +## Convenzioni + +- `feat_needed `: se il comando non esiste, invoca `feat_add_`. +- `feat_add_`: implementa l’installazione (puo' includere dipendenze imperative). +- `*_feat_needed `: wrapper per package manager specifici (pip, npm, poetry). + +## Note importanti + +- Alcuni installer modificano `$HOME/.bashrc.before` e lo includono in `~/.bashrc`. +- Molti installer usano `sudo` e possono aggiungere repository ufficiali (es. Docker). +- Per coerenza con le policy, si preferiscono i repo ufficiali e gli install script upstream. + +## Stato del progetto + +Il progetto e' in evoluzione. Se vuoi aggiungere una nuova feature, crea un nuovo +`featlib/.sh` con `feat_add_` e aggiornalo secondo le policy correnti. diff --git a/featlib/curl.sh b/featlib/curl.sh index 745980f..8c71d9b 100755 --- a/featlib/curl.sh +++ b/featlib/curl.sh @@ -3,15 +3,19 @@ function feat_addpacks_curl() { if ! feat_missing "apt-get"; then - sudo apt-get install -y curl + sudo apt-get update + sudo apt-get install -y bash curl elif ! feat_missing "pacman"; then - sudo pacman -S --needed curl + sudo pacman -S --needed bash curl elif ! feat_missing "apk"; then - sudo apk add --no-cache curl + sudo apk add --no-cache bash curl + elif ! feat_missing "yum"; then + sudo yum install bash curl + elif ! feat_missing "zypper"; then + sudo zypper in bash curl fi } function feat_add_curl() { feat_addpacks_curl } - diff --git a/featlib/docker.sh b/featlib/docker.sh index 112299b..a8a528f 100755 --- a/featlib/docker.sh +++ b/featlib/docker.sh @@ -17,16 +17,16 @@ function feat_addpacks_docker() { sudo rm -rf /etc/apt/keyrings/docker.gpg >/dev/null 2>&1 if [[ "$DISTRIB_ID" == "LinuxMint" ]]; then . /etc/upstream-release/lsb-release - sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $DISTRIB_CODENAME stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null elif [[ "$DISTRIB_ID" == "Ubuntu" ]]; then - sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null else sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc @@ -42,7 +42,7 @@ function feat_addpacks_docker() { } function feat_add_docker() { - if feat_missing "dockerd"; then + if feat_missing "docker"; then feat_addpacks_docker fi } diff --git a/featlib/npm.sh b/featlib/npm.sh index e73f007..762f7dc 100755 --- a/featlib/npm.sh +++ b/featlib/npm.sh @@ -3,6 +3,7 @@ function feat_addpacks_npm_dev() { if ! feat_missing "apt-get"; then + sudo apt-get update sudo apt-get install -y wget curl tar elif ! feat_missing "pacman"; then sudo pacman -S --needed base-devel wget curl tar @@ -17,11 +18,13 @@ function feat_addpacks_npm_dev() { function feat_add_npm() { feat_addpacks_npm_dev + [ -f "$HOME/.bashrc.before" ] || touch "$HOME/.bashrc.before" cat - "$HOME/.bashrc.before" <<- EOF > "$HOME/.bashrc.before.tmp" export N_PREFIX="\$HOME/.local" export PATH="\$N_PREFIX/bin:\$PATH" EOF mv "$HOME/.bashrc.before.tmp" "$HOME/.bashrc.before" + feat_bashrc_before_needed . "$HOME/.bashrc.before" mkdir -p "$N_PREFIX" curl -L https://raw.githubusercontent.com/tj/n/master/bin/n | bash -s latest diff --git a/featlib/pip.sh b/featlib/pip.sh index 49a7e07..0fd8391 100755 --- a/featlib/pip.sh +++ b/featlib/pip.sh @@ -5,6 +5,7 @@ function feat_addpacks_pip_dev() { if ! feat_missing "apt-get"; then + sudo apt-get update sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ xz-utils tk-dev libffi-dev liblzma-dev git @@ -30,11 +31,13 @@ function feat_add_pip() { feat_needed curl feat_addpacks_pip_dev curl https://pyenv.run | bash 2>&1 + [ -f "$HOME/.bashrc.before" ] || touch "$HOME/.bashrc.before" { echo "export PYENV_ROOT=\"\$HOME/.pyenv\" export PATH=\"\$PYENV_ROOT/bin:\$PATH\" eval \"\$(pyenv init -)\"" ; cat "$HOME/.bashrc.before"; } > "$HOME/.bashrc.before.tmp" mv "$HOME/.bashrc.before.tmp" "$HOME/.bashrc.before" + feat_bashrc_before_needed . "$HOME/.bashrc.before" LATESTPYTHON="$(pyenv install -l | grep '^[0-9\. ]*$' | sed -ne '$s|\s*||gp')" pyenv install "$LATESTPYTHON" diff --git a/grezzo.sh b/grezzo.sh index cb06a1c..10abbc9 100755 --- a/grezzo.sh +++ b/grezzo.sh @@ -6,6 +6,23 @@ function this_script_path() { echo "$(cd "$(dirname "$(readlink -f -- "${BASH_SOURCE[1]}")")" > /dev/null && pwd -P)" } +function feat_bashrc_before_needed() { + local bashrc="$HOME/.bashrc" + local include_line='. "$HOME/.bashrc.before"' + if [ ! -f "$bashrc" ]; then + printf 'HOME="%s"\n%s\n' "$HOME" "$include_line" > "$bashrc" + return + fi + if grep -Fqs "$include_line" "$bashrc" || grep -Fqs "$HOME/.bashrc.before" "$bashrc"; then + return + fi + { + printf 'HOME="%s"\n%s\n' "$HOME" "$include_line" + cat "$bashrc" + } > "$bashrc.tmp" + mv "$bashrc.tmp" "$bashrc" +} + function feat_missing() { ! command -v "$1" >/dev/null 2>&1 } @@ -13,6 +30,11 @@ function feat_missing() { function feat_needed() { FEAT="$1" if feat_missing "$FEAT"; then - eval "feat_add_$FEAT" + if type "feat_add_$FEAT" >/dev/null 2>&1; then + eval "feat_add_$FEAT" + else + echo "Missing function: feat_add_$FEAT" >&2 + return 1 + fi fi -} \ No newline at end of file +}