pmbootstrap init: don't allow 'root' as username

While going over the wiki pages recently, I've noticed that somebody
added a note to not use "root" as username. I don't think many people
will attempt to do this, but let's catch it here in pmbootstrap with a
friendly message instead of mentioning it in the wiki.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230126071154.1689-1-ollieparanoid@postmarketos.org%3E
This commit is contained in:
Oliver Smith 2023-01-26 08:11:55 +01:00
parent e8a2ab2e98
commit 98290f9191
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 18 additions and 5 deletions

View File

@ -33,6 +33,23 @@ def require_programs():
f" {', '.join(missing)}")
def ask_for_username(args):
"""
Ask for a reasonable username for the non-root user.
:returns: the username
"""
while True:
ret = pmb.helpers.cli.ask("Username", None, args.user, False,
"[a-z_][a-z0-9_-]*")
if ret == "root":
logging.fatal("ERROR: don't put \"root\" here. This is about"
" creating an additional non-root user. Don't worry,"
" the root user will also be created ;)")
continue
return ret
def ask_for_work_path(args):
"""
Ask for the work path, until we can create it (when it does not exist) and
@ -653,11 +670,7 @@ def frontend(args):
if device_exists:
cfg["pmbootstrap"]["keymap"] = ask_for_keymaps(args, info)
# Username
cfg["pmbootstrap"]["user"] = pmb.helpers.cli.ask("Username", None,
args.user, False,
"[a-z_][a-z0-9_-]*")
cfg["pmbootstrap"]["user"] = ask_for_username(args)
ask_for_provider_select_pkg(args, "postmarketos-base", cfg["providers"])
# UI and various build options