From f604e22f6e80c704df202e1e1be4bc3497531541 Mon Sep 17 00:00:00 2001 From: Gilles Soulier Date: Fri, 22 May 2026 21:49:13 +0200 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20permissions=20config=20et=20prom?= =?UTF-8?q?pt=20d'=C3=A9crasement=20au=20r=C3=A9install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ConfigurationDirectoryMode 0750→0755 : le DynamicUser (sans groupe root) peut maintenant traverser /etc/nanometrics et lire config.toml - chmod 644 systématique sur config.toml même si conservé (corrige les anciennes installs en 640 qui causent un PermissionDenied au démarrage) - Prompt interactif si config existe : o=écraser, N=conserver ; variable OVERWRITE_CONFIG=true pour forcer sans interaction (curl|bash) Co-Authored-By: Claude Sonnet 4.6 --- deploy/install.sh | 33 +++++++++++++++++++++++++++++--- deploy/nanometrics-agent.service | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/deploy/install.sh b/deploy/install.sh index 21a448c..3050d8f 100755 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -112,10 +112,33 @@ ok "Répertoire créé" # ── 7. Écrire config.toml ───────────────────────────────────────────────────── echo "[3/5] Écriture de $CONFIG_FILE" -# Ne pas écraser une config existante (upgrade) +OVERWRITE_CONFIG="${OVERWRITE_CONFIG:-}" +WRITE_CONFIG=true + if [ -f "$CONFIG_FILE" ]; then - warn "config.toml déjà présent — conservé tel quel" -else + if [ "${OVERWRITE_CONFIG}" = "true" ]; then + warn "OVERWRITE_CONFIG=true — config.toml sera écrasé" + WRITE_CONFIG=true + elif [ -t 0 ]; then + # Mode interactif (bash local, pas curl | bash) + echo "" + warn "Un config.toml existe déjà :" + echo " $CONFIG_FILE" + printf " Écraser la configuration existante ? [o/N] : " + read -r _ANS + if [[ "$_ANS" =~ ^[Oo]$ ]]; then + WRITE_CONFIG=true + else + ok "config.toml conservé" + WRITE_CONFIG=false + fi + else + warn "config.toml déjà présent — conservé (relancez avec OVERWRITE_CONFIG=true pour écraser)" + WRITE_CONFIG=false + fi +fi + +if [ "$WRITE_CONFIG" = "true" ]; then cat > "$CONFIG_FILE" << TOML [server] ip = "$SERVER_IP" @@ -165,6 +188,10 @@ TOML ok "config.toml créé" fi +# S'assurer que le fichier est toujours lisible (cas d'un config existant en 640) +chmod 644 "$CONFIG_FILE" 2>/dev/null || true +chmod 755 "$CONFIG_DIR" + # ── 8. Installer le fichier service ────────────────────────────────────────── echo "[4/5] Installation du service systemd" curl -fsSL -o "$SERVICE_FILE" "$SERVICE_URL" diff --git a/deploy/nanometrics-agent.service b/deploy/nanometrics-agent.service index 1b1cd91..454db56 100644 --- a/deploy/nanometrics-agent.service +++ b/deploy/nanometrics-agent.service @@ -11,7 +11,7 @@ RestartSec=5 DynamicUser=yes ConfigurationDirectory=nanometrics -ConfigurationDirectoryMode=0750 +ConfigurationDirectoryMode=0755 ProtectSystem=strict ProtectHome=read-only