From 0fed839110983f024edda88c10d9cd55be9ae122 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 1 Mar 2022 01:42:49 +1100 Subject: Rework the user/superuser configuration (#993) * Fix user/superuser config * Fix flake8 * Remove timezone check since we have a default value now * Remove unused Co-authored-by: Daniel Girtler Co-authored-by: Anton Hvornum --- archinstall/lib/user_interaction.py | 45 +++++++++---------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index aaf57143..e57fca8a 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -19,7 +19,7 @@ if TYPE_CHECKING: from .disk.partition import Partition from .disk import BlockDevice, suggest_single_disk_layout, suggest_multi_disk_layout, valid_parted_position, all_blockdevices -from .exceptions import RequirementError, UserError, DiskError +from .exceptions import RequirementError, DiskError from .hardware import AVAILABLE_GFX_DRIVERS, has_uefi, has_amd_graphics, has_intel_graphics, has_nvidia_graphics from .locale_helpers import list_keyboard_languages, list_timezones, list_locales from .networking import list_interfaces @@ -327,30 +327,15 @@ def ask_hostname(preset :str = None) -> str : return hostname -def ask_for_superuser_account(prompt: str = '', forced :bool = False) -> Dict[str, Dict[str, str]]: - prompt = prompt if prompt else _('Username for required superuser with sudo privileges: ') - while 1: - new_user = input(prompt).strip(' ') - - if not new_user and forced: - # TODO: make this text more generic? - # It's only used to create the first sudo user when root is disabled in guided.py - log(' * Since root is disabled, you need to create a least one superuser!', fg='red') - continue - elif not new_user and not forced: - raise UserError("No superuser was created.") - elif not check_for_correct_username(new_user): - continue +def ask_for_superuser_account(prompt: str) -> Dict[str, Dict[str, str]]: + prompt = prompt if prompt else str(_('Enter username for superuser with sudo privileges (leave blank for no superusers): ')) + superusers = ask_for_additional_users(prompt) + return superusers - prompt = str(_('Password for user "{}": ').format(new_user)) - password = get_password(prompt=prompt) - return {new_user: {"!password": password}} - -def ask_for_additional_users(prompt :str = '') -> tuple[dict[str, dict[str, str | None]], dict[str, dict[str, str | None]]]: +def ask_for_additional_users(prompt :str = '') -> Dict[str, Dict[str, str | None]]: prompt = prompt if prompt else _('Any additional users to install (leave blank for no users): ') users = {} - superusers = {} while 1: new_user = input(prompt).strip(' ') @@ -359,21 +344,11 @@ def ask_for_additional_users(prompt :str = '') -> tuple[dict[str, dict[str, str if not check_for_correct_username(new_user): continue - password = get_password(prompt=str(_('Password for user "{}": ').format(new_user))) - - choice = Menu( - str(_('Should this user be a superuser (sudoer)?')), - ['yes', 'no'], - skip=False, - default_option='no' - ).run() - - if choice == 'yes': - superusers[new_user] = {"!password": password} - else: - users[new_user] = {"!password": password} + password_prompt = str(_('Password for user "{}": ').format(new_user)) + password = get_password(prompt=password_prompt) + users[new_user] = {"!password": password} - return users, superusers + return users def ask_for_a_timezone(preset :str = None) -> str: -- cgit v1.2.3-54-g00ecf