feat: add sudo utils

This commit is contained in:
Amin Yahyaabadi 2021-09-16 08:36:29 -05:00
parent 9702fd9926
commit 8ab3e55ee8
1 changed files with 17 additions and 0 deletions

17
src/utils/setup/sudo.ts Normal file
View File

@ -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
}