diff --git a/scripts/install-dirigent-openclaw.mjs b/scripts/install-dirigent-openclaw.mjs index c08c755..99bfde0 100755 --- a/scripts/install-dirigent-openclaw.mjs +++ b/scripts/install-dirigent-openclaw.mjs @@ -6,7 +6,7 @@ import fs from "node:fs"; import path from "node:path"; import os from "node:os"; -import { execFileSync } from "node:child_process"; +import { execFileSync, spawnSync } from "node:child_process"; const modeArg = process.argv[2]; if (modeArg !== "--install" && modeArg !== "--uninstall") { @@ -134,9 +134,26 @@ if (!fs.existsSync(OPENCLAW_CONFIG_PATH)) { } // ═══════════════════════════════════════════════════════════════════════════ -// INSTALL +// INSTALL (with auto-reinstall if already installed) // ═══════════════════════════════════════════════════════════════════════════ if (mode === "install") { + // Check if already installed - if so, uninstall first + const existingRecord = findLatestInstallRecord(); + if (existingRecord) { + console.log("[dirigent] existing installation detected, uninstalling first..."); + process.env.RECORD_FILE = existingRecord; + // Re-exec ourselves in uninstall mode + const result = spawnSync(process.execPath, [import.meta.filename, "--uninstall"], { + env: process.env, + stdio: ["inherit", "inherit", "inherit"], + }); + if (result.status !== 0) { + console.error("[dirigent] reinstall failed during uninstall phase"); + process.exit(1); + } + console.log("[dirigent] previous installation removed, proceeding with fresh install..."); + } + fs.copyFileSync(OPENCLAW_CONFIG_PATH, BACKUP_PATH); console.log(`[dirigent] safety backup: ${BACKUP_PATH}`); @@ -248,8 +265,8 @@ if (mode === "install") { else { const recFile = env.RECORD_FILE || findLatestInstallRecord(); if (!recFile || !fs.existsSync(recFile)) { - console.error("[dirigent] no install record found. set RECORD_FILE= to an install record."); - process.exit(1); + console.log("[dirigent] no install record found, nothing to uninstall."); + process.exit(0); } fs.copyFileSync(OPENCLAW_CONFIG_PATH, BACKUP_PATH);