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:
parent
9702fd9926
commit
8ab3e55ee8
17
src/utils/setup/sudo.ts
Normal file
17
src/utils/setup/sudo.ts
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user