Verified Commit 1894d128 authored by Aral Balkan's avatar Aral Balkan
Browse files

Auto-restart with sudo for commands that require root privileges

parent c9664759
...@@ -271,10 +271,14 @@ function clr (text, color) { ...@@ -271,10 +271,14 @@ function clr (text, color) {
// Ensure we have root privileges and exit if we don’t. // Ensure we have root privileges and exit if we don’t.
function ensureRoot (commandName) { function ensureRoot (commandName) {
if (process.getuid() !== 0) { if (process.getuid() !== 0) {
const nodeSyntax = `sudo node bin/webserver.js ${commandName}` // Requires root but wasn’t run with sudo. Automatically restart using sudo.
const binarySyntax = `sudo web-server ${commandName}` const options = {env: process.env, stdio: 'inherit'}
console.log(`\n 👿 Error: Requires root. Please try again with ${runtime.isNode ? nodeSyntax : binarySyntax}\n`) if (runtime.isNode) {
process.exit(1) childProcess.execSync(`sudo node ${path.join(__dirname, 'web-server.js')} ${process.argv.slice(2).join(' ')}`, options)
} else {
childProcess.execSync(`sudo web-server ${process.argv.slice(2).join(' ')}`, options)
}
process.exit(0)
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment