Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for buildozer running as root #128

Merged
merged 2 commits into from
Jul 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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