Improve updating existing agent install

This commit is contained in:
Sander Declerck 2026-01-19 13:54:32 +01:00
parent 6a3c7b938b
commit 4851e582f6
No known key found for this signature in database

View file

@ -24,7 +24,7 @@ async function installOnWindows() {
if (!isRunningAsAdmin()) { if (!isRunningAsAdmin()) {
ui.writeError("Administrator privileges required."); ui.writeError("Administrator privileges required.");
ui.writeInformation( ui.writeInformation(
"Please run this command in an elevated terminal (Run as Administrator)." "Please run this command in an elevated terminal (Run as Administrator).",
); );
return; return;
} }
@ -33,15 +33,20 @@ async function installOnWindows() {
const downloadUrl = buildDownloadUrl(architecture); const downloadUrl = buildDownloadUrl(architecture);
const msiPath = join(tmpdir(), `SafeChainAgent-${Date.now()}.msi`); const msiPath = join(tmpdir(), `SafeChainAgent-${Date.now()}.msi`);
ui.writeInformation(`Downloading SafeChain Agent ${ULTIMATE_VERSION} for ${architecture}...`); ui.writeInformation(
`Downloading SafeChain Agent ${ULTIMATE_VERSION} for ${architecture}...`,
);
ui.writeVerbose(`Download URL: ${downloadUrl}`); ui.writeVerbose(`Download URL: ${downloadUrl}`);
ui.writeVerbose(`Destination: ${msiPath}`); ui.writeVerbose(`Destination: ${msiPath}`);
await downloadFile(downloadUrl, msiPath); await downloadFile(downloadUrl, msiPath);
stopServiceIfRunning(); stopServiceIfRunning();
// Wait a moment for the service to fully stop before installing
await new Promise((resolve) => setTimeout(resolve, 10000));
ui.writeInformation("Installing SafeChain Agent..."); ui.writeInformation("Installing SafeChain Agent...");
ui.writeVerbose(`Running: msiexec /i "${msiPath}" /qn REINSTALL=ALL REINSTALLMODE=vomus`); ui.writeVerbose(`Running: msiexec /i "${msiPath}" /qn /norestart`);
runMsiInstaller(msiPath); runMsiInstaller(msiPath);
ui.writeInformation("Starting SafeChain Agent service..."); ui.writeInformation("Starting SafeChain Agent service...");
@ -91,10 +96,23 @@ async function downloadFile(url, destPath) {
* @param {string} msiPath * @param {string} msiPath
*/ */
function runMsiInstaller(msiPath) { function runMsiInstaller(msiPath) {
// Use /i for install/upgrade with REINSTALL=ALL REINSTALLMODE=vomus // Try to install/upgrade
// This forces a reinstall of all features if the product is already installed // /i = install (will upgrade if product code matches)
// /qn = quiet mode (no UI) // /qn = quiet mode (no UI)
execSync(`msiexec /i "${msiPath}" /qn REINSTALL=ALL REINSTALLMODE=vomus`, { stdio: "inherit" }); // /norestart = suppress restarts
try {
execSync(`msiexec /i "${msiPath}" /qn /norestart`, { stdio: "inherit" });
} catch (error) {
// If installation fails, it might be because it's already installed
// Try to force a reinstall
ui.writeVerbose(
"Initial installation failed, attempting to force reinstall...",
);
execSync(
`msiexec /i "${msiPath}" /qn /norestart REINSTALL=ALL REINSTALLMODE=vomus`,
{ stdio: "inherit" },
);
}
} }
function stopServiceIfRunning() { function stopServiceIfRunning() {