mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Mac: use uninstaller script
This commit is contained in:
parent
57c090c3a7
commit
aa6553716d
2 changed files with 22 additions and 53 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { tmpdir } from "os";
|
||||
import { unlinkSync, rmSync } from "fs";
|
||||
import { unlinkSync } from "fs";
|
||||
import { join } from "path";
|
||||
import { execSync } from "child_process";
|
||||
import { execSync, spawnSync } from "child_process";
|
||||
import { ui } from "../environment/userInteraction.js";
|
||||
import { printVerboseAndSafeSpawn } from "../utils/safeSpawn.js";
|
||||
import { downloadAgentToFile, getAgentVersion } from "./downloadAgent.js";
|
||||
|
|
@ -73,6 +73,9 @@ export async function installOnMacOS() {
|
|||
}
|
||||
}
|
||||
|
||||
const MACOS_UNINSTALL_SCRIPT =
|
||||
"/Library/Application Support/AikidoSecurity/SafeChainUltimate/scripts/uninstall";
|
||||
|
||||
export async function uninstallOnMacOS() {
|
||||
if (!requireRootPrivileges("sudo safe-chain ultimate uninstall")) {
|
||||
return;
|
||||
|
|
@ -85,14 +88,20 @@ export async function uninstallOnMacOS() {
|
|||
return;
|
||||
}
|
||||
|
||||
ui.writeInformation("⏹️ Stopping service...");
|
||||
await stopService();
|
||||
ui.writeInformation("🗑️ Uninstalling SafeChain Ultimate...");
|
||||
ui.writeVerbose(`Running: ${MACOS_UNINSTALL_SCRIPT}`);
|
||||
|
||||
ui.writeInformation("🗑️ Removing files...");
|
||||
removeKnownFiles();
|
||||
const result = spawnSync(MACOS_UNINSTALL_SCRIPT, {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
});
|
||||
|
||||
ui.writeInformation("🧹 Forgetting package receipt...");
|
||||
forgetPackage();
|
||||
if (result.status !== 0) {
|
||||
ui.writeError(
|
||||
`Uninstall script failed (exit code: ${result.status}). Please try again or remove manually.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
ui.emptyLine();
|
||||
ui.writeInformation("✅ SafeChain Ultimate has been uninstalled.");
|
||||
|
|
@ -111,46 +120,6 @@ function isPackageInstalled() {
|
|||
}
|
||||
}
|
||||
|
||||
async function stopService() {
|
||||
const result = await printVerboseAndSafeSpawn(
|
||||
"launchctl",
|
||||
["bootout", `system/${MACOS_PKG_IDENTIFIER}`],
|
||||
{ stdio: "pipe" },
|
||||
);
|
||||
|
||||
if (result.status !== 0) {
|
||||
ui.writeVerbose("Service not running (will continue with uninstall).");
|
||||
}
|
||||
}
|
||||
|
||||
const MACOS_KNOWN_PATHS = [
|
||||
"/Library/Application Support/AikidoSecurity/SafeChainUltimate",
|
||||
"/Library/Logs/AikidoSecurity/SafeChainUltimate",
|
||||
`/Library/LaunchDaemons/${MACOS_PKG_IDENTIFIER}.plist`,
|
||||
];
|
||||
|
||||
function removeKnownFiles() {
|
||||
for (const filePath of MACOS_KNOWN_PATHS) {
|
||||
try {
|
||||
rmSync(filePath, { recursive: true, force: true });
|
||||
ui.writeVerbose(`Removed: ${filePath}`);
|
||||
} catch {
|
||||
ui.writeVerbose(`Failed to remove: ${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function forgetPackage() {
|
||||
try {
|
||||
execSync(`pkgutil --forget ${MACOS_PKG_IDENTIFIER}`, {
|
||||
encoding: "utf8",
|
||||
stdio: "pipe",
|
||||
});
|
||||
} catch {
|
||||
ui.writeVerbose("Failed to forget package receipt.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} pkgPath
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue