-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
const { spawnSync } = require('child_process'); | ||
|
||
// It seems `sudo npm ...` no longer give the script sudo perms in npm v7, so here we are. | ||
// It seems `sudo npm ...` no longer gives the script sudo perms in npm v7, so here we are. | ||
if (process.platform === 'linux' && process.getuid() !== 0) { | ||
// todo: decide whether this is a viable solution for the long term. people may use doas or other tools for elevating themselves. | ||
spawnSync('sudo', process.argv, { stdio: 'inherit' }) | ||
tryToElevate('sudo') | ||
tryToElevate('doas') | ||
|
||
console.warn('Neither doas nor sudo were found. Falling back to su.') | ||
console.log('Please enter your root password') | ||
spawnSync('su', ['-c', process.argv.join(' ')], { stdio: 'inherit'}) | ||
process.exit(0) | ||
} | ||
|
||
function tryToElevate(command) { | ||
const { error } = spawnSync(command, process.argv, { stdio: 'inherit'}) | ||
if (!error) { | ||
process.exit(0) | ||
} else if (error.code !== 'ENOENT') { | ||
console.error(error) | ||
process.exit(0) | ||
} | ||
} |