Skip to content

Commit

Permalink
Merge pull request #128 from inclement/root_check
Browse files Browse the repository at this point in the history
Added check for buildozer running as root
  • Loading branch information
akshayaurora committed Jul 6, 2014
2 parents 3a523e0 + 170738b commit 0323f6c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions buildozer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,8 @@ def run_command(self, args):

self._merge_config_profile()

self.check_root()

if not args:
self.run_default()
return
Expand All @@ -956,6 +958,28 @@ def run_command(self, args):
self.set_target(command)
self.target.run_commands(args)

def check_root(self):
'''If effective user id is 0, display a warning and require
user input to continue (or to cancel)'''

try: # ensure same result in python2 and python3
input = raw_input
except NameError:
pass

warn_on_root = self.config.getdefault('buildozer', 'warn_on_root', 'yay')
euid = os.geteuid()
if warn_on_root == '1' and euid == 0:
print('\033[91m\033[1mBuildozer is running as root!\033[0m')
print('\033[91mThis is \033[1mnot\033[0m \033[91mrecommended, and may lead to problems later.\033[0m')
cont = None
while cont not in ('y', 'n'):
cont = input('Are you sure you want to continue [y/n]? ')

if cont == 'n':
sys.exit()


def cmd_init(self, *args):
'''Create a initial buildozer.spec in the current directory
'''
Expand Down
3 changes: 3 additions & 0 deletions buildozer/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ fullscreen = 1
# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 1
# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1
# -----------------------------------------------------------------------------
# List as sections
Expand Down

0 comments on commit 0323f6c

Please sign in to comment.