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