68 lines
1.7 KiB
JavaScript
Raw Normal View History

2025-01-03 08:25:09 -05:00
import * as child_process from 'node:child_process';
2025-01-03 10:20:33 -05:00
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as url from 'node:url';
2025-01-03 08:25:09 -05:00
// Logging
const EXIT_FAILURE = 1;
export function fail(message) {
console.error(message);
process.exit(EXIT_FAILURE);
}
export function err(message) {
fail('ERROR: ' + message);
}
export function info(message) {
console.log('INFO: ' + message);
}
// Sub-Process
export function run(command) {
try {
info('Running: ' + command.join(' '));
child_process.execFileSync(command[0], command.slice(1), {stdio: 'inherit'});
} catch (e) {
err(e);
}
2025-01-03 10:20:33 -05:00
}
// Create Directory
export function createDir(dir, clean) {
if (clean) {
fs.rmSync(dir, {recursive: true, force: true});
}
fs.mkdirSync(dir, {recursive: true});
}
// Get System Information
export function getDebianVersion() {
const info = fs.readFileSync('/etc/os-release', 'utf8');
const lines = info.split('\n');
const prefix = 'VERSION_CODENAME=';
for (const line of lines) {
if (line.startsWith(prefix)) {
return line.substring(prefix.length);
}
}
return 'unknown';
}
// Make File Executable
export function makeExecutable(path) {
2025-01-03 15:03:30 -05:00
fs.chmodSync(path,
fs.constants.S_IRUSR |
fs.constants.S_IWUSR |
fs.constants.S_IXUSR |
fs.constants.S_IRGRP |
fs.constants.S_IXGRP |
fs.constants.S_IROTH |
fs.constants.S_IXOTH
);
2025-01-03 10:20:33 -05:00
}
// Get Scripts Directory
export function getScriptsDir() {
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
return path.join(__dirname, '..');
2025-01-03 08:25:09 -05:00
}