From 37b1e618280c8b428824f202902e392792e10c18 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 14 Mar 2021 14:00:52 +0100 Subject: Corrected some spelling errors and wrong variables. --- archinstall/lib/user_interaction.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 7e7f5873..ab2b19bc 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -31,7 +31,7 @@ def ask_for_superuser_account(prompt='Create a required super-user with sudo pri raise UserError("No superuser was created.") password = get_password(prompt=f'Password for user {new_user}: ') - return {new_user: password} + return {new_user: {"!password" : password}} def ask_for_additional_users(prompt='Any additional users to install (leave blank for no users): '): users = {} @@ -44,9 +44,9 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan password = get_password(prompt=f'Password for user {new_user}: ') if input("Should this user be a sudo (super) user (y/N): ").strip(' ').lower() in ('y', 'yes'): - super_users[new_user] = password + super_users[new_user] = {"!password" : password} else: - users[new_user] = password + users[new_user] = {"!password" : password} return users, super_users -- cgit v1.2.3-70-g09d2 From b67257233f43fa8d34dacd6ecc3dc7cbbf60d221 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 20 Mar 2021 17:26:48 +0100 Subject: Fixed #64. installation.set_timezone() already excisted since earlier versions of archinstall in the library section. The guided.py example simply never asked for a time-zone. There's still no NTP option, which I'll add in later. Mostly because there's a lot of settings one can do to a time-client configuration, and I'm not sure all users want the default time servers etc. --- archinstall/lib/installer.py | 5 +++-- archinstall/lib/user_interaction.py | 7 ++++++- examples/guided.py | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 39e3447d..2604e77d 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,4 @@ -import os, stat, time, shutil +import os, stat, time, shutil, pathlib from .exceptions import * from .disk import * @@ -171,7 +171,8 @@ class Installer(): def set_timezone(self, zone, *args, **kwargs): if not len(zone): return True - o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} ln -s /usr/share/zoneinfo/{zone} /etc/localtime')) + (pathlib.Path(self.mountpoint)/"etc"/"localtime").unlink(missing_ok=True) + sys_command(f'/usr/bin/arch-chroot {self.mountpoint} ln -s /usr/share/zoneinfo/{zone} /etc/localtime') return True def activate_ntp(self): diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index ab2b19bc..6b3e5faa 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -1,4 +1,4 @@ -import getpass +import getpass, pathlib from .exceptions import * from .profiles import Profile from .locale_helpers import search_keyboard_layout @@ -50,6 +50,11 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan return users, super_users +def ask_for_a_timezone(): + timezone = input('Enter a valid timezone (Example: Europe/Stockholm): ').strip() + if pathlib.Path(timezone).exists(): + return timezone + def ask_to_configure_network(): # Optionally configure one network interface. #while 1: diff --git a/examples/guided.py b/examples/guided.py index 655fc29f..e9edac09 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -190,6 +190,9 @@ def ask_user_questions(): if not archinstall.arguments['nic']: archinstall.log(f"No network configuration was selected. Network is going to be unavailable until configured manually!", fg="yellow") + if not archinstall.arguments.get('timezone', None): + archinstall.arguments['timezone'] = archinstall.ask_for_a_timezone() + def perform_installation_steps(): global SIG_TRIGGER @@ -323,6 +326,9 @@ def perform_installation(device, boot_partition, language, mirrors): for superuser, user_info in archinstall.arguments.get('superusers', {}).items(): installation.user_create(superuser, user_info["!password"], sudo=True) + if (timezone := archinstall.arguments.get('timezone', None)): + installation.set_timezone(timezone) + if (root_pw := archinstall.arguments.get('!root-password', None)) and len(root_pw): installation.user_set_pw('root', root_pw) -- cgit v1.2.3-70-g09d2 From e209767d13bb8887ad7449cab59501fdc0eb4f77 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 20 Mar 2021 18:26:38 +0100 Subject: Added helper functions for #81. So that we have a basic information about the terminal when outputting large lists/options. --- archinstall/lib/user_interaction.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 6b3e5faa..b9689d05 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -1,4 +1,4 @@ -import getpass, pathlib +import getpass, pathlib, os, shutil from .exceptions import * from .profiles import Profile from .locale_helpers import search_keyboard_layout @@ -9,6 +9,15 @@ from .networking import list_interfaces ## TODO: Some inconsistencies between the selection processes. ## Some return the keys from the options, some the values? +def get_terminal_height(): + return shutil.get_terminal_size().lines + +def get_terminal_width(): + return shutil.get_terminal_size().columns + +def get_longest_option(options): + return max([len(x) for x in options]) + def get_password(prompt="Enter a password: "): while (passwd := getpass.getpass(prompt)): passwd_verification = getpass.getpass(prompt='And one more time for verification: ') -- cgit v1.2.3-70-g09d2 From 9f87b6963d6b195c35891366cbd5421324a593e3 Mon Sep 17 00:00:00 2001 From: Ninchester <5041877+ninchester@users.noreply.github.com> Date: Sat, 20 Mar 2021 21:41:56 +0100 Subject: Print options in columns --- archinstall/lib/user_interaction.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index b9689d05..b3baebf8 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -27,6 +27,21 @@ def get_password(prompt="Enter a password: "): return passwd return None +def print_large_list(options, padding=5, margin_bottom=0, separator=': '): + longest_line = len(str(len(options))) + len(separator) + get_longest_option(options) + padding + num_of_columns = get_terminal_width() // longest_line + max_options_in_cells = num_of_columns * (get_terminal_height()-margin_bottom) + + if (len(options) > max_options_in_cells): + for index, option in enumerate(options): + print(f"{index}: {option}") + else: + for row in range(0, (get_terminal_height()-margin_bottom)): + for column in range(row, len(options), (get_terminal_height()-margin_bottom)): + spaces = " "*(longest_line - len(options[column])) + print(f"{str(column+1).zfill(2)}{separator}{options[column]}", end = spaces) + print() + def ask_for_superuser_account(prompt='Create a required super-user with sudo privileges: ', forced=False): while 1: new_user = input(prompt).strip(' ') @@ -279,8 +294,7 @@ def select_mirror_regions(mirrors, show_top_mirrors=True): selected_mirrors = {} if len(regions) >= 1: - for index, region in enumerate(regions): - print(f"{index}: {region}") + print_large_list(regions) print(' -- You can enter ? or help to search for more regions --') print(' -- You can skip this step by leaving the option blank --') -- cgit v1.2.3-70-g09d2 From 0318125a7b70114531951da300b06f47f427b89f Mon Sep 17 00:00:00 2001 From: Ninchester <5041877+ninchester@users.noreply.github.com> Date: Sat, 20 Mar 2021 21:48:34 +0100 Subject: Add margin at the bottom --- archinstall/lib/user_interaction.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index b3baebf8..25ca71f0 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -29,8 +29,8 @@ def get_password(prompt="Enter a password: "): def print_large_list(options, padding=5, margin_bottom=0, separator=': '): longest_line = len(str(len(options))) + len(separator) + get_longest_option(options) + padding - num_of_columns = get_terminal_width() // longest_line - max_options_in_cells = num_of_columns * (get_terminal_height()-margin_bottom) + max_num_of_columns = get_terminal_width() // longest_line + max_options_in_cells = max_num_of_columns * (get_terminal_height()-margin_bottom) if (len(options) > max_options_in_cells): for index, option in enumerate(options): @@ -294,7 +294,7 @@ def select_mirror_regions(mirrors, show_top_mirrors=True): selected_mirrors = {} if len(regions) >= 1: - print_large_list(regions) + print_large_list(regions, margin_bottom=4) print(' -- You can enter ? or help to search for more regions --') print(' -- You can skip this step by leaving the option blank --') -- cgit v1.2.3-70-g09d2 From 6dea24ad22a84f35b3416da3440b03768a2afefe Mon Sep 17 00:00:00 2001 From: Ninchester <5041877+ninchester@users.noreply.github.com> Date: Sat, 20 Mar 2021 21:51:57 +0100 Subject: Make option list 0-index based --- archinstall/lib/user_interaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 25ca71f0..e7fba747 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -39,7 +39,7 @@ def print_large_list(options, padding=5, margin_bottom=0, separator=': '): for row in range(0, (get_terminal_height()-margin_bottom)): for column in range(row, len(options), (get_terminal_height()-margin_bottom)): spaces = " "*(longest_line - len(options[column])) - print(f"{str(column+1).zfill(2)}{separator}{options[column]}", end = spaces) + print(f"{str(column).zfill(2)}{separator}{options[column]}", end = spaces) print() def ask_for_superuser_account(prompt='Create a required super-user with sudo privileges: ', forced=False): -- cgit v1.2.3-70-g09d2 From 42ba36b5d8ab5a8442bb4996815598ef517003a2 Mon Sep 17 00:00:00 2001 From: Ninchester <5041877+ninchester@users.noreply.github.com> Date: Sat, 20 Mar 2021 22:01:00 +0100 Subject: Fix number padding based on length of the highest option index - instead of using zeroes, now spaces are used --- archinstall/lib/user_interaction.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index e7fba747..d82068a7 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -28,7 +28,8 @@ def get_password(prompt="Enter a password: "): return None def print_large_list(options, padding=5, margin_bottom=0, separator=': '): - longest_line = len(str(len(options))) + len(separator) + get_longest_option(options) + padding + highest_index_number_length = len(str(len(options))) + longest_line = highest_index_number_length + len(separator) + get_longest_option(options) + padding max_num_of_columns = get_terminal_width() // longest_line max_options_in_cells = max_num_of_columns * (get_terminal_height()-margin_bottom) @@ -39,7 +40,7 @@ def print_large_list(options, padding=5, margin_bottom=0, separator=': '): for row in range(0, (get_terminal_height()-margin_bottom)): for column in range(row, len(options), (get_terminal_height()-margin_bottom)): spaces = " "*(longest_line - len(options[column])) - print(f"{str(column).zfill(2)}{separator}{options[column]}", end = spaces) + print(f"{str(column): >{highest_index_number_length}}{separator}{options[column]}", end = spaces) print() def ask_for_superuser_account(prompt='Create a required super-user with sudo privileges: ', forced=False): -- cgit v1.2.3-70-g09d2 From f3b93c1c1ce774375aedfa02c2220d9b5d4512c2 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 20 Mar 2021 22:15:42 +0100 Subject: Removed search logic for mirrors since we now have column-printouts, the columns enabled us to print all the regions which means the search was an excessive feature. --- archinstall/lib/user_interaction.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index d82068a7..296fa8db 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -295,23 +295,13 @@ def select_mirror_regions(mirrors, show_top_mirrors=True): selected_mirrors = {} if len(regions) >= 1: - print_large_list(regions, margin_bottom=4) + print_large_list(regions, margin_bottom=2) - print(' -- You can enter ? or help to search for more regions --') print(' -- You can skip this step by leaving the option blank --') - print(' -- (You can use Shift + PageUp to scroll in the list --') selected_mirror = input('Select one of the above regions to download packages from (by number or full name): ') if len(selected_mirror.strip()) == 0: return {} - elif selected_mirror.lower() in ('?', 'help'): - filter_string = input('Search for a region containing (example: "united"): ').strip().lower() - for region in mirrors: - if filter_string in region.lower(): - selected_mirrors[region] = mirrors[region] - - return selected_mirrors - elif selected_mirror.isdigit() and (pos := int(selected_mirror)) <= len(regions)-1: region = regions[int(selected_mirror)] selected_mirrors[region] = mirrors[region] -- cgit v1.2.3-70-g09d2 From a3aef119b24201078857e605f2b62c7f6000e91a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 21:30:52 +0100 Subject: Improved english grammar and dialogues. Some 'questions' were formatted in a way where the user would enter 'yes' instead of the expected input. For instance, 'Any additional users to install:' which is a question where 'yes' is a appropriate response, but the expected input was the username to be created. Rephrased it to 'Enter a username to create a additional user:' instead for instance. --- archinstall/lib/user_interaction.py | 8 ++++---- examples/guided.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 296fa8db..c883d6a3 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -136,7 +136,7 @@ def ask_for_main_filesystem_format(): 'vfat' : 'vfat' } - value = generic_select(options.values(), "Select your main partitions filesystem by number or free-text: ") + value = generic_select(options.values(), "Select which filesystem your main partition should use (by number of name): ") return next((key for key, val in options.items() if val == value), None) def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True): @@ -212,10 +212,10 @@ def select_profile(options): for index, profile in enumerate(profiles): print(f"{index}: {profile}") - print(' -- The above list is pre-programmed profiles. --') + print(' -- The above list is a set of pre-programmed profiles. --') print(' -- They might make it easier to install things like desktop environments. --') - print(' -- (Leave blank to skip this next optional step) --') - selected_profile = input('Any particular pre-programmed profile you want to install: ') + print(' -- (Leave blank and hit enter to skip this step and continue) --') + selected_profile = input('Enter a pre-programmed profile name if you want to install one: ') if len(selected_profile.strip()) <= 0: return None diff --git a/examples/guided.py b/examples/guided.py index b6aa5810..4766301e 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -53,7 +53,7 @@ def ask_user_questions(): # 3. Check that we support the current partitions # 2. If so, ask if we should keep them or wipe everything if archinstall.arguments['harddrive'].has_partitions(): - archinstall.log(f"{archinstall.arguments['harddrive']} contains the following partitions:", fg='red') + archinstall.log(f"{archinstall.arguments['harddrive']} contains the following partitions:", fg='yellow') # We curate a list pf supported paritions # and print those that we don't support. @@ -149,7 +149,7 @@ def ask_user_questions(): # Ask for a root password (optional, but triggers requirement for super-user if skipped) if not archinstall.arguments.get('!root-password', None): - archinstall.arguments['!root-password'] = archinstall.get_password(prompt='Enter root password (Recommended: leave blank to leave root disabled): ') + archinstall.arguments['!root-password'] = archinstall.get_password(prompt='Enter root password (Recommendation: leave blank to leave root disabled): ') # Ask for additional users (super-user if root pw was not set) archinstall.arguments['users'] = {} @@ -157,7 +157,7 @@ def ask_user_questions(): if not archinstall.arguments.get('!root-password', None): archinstall.arguments['superusers'] = archinstall.ask_for_superuser_account('Create a required super-user with sudo privileges: ', forced=True) - users, superusers = archinstall.ask_for_additional_users('Any additional users to install (leave blank for no users): ') + users, superusers = archinstall.ask_for_additional_users('Enter a username to create a additional user (leave blank to skip & continue): ') archinstall.arguments['users'] = users archinstall.arguments['superusers'] = {**archinstall.arguments['superusers'], **superusers} @@ -180,7 +180,7 @@ def ask_user_questions(): # Additional packages (with some light weight error handling for invalid package names) if not archinstall.arguments.get('packages', None): - archinstall.arguments['packages'] = [package for package in input('Additional packages aside from base (space separated): ').split(' ') if len(package)] + archinstall.arguments['packages'] = [package for package in input('Write additional packages to install (space separated, leave blank to skip): ').split(' ') if len(package)] # Verify packages that were given try: -- cgit v1.2.3-70-g09d2 From 037332a18d2c506d1dd0bef7b3450c8308792f61 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 24 Mar 2021 15:26:32 +0100 Subject: Removed vfat as an option for the root partition --- archinstall/lib/user_interaction.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index c883d6a3..e462c370 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -132,8 +132,7 @@ def ask_for_main_filesystem_format(): 'btrfs' : 'btrfs', 'ext4' : 'ext4', 'xfs' : 'xfs', - 'f2fs' : 'f2fs', - 'vfat' : 'vfat' + 'f2fs' : 'f2fs' } value = generic_select(options.values(), "Select which filesystem your main partition should use (by number of name): ") @@ -317,4 +316,4 @@ def select_mirror_regions(mirrors, show_top_mirrors=True): return selected_mirrors - raise RequirementError("Selecting mirror region require a least one region to be given as an option.") \ No newline at end of file + raise RequirementError("Selecting mirror region require a least one region to be given as an option.") -- cgit v1.2.3-70-g09d2 From 37a6018aaeed53ca95d9c7f81981db98aab24eab Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 28 Mar 2021 22:36:47 +0200 Subject: Fixed a path-check issue with Time Zones. --- archinstall/lib/installer.py | 16 ++++++++++++---- archinstall/lib/user_interaction.py | 8 +++++++- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 2200db8e..ff47be01 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -169,11 +169,19 @@ class Installer(): return True if sys_command(f'/usr/bin/arch-chroot {self.mountpoint} locale-gen').exit_code == 0 else False def set_timezone(self, zone, *args, **kwargs): - if not len(zone): return True + if not zone: return True + if not len(zone): return True # Redundant - (pathlib.Path(self.mountpoint)/"etc"/"localtime").unlink(missing_ok=True) - sys_command(f'/usr/bin/arch-chroot {self.mountpoint} ln -s /usr/share/zoneinfo/{zone} /etc/localtime') - return True + if (pathlib.Path("/usr")/"share"/"zoneinfo"/zone).exists(): + (pathlib.Path(self.mountpoint)/"etc"/"localtime").unlink(missing_ok=True) + sys_command(f'/usr/bin/arch-chroot {self.mountpoint} ln -s /usr/share/zoneinfo/{zone} /etc/localtime') + return True + else: + self.log( + f"Time zone {zone} does not exist, continuing with system default.", + level=LOG_LEVELS.Warning, + fg='red' + ) def activate_ntp(self): self.log(f'Installing and activating NTP.', level=LOG_LEVELS.Info) diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index e462c370..a79b4847 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -77,8 +77,14 @@ def ask_for_additional_users(prompt='Any additional users to install (leave blan def ask_for_a_timezone(): timezone = input('Enter a valid timezone (Example: Europe/Stockholm): ').strip() - if pathlib.Path(timezone).exists(): + if (pathlib.Path("/usr")/"share"/"zoneinfo"/timezone).exists(): return timezone + else: + log( + f"Time zone {timezone} does not exist, continuing with system default.", + level=LOG_LEVELS.Warning, + fg='red' + ) def ask_to_configure_network(): # Optionally configure one network interface. -- cgit v1.2.3-70-g09d2 From f452dc695a6a2929ecf796f1730af3b683b1a449 Mon Sep 17 00:00:00 2001 From: Didr Date: Mon, 29 Mar 2021 10:16:20 +0200 Subject: Fix spelling error in filesystem choice Fixes a simple spelling error when the user is asked to select a filesystem. "Select which filesystem your main partition should use (by number **of** name)" should be **or**. --- archinstall/lib/user_interaction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index a79b4847..a782197e 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -141,7 +141,7 @@ def ask_for_main_filesystem_format(): 'f2fs' : 'f2fs' } - value = generic_select(options.values(), "Select which filesystem your main partition should use (by number of name): ") + value = generic_select(options.values(), "Select which filesystem your main partition should use (by number or name): ") return next((key for key, val in options.items() if val == value), None) def generic_select(options, input_text="Select one of the above by index or absolute value: ", sort=True): -- cgit v1.2.3-70-g09d2 From 36dfa2e1c42add691243850b62b705b26a0a796c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 10:20:35 +0200 Subject: Reverting .strip() logic and moving the check into the get_password() function. --- archinstall/lib/user_interaction.py | 4 ++++ examples/guided.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index a79b4847..bee7b569 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -24,6 +24,10 @@ def get_password(prompt="Enter a password: "): if passwd != passwd_verification: log(' * Passwords did not match * ', bg='black', fg='red') continue + + if len(passwd.strip()) <= 0: + break + return passwd return None diff --git a/examples/guided.py b/examples/guided.py index 009f9fa6..92331450 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -139,7 +139,7 @@ def ask_user_questions(): # Get disk encryption password (or skip if blank) if not archinstall.arguments.get('!encryption-password', None): - if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')).strip(): + if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')): archinstall.arguments['!encryption-password'] = passwd archinstall.arguments['harddrive'].encryption_password = archinstall.arguments['!encryption-password'] -- cgit v1.2.3-70-g09d2 From 82342a0e94ed6d591b9855db590719764e9cb460 Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Tue, 30 Mar 2021 16:12:52 +0200 Subject: Add range check to generic_select --- archinstall/lib/user_interaction.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index defc2cfc..b3e0b665 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -170,7 +170,10 @@ def generic_select(options, input_text="Select one of the above by index or abso if len(selected_option.strip()) <= 0: return None elif selected_option.isdigit(): - selected_option = options[int(selected_option)] + selected_option = int(selected_option) + if selected_option >= len(options): + raise RequirementError(f'Selected option "{selected_option}" is out of range') + selected_option = options[selected_option] elif selected_option in options: pass # We gave a correct absolute value else: -- cgit v1.2.3-70-g09d2 From 40dbb5791c4be60d671d0a4abd2e9ba70e11b896 Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Tue, 30 Mar 2021 16:24:48 +0200 Subject: Add range check to disk selection --- archinstall/lib/user_interaction.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'archinstall/lib/user_interaction.py') diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index b3e0b665..80db7be1 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -198,7 +198,10 @@ def select_disk(dict_o_disks): print(f"{index}: {drive} ({dict_o_disks[drive]['size'], dict_o_disks[drive].device, dict_o_disks[drive]['label']})") drive = input('Select one of the above disks (by number or full path): ') if drive.isdigit(): - drive = dict_o_disks[drives[int(drive)]] + drive = int(drive) + if drive >= len(drives): + raise DiskError(f'Selected option "{drive}" is out of range') + drive = dict_o_disks[drives[drive]] elif drive in dict_o_disks: drive = dict_o_disks[drive] else: -- cgit v1.2.3-70-g09d2