mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Add mac os installation
This commit is contained in:
parent
6c1383a9d3
commit
c8ee15dc57
2 changed files with 81 additions and 0 deletions
78
packages/safe-chain/src/installation/installOnMacOS.js
Normal file
78
packages/safe-chain/src/installation/installOnMacOS.js
Normal 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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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.`,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue