Template
1
0
mirror of https://github.com/aminya/setup-cpp synced 2024-11-30 21:22:30 +08:00

feat: add sudo utils

This commit is contained in:
Amin Yahyaabadi 2021-09-16 08:36:29 -05:00
parent 9702fd9926
commit 8ab3e55ee8

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
}