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/menu/selection_menu.py | 39 ++++++++++------------------- archinstall/lib/user_interaction.py | 45 ++++++++-------------------------- 2 files changed, 23 insertions(+), 61 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/menu/selection_menu.py b/archinstall/lib/menu/selection_menu.py index a82e8a70..14278999 100644 --- a/archinstall/lib/menu/selection_menu.py +++ b/archinstall/lib/menu/selection_menu.py @@ -313,15 +313,6 @@ class GeneralMenu: if exec_ret_val and self._check_mandatory_status(): return False return True - """ old behaviour - # we allow for a callback after we get the result - self.post_callback(selector_name,result) - # we have a callback, by option, to determine if we can exit the menu. Only if ALL mandatory fields are written - if selector.exec_func: - if selector.exec_func(result) and self._check_mandatory_status(): - return False - """ - return True def _set_kb_language(self): """ general for ArchInstall""" @@ -474,9 +465,9 @@ class GlobalMenu(GeneralMenu): self._menu_options['!superusers'] = \ Selector( _('Specify superuser account'), - lambda x: self._create_superuser_account(), + lambda: self._create_superuser_account(), dependencies_not=['!root-password'], - display_func=lambda x: list(x.keys()) if x else '') + display_func=lambda x: self._display_superusers()) self._menu_options['!users'] = \ Selector( _('Specify user account'), @@ -564,8 +555,6 @@ class GlobalMenu(GeneralMenu): missing += 1 if not check('audio'): missing += 1 - if not check('timezone'): - missing += 1 if not check('!root-password') and not check('!superusers'): missing += 1 if not check('harddrives'): @@ -579,14 +568,6 @@ class GlobalMenu(GeneralMenu): def _set_root_password(self): prompt = str(_('Enter root password (leave blank to disable root): ')) password = get_password(prompt=prompt) - - # TODO: Do we really wanna wipe the !superusers and !users if root password is set? - # What if they set a superuser first, but then decides to set a root password? - if password is not None: - self._menu_options.get('!superusers').set_current_selection(None) - storage['arguments']['!users'] = {} - storage['arguments']['!superusers'] = {} - return password def _select_encrypted_password(self): @@ -640,11 +621,17 @@ class GlobalMenu(GeneralMenu): return profile def _create_superuser_account(self): - superuser = ask_for_superuser_account(str(_('Create a required super-user with sudo privileges: ')), forced=True) - return superuser + superusers = ask_for_superuser_account(str(_('Enter a username to create an additional superuser (leave blank to skip): '))) + return superusers if superusers else None def _create_user_account(self): - users, superusers = ask_for_additional_users(str(_('Enter a username to create an additional user (leave blank to skip): '))) - storage['arguments']['!superusers'] = {**storage['arguments'].get('!superusers', {}), **superusers} - + users = ask_for_additional_users(str(_('Enter a username to create an additional user (leave blank to skip): '))) return users + + def _display_superusers(self): + superusers = self._data_store.get('!superusers', {}) + + if self._menu_options.get('!root-password').has_selection(): + return list(superusers.keys()) if superusers else '[]' + else: + return list(superusers.keys()) if superusers else '' 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