Don't run under sudo

This commit is contained in:
Ben Jackson 2020-03-21 14:04:48 +00:00
commit 9393c1d80e
2 changed files with 29 additions and 1 deletions

View file

@ -537,6 +537,7 @@ print( 'OS = ' + OS )
print( 'gadget_dir = ' + gadget_dir )
parser = argparse.ArgumentParser(
formatter_class = argparse.RawDescriptionHelpFormatter,
description = 'Install DAP Servers for use with Vimspector.',
epilog =
"""
@ -548,6 +549,12 @@ parser = argparse.ArgumentParser(
The format of the file can be found on the Vimspector reference guide:
https://puremourning.github.io/vimspector
NOTE: This script should usually _not_ be run under `sudo` or as root. It
downloads and extracts things only to directories under its own path. No
system files or folders are chnaged by this script. If you really want to
run under sudo, pass --sudo, but this is _almost certainly_ the wrong thing
to do.
"""
)
parser.add_argument( '--all',
@ -571,6 +578,11 @@ parser.add_argument( '--enable-custom',
'can be supplied multiple times and each time '
'multiple files can be passed.' )
parser.add_argument( '--sudo',
action='store_true',
help = "If you're really really really sure you want to "
"run this as root via sudo, pass this flag." )
done_languages = set()
for name, gadget in GADGETS.items():
lang = gadget[ 'language' ]
@ -608,6 +620,8 @@ parser.add_argument(
args = parser.parse_args()
installer.AbortIfSUperUser( args.sudo )
if args.force_all and not args.all:
args.all = True

View file

@ -28,6 +28,7 @@ import ssl
import subprocess
import functools
import os
import sys
from vimspector import install
@ -220,7 +221,6 @@ def MakeSymlink( in_folder, link, pointing_to ):
else:
os.symlink( pointing_to_relative, link_path )
def CloneRepoTo( url, ref, destination ):
RemoveIfExists( destination )
git_in_repo = [ 'git', '-C', destination ]
@ -231,3 +231,17 @@ def CloneRepoTo( url, ref, destination ):
'update',
'--init',
'--recursive' ] )
def AbortIfSUperUser( force_sudo ):
# TODO: We should probably check the effective uid too
is_su = False
if 'SUDO_COMMAND' in os.environ:
is_su = True
if is_su:
if force_sudo:
print( "*** RUNNING AS SUPER USER DUE TO force_sudo! "
" All bets are off. ***" )
else:
sys.exit( "This script should *not* be run as super user. Aborting." )