#!/bin/sh # install.sh — installa il collector statusd come servizio UTENTE (senza root). # # Cosa fa: # 1. copia statusd.py in ~/.local/share/statod/ # 2. genera il token in ~/.config/statusd/token (0600) se non esiste # 3. installa le unit systemd utente e le attiva # # NON tocca il firewall: la porta 8792 resta chiusa finche' non si applica # 53-statusd-lan-vpn.conf come root (vedi README.md). set -eu qui=$(cd "$(dirname "$0")" && pwd) dest="$HOME/.local/share/statod" echo "── installazione in $dest" mkdir -p "$dest" "$HOME/.cache/statusd" "$HOME/.config/statusd" "$HOME/.config/systemd/user" cp "$qui/statusd.py" "$dest/statusd.py" if [ -s "$HOME/.config/statusd/token" ]; then echo "── token gia' presente, lo lascio com'e'" else python3 -c "import secrets; print(secrets.token_urlsafe(24))" > "$HOME/.config/statusd/token" chmod 600 "$HOME/.config/statusd/token" echo "── token generato: $HOME/.config/statusd/token" fi cp "$qui/systemd/statusd-collect.service" "$qui/systemd/statusd-collect.timer" \ "$qui/systemd/statusd-http.service" "$HOME/.config/systemd/user/" export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" systemctl --user daemon-reload systemctl --user enable --now statusd-collect.timer statusd-http.service echo "── stato" systemctl --user is-active statusd-collect.timer statusd-http.service echo echo "Token (da incollare nell'app): cat $HOME/.config/statusd/token" echo "Prova locale: curl -s -H \"X-Status-Token: \$(cat ~/.config/statusd/token)\" \\" echo " -o /dev/null -w '%{http_code}\\n' http://127.0.0.1:8792/v1/status" echo echo "Per l'accesso dal telefono serve la regola firewall (root):" echo " sudo install -m 644 $qui/53-statusd-lan-vpn.conf /etc/nftables.d/" echo " sudo nft -f /etc/nftables.d/53-statusd-lan-vpn.conf"