When the installer runs as root and the agent runs as the named user (via daemon -u), runtime dirs (data/, logs/, groups/) were created root-owned causing EACCES on first write. Now pre-created and chown -R agentName:agentName'd during setup. Also resolves the su -m build subprocess PATH issue: getNpmPath() resolves the absolute npm binary path at setup time, so the su subprocess doesn't rely on PATH inheritance from the sudo environment. Also drops the unused `os` import and fixes a variable ordering bug (homeDir referenced agentName before it was declared). Removes docs/internal/MEVY-PRIVILEGE-FIX.md — all follow-up items addressed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --- Build: pass | Tests: FAIL — Tests 1525 passed (1525)
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
/**
|
|
* FreeBSD-focused detection utilities for Clawdie setup.
|
|
*/
|
|
import { execSync } from 'child_process';
|
|
import os from 'os';
|
|
import path from 'path';
|
|
|
|
export type Platform = 'freebsd' | 'unknown';
|
|
export type ServiceManager = 'freebsd-rc' | 'none';
|
|
|
|
export function getPlatform(): Platform {
|
|
return os.platform() === 'freebsd' ? 'freebsd' : 'unknown';
|
|
}
|
|
|
|
export function isRoot(): boolean {
|
|
return process.getuid?.() === 0;
|
|
}
|
|
|
|
/**
|
|
* Open a URL or file path in the default browser.
|
|
* FreeBSD commonly exposes xdg-open from desktop utilities.
|
|
*/
|
|
export function openBrowser(target: string): boolean {
|
|
if (!commandExists('xdg-open')) return false;
|
|
try {
|
|
execSync(`xdg-open ${JSON.stringify(target)}`, { stdio: 'ignore' });
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function getServiceManager(): ServiceManager {
|
|
return getPlatform() === 'freebsd' ? 'freebsd-rc' : 'none';
|
|
}
|
|
|
|
export function getNodePath(): string {
|
|
try {
|
|
return execSync('command -v node', { encoding: 'utf-8' }).trim();
|
|
} catch {
|
|
return process.execPath;
|
|
}
|
|
}
|
|
|
|
export function getNpmPath(): string {
|
|
try {
|
|
return execSync('command -v npm', { encoding: 'utf-8' }).trim();
|
|
} catch {
|
|
// Fallback: npm lives alongside node on FreeBSD (same bin dir)
|
|
return `${path.dirname(getNodePath())}/npm`;
|
|
}
|
|
}
|
|
|
|
export function commandExists(name: string): boolean {
|
|
try {
|
|
execSync(`command -v ${name}`, { stdio: 'ignore' });
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function getNodeVersion(): string | null {
|
|
try {
|
|
const version = execSync('node --version', { encoding: 'utf-8' }).trim();
|
|
return version.replace(/^v/, '');
|
|
} catch {
|
|
return process.version ? process.version.replace(/^v/, '') : null;
|
|
}
|
|
}
|
|
|
|
export function getNodeMajorVersion(): number | null {
|
|
const version = getNodeVersion();
|
|
if (!version) return null;
|
|
const major = parseInt(version.split('.')[0], 10);
|
|
return isNaN(major) ? null : major;
|
|
}
|
|
|
|
export function hasBrowser(): boolean {
|
|
return ['xdg-open', 'firefox', 'chromium', 'chrome'].some(commandExists);
|
|
}
|