mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-27 09:12:29 +00:00
0bff122b1c
Change-type: patch Signed-off-by: Paulo Castro <paulo@balena.io>
27 lines
605 B
TypeScript
27 lines
605 B
TypeScript
import { spawn } from 'child_process';
|
|
|
|
import * as Bluebird from 'bluebird';
|
|
import * as rindle from 'rindle';
|
|
|
|
export async function executeWithPrivileges(
|
|
command: string[],
|
|
stderr?: NodeJS.WritableStream,
|
|
): Promise<string> {
|
|
const opts = {
|
|
stdio: ['inherit', 'inherit', stderr ? 'pipe' : 'inherit'],
|
|
env: process.env,
|
|
};
|
|
|
|
const args = process.argv
|
|
.slice(0, 2)
|
|
.concat(['internal', 'sudo', command.join(' ')]);
|
|
|
|
const ps = spawn(args[0], args.slice(1), opts);
|
|
|
|
if (stderr) {
|
|
ps.stderr.pipe(stderr);
|
|
}
|
|
|
|
return Bluebird.fromCallback<string>(callback => rindle.wait(ps, callback));
|
|
}
|