69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
/**
|
|
* Step: jail — Validate FreeBSD jail tooling and current Clawdie jail state.
|
|
*/
|
|
import { execSync } from 'child_process';
|
|
import fs from 'fs';
|
|
|
|
import { logger } from '../src/logger.js';
|
|
import { commandExists, getPlatform } from './platform.js';
|
|
import { emitStatus } from './status.js';
|
|
|
|
const DEFAULT_JAIL_NAME = process.env.JAIL_NAME || 'clawdie';
|
|
|
|
function getRunningJails(): string[] {
|
|
try {
|
|
const output = execSync('jls -N name', {
|
|
encoding: 'utf-8',
|
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
});
|
|
return output
|
|
.split('\n')
|
|
.map((line) => line.trim())
|
|
.filter(Boolean)
|
|
.filter((line) => line !== 'name');
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export async function run(_args: string[]): Promise<void> {
|
|
logger.info('Starting jail setup validation');
|
|
|
|
if (getPlatform() !== 'freebsd') {
|
|
emitStatus('SETUP_JAIL', {
|
|
PLATFORM: getPlatform(),
|
|
STATUS: 'failed',
|
|
ERROR: 'unsupported_platform',
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
process.exit(1);
|
|
}
|
|
|
|
const hasJexec = commandExists('jexec');
|
|
const hasJls = commandExists('jls');
|
|
const hasService = commandExists('service');
|
|
const hasJailCtl = commandExists('jail');
|
|
const hasJailConf = fs.existsSync('/etc/jail.conf');
|
|
const runningJails = getRunningJails();
|
|
const targetJailRunning = runningJails.includes(DEFAULT_JAIL_NAME);
|
|
|
|
const status =
|
|
hasJexec && hasJls && hasService && hasJailCtl ? 'success' : 'failed';
|
|
|
|
emitStatus('SETUP_JAIL', {
|
|
JAIL_NAME: DEFAULT_JAIL_NAME,
|
|
JEXEC: hasJexec,
|
|
JLS: hasJls,
|
|
SERVICE: hasService,
|
|
JAIL_CTL: hasJailCtl,
|
|
JAIL_CONF: hasJailConf,
|
|
RUNNING_JAILS: runningJails.join(',') || 'none',
|
|
TARGET_JAIL_RUNNING: targetJailRunning,
|
|
STATUS: status,
|
|
LOG: 'logs/setup.log',
|
|
});
|
|
|
|
if (status === 'failed') {
|
|
process.exit(1);
|
|
}
|
|
}
|