shell: make require take a tag

This commit is contained in:
Girish Ramakrishnan
2024-10-14 19:10:31 +02:00
parent 02823c4158
commit a9e1d7641d
27 changed files with 162 additions and 156 deletions
+6 -6
View File
@@ -33,7 +33,7 @@ const apps = require('./apps.js'),
path = require('path'),
paths = require('./paths.js'),
safe = require('safetydance'),
shell = require('./shell.js'),
shell = require('./shell.js')('system'),
tasks = require('./tasks.js'),
volumes = require('./volumes.js');
@@ -44,7 +44,7 @@ const REBOOT_CMD = path.join(__dirname, 'scripts/reboot.sh');
async function du(file) {
assert.strictEqual(typeof file, 'string');
const [error, stdoutResult] = await safe(shell.promises.sudo('system', [ DU_CMD, file ], { captureStdout: true }));
const [error, stdoutResult] = await safe(shell.promises.sudo([ DU_CMD, file ], { captureStdout: true }));
if (error) throw new BoxError(BoxError.FS_ERROR, error);
return parseInt(stdoutResult.trim(), 10);
@@ -53,7 +53,7 @@ async function du(file) {
async function hdparm(file) {
assert.strictEqual(typeof file, 'string');
const [error, stdoutResult] = await safe(shell.promises.sudo('system', [ HDPARM_CMD, file ], { captureStdout: true }));
const [error, stdoutResult] = await safe(shell.promises.sudo([ HDPARM_CMD, file ], { captureStdout: true }));
if (error) throw new BoxError(BoxError.FS_ERROR, error);
const lines = stdoutResult.split('\n');
@@ -67,7 +67,7 @@ async function hdparm(file) {
}
async function getSwaps() {
const [error, stdout] = await safe(shell.exec('getSwaps', 'swapon --noheadings --raw --bytes --show=type,size,used,name', {}));
const [error, stdout] = await safe(shell.exec('swapon --noheadings --raw --bytes --show=type,size,used,name', {}));
if (error) return {};
const output = stdout.trim();
if (!output) return {}; // no swaps
@@ -266,7 +266,7 @@ async function updateDiskUsage(progressCallback) {
async function reboot() {
await notifications.clearAlert(notifications.ALERT_REBOOT, 'Reboot Required');
const [error] = await safe(shell.promises.sudo('reboot', [ REBOOT_CMD ], {}));
const [error] = await safe(shell.promises.sudo([ REBOOT_CMD ], {}));
if (error) debug('reboot: could not reboot. %o', error);
}
@@ -314,7 +314,7 @@ async function getLogs(unit, options) {
}
async function getBlockDevices() {
const result = await shell.exec('getBlockDevices', 'lsblk --paths --json --list --fs --output +rota', {});
const result = await shell.exec('lsblk --paths --json --list --fs --output +rota', {});
const info = safe.JSON.parse(result);
if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, `failed to parse lsblk: ${safe.error.message}`);