diff --git a/src/utils/setup/sudo.ts b/src/utils/setup/sudo.ts new file mode 100644 index 00000000..3d63afd6 --- /dev/null +++ b/src/utils/setup/sudo.ts @@ -0,0 +1,17 @@ +let _issudo: boolean | undefined = undefined + +export function isRoot(): boolean { + if (_issudo !== undefined) { + return _issudo + } + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/no-unnecessary-condition + _issudo = Boolean(process.env.CI) || process.getuid?.() === 0 + return _issudo +} + +export function mightSudo(command: string) { + if (isRoot()) { + return `sudo ${command}` + } + return command +}