mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 20:20:49 +00:00
Improve updating existing agent install
This commit is contained in:
parent
7f6ce79f44
commit
8410b94b4c
1 changed files with 24 additions and 6 deletions
|
|
@ -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() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue