Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hypha
Tools
Indie Web Server
Commits
1894d128
Verified
Commit
1894d128
authored
Apr 13, 2019
by
Aral Balkan
Browse files
Auto-restart with sudo for commands that require root privileges
parent
c9664759
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/web-server.js
View file @
1894d128
...
...
@@ -271,10 +271,14 @@ function clr (text, color) {
// Ensure we have root privileges and exit if we don’t.
function
ensureRoot
(
commandName
)
{
if
(
process
.
getuid
()
!==
0
)
{
const
nodeSyntax
=
`sudo node bin/webserver.js
${
commandName
}
`
const
binarySyntax
=
`sudo web-server
${
commandName
}
`
console
.
log
(
`\n 👿 Error: Requires root. Please try again with
${
runtime
.
isNode
?
nodeSyntax
:
binarySyntax
}
\n`
)
process
.
exit
(
1
)
// Requires root but wasn’t run with sudo. Automatically restart using sudo.
const
options
=
{
env
:
process
.
env
,
stdio
:
'
inherit
'
}
if
(
runtime
.
isNode
)
{
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
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment