Add mac os installation

This commit is contained in:
Sander Declerck 2026-01-21 09:14:44 +01:00
parent a7e21bbfe2
commit d4c496d60d
No known key found for this signature in database
2 changed files with 81 additions and 0 deletions

View file

@ -0,0 +1,78 @@
import { tmpdir } from "os";
import { unlinkSync } from "fs";
import { join } from "path";
import { ui } from "../environment/userInteraction.js";
import { safeSpawn } from "../utils/safeSpawn.js";
import { downloadAgentToFile, getAgentVersion } from "./downloadAgent.js";
const MACOS_SERVICE_LABEL = "com.aikido.SafeChainAgent";
export async function installOnMacOS() {
if (!isRunningAsRoot()) {
ui.writeError("Root privileges required.");
ui.writeInformation("Please run this command with sudo:");
ui.writeInformation(" sudo safe-chain --ultimate");
return;
}
const pkgPath = join(tmpdir(), `SafeChainUltimate-${Date.now()}.pkg`);
ui.emptyLine();
ui.writeInformation(`📥 Downloading SafeChain Ultimate ${getAgentVersion()}`);
ui.writeVerbose(`Destination: ${pkgPath}`);
const result = await downloadAgentToFile(pkgPath);
if (!result) {
ui.writeError("No download available for this platform/architecture.");
return;
}
try {
ui.writeInformation("⚙️ Installing SafeChain Ultimate...");
await runPkgInstaller(pkgPath);
ui.emptyLine();
ui.writeInformation(
"✅ SafeChain Ultimate installed and started successfully!",
);
ui.emptyLine();
} finally {
ui.writeVerbose(`Cleaning up temporary file: ${pkgPath}`);
cleanup(pkgPath);
}
}
function isRunningAsRoot() {
const rootUserUid = 0;
return process.getuid?.() === rootUserUid;
}
/**
* @param {string} pkgPath
*/
async function runPkgInstaller(pkgPath) {
ui.writeVerbose(`Running: installer -pkg "${pkgPath}" -target /`);
const result = await safeSpawn(
"installer",
["-pkg", pkgPath, "-target", "/"],
{
stdio: "inherit",
},
);
if (result.status !== 0) {
throw new Error(`PKG installer failed (exit code: ${result.status})`);
}
}
/**
* @param {string} pkgPath
*/
function cleanup(pkgPath) {
try {
unlinkSync(pkgPath);
} catch {
ui.writeVerbose("Failed to clean up temporary installer file.");
}
}

View file

@ -2,6 +2,7 @@ import { platform } from "os";
import { ui } from "../environment/userInteraction.js"; import { ui } from "../environment/userInteraction.js";
import { initializeCliArguments } from "../config/cliArguments.js"; import { initializeCliArguments } from "../config/cliArguments.js";
import { installOnWindows } from "./installOnWindows.js"; import { installOnWindows } from "./installOnWindows.js";
import { installOnMacOS } from "./installOnMacOS.js";
export async function installUltimate() { export async function installUltimate() {
initializeCliArguments(process.argv); initializeCliArguments(process.argv);
@ -10,6 +11,8 @@ export async function installUltimate() {
if (operatingSystem === "win32") { if (operatingSystem === "win32") {
await installOnWindows(); await installOnWindows();
} else if (operatingSystem === "darwin") {
await installOnMacOS();
} else { } else {
ui.writeInformation( ui.writeInformation(
`${operatingSystem} is not supported yet by SafeChain's ultimate version.`, `${operatingSystem} is not supported yet by SafeChain's ultimate version.`,