created load_config() to load configuration

This commit is contained in:
Yash Tripathi 2021-07-18 01:28:41 +05:30
parent 8489137b87
commit d55b1786c5
2 changed files with 31 additions and 42 deletions

View File

@ -710,7 +710,8 @@ def select_driver(options=AVAILABLE_GFX_DRIVERS):
if has_nvidia_graphics(): if has_nvidia_graphics():
print('For the best compatibility with your Nvidia hardware, you may want to use the Nvidia proprietary driver.') print('For the best compatibility with your Nvidia hardware, you may want to use the Nvidia proprietary driver.')
arguments['gfx_driver'] = generic_select(drivers, input_text="Select your graphics card driver: ") if not arguments.get('gfx_driver', None):
arguments['gfx_driver'] = generic_select(drivers, input_text="Select a graphics driver or leave blank to install all open-source drivers: ")
if arguments.get('gfx_driver', None) is None: if arguments.get('gfx_driver', None) is None:
arguments['gfx_driver'] = "All open-source (default)" arguments['gfx_driver'] = "All open-source (default)"

View File

@ -26,6 +26,29 @@ archinstall.log(f"Graphics devices detected: {archinstall.graphics_devices().key
# For support reasons, we'll log the disk layout pre installation to match against post-installation layout # For support reasons, we'll log the disk layout pre installation to match against post-installation layout
archinstall.log(f"Disk states before installing: {archinstall.disk_layouts()}", level=logging.DEBUG) archinstall.log(f"Disk states before installing: {archinstall.disk_layouts()}", level=logging.DEBUG)
def load_config():
if archinstall.arguments.get('harddrive', None) is not None:
archinstall.arguments['harddrive'] = archinstall.BlockDevice(path=archinstall.arguments['harddrive']['path'])
# Temporarily disabling keep_partitions if config file is loaded
archinstall.arguments['harddrive'].keep_partitions = False
# Temporary workaround to make Desktop Environments work
if archinstall.arguments.get('profile', None) is not None:
if type(archinstall.arguments.get('profile', None)) is dict:
archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None)['path'])
else:
archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None))
if archinstall.arguments.get('mirror-region', None) is not None:
if type(archinstall.arguments.get('mirror-region', None)) is dict:
archinstall.arguments['mirror-region'] = archinstall.arguments.get('mirror-region', None)
else:
selected_region = archinstall.arguments.get('mirror-region', None)
archinstall.arguments['mirror-region'] = {selected_region: archinstall.list_mirrors()[selected_region]}
if archinstall.arguments.get('sys-language', None) is not None:
archinstall.arguments['sys-language'] = archinstall.arguments.get('sys-language', 'en_US')
if archinstall.arguments.get('sys-encoding', None) is not None:
archinstall.arguments['sys-encoding'] = archinstall.arguments.get('sys-encoding', 'utf-8')
if archinstall.arguments.get('gfx_driver', None) is not None:
archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(archinstall.arguments.get('gfx_driver', None), None)
def ask_user_questions(): def ask_user_questions():
""" """
@ -54,9 +77,6 @@ def ask_user_questions():
break break
except archinstall.RequirementError as e: except archinstall.RequirementError as e:
archinstall.log(e, fg="red") archinstall.log(e, fg="red")
else:
selected_region = archinstall.arguments['mirror-region']
archinstall.arguments['mirror-region'] = {selected_region: archinstall.list_mirrors()[selected_region]}
if not archinstall.arguments.get('sys-language', None) and archinstall.arguments.get('advanced', False): if not archinstall.arguments.get('sys-language', None) and archinstall.arguments.get('advanced', False):
archinstall.arguments['sys-language'] = input("Enter a valid locale (language) for your OS, (Default: en_US): ").strip() archinstall.arguments['sys-language'] = input("Enter a valid locale (language) for your OS, (Default: en_US): ").strip()
@ -69,9 +89,7 @@ def ask_user_questions():
archinstall.arguments['sys-encoding'] = 'utf-8' archinstall.arguments['sys-encoding'] = 'utf-8'
# Ask which harddrive/block-device we will install to # Ask which harddrive/block-device we will install to
if archinstall.arguments.get('harddrive', None): if not archinstall.arguments.get('harddrive', None):
archinstall.arguments['harddrive'] = archinstall.BlockDevice(archinstall.arguments['harddrive'])
else:
archinstall.arguments['harddrive'] = archinstall.select_disk(archinstall.all_disks()) archinstall.arguments['harddrive'] = archinstall.select_disk(archinstall.all_disks())
if archinstall.arguments['harddrive'] is None: if archinstall.arguments['harddrive'] is None:
archinstall.arguments['target-mount'] = archinstall.storage.get('MOUNT_POINT', '/mnt') archinstall.arguments['target-mount'] = archinstall.storage.get('MOUNT_POINT', '/mnt')
@ -188,20 +206,15 @@ def ask_user_questions():
archinstall.arguments['!root-password'] = archinstall.get_password(prompt='Enter root password (Recommendation: 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) # Ask for additional users (super-user if root pw was not set)
archinstall.arguments['users'] = {} if not archinstall.arguments.get('!root-password', None) and not archinstall.arguments.get('superusers', None):
archinstall.arguments['superusers'] = {}
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) 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('Enter a username to create a additional user (leave blank to skip & continue): ')
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['users'] = users archinstall.arguments['superusers'] = {**archinstall.arguments['superusers'], **superusers}
archinstall.arguments['superusers'] = {**archinstall.arguments['superusers'], **superusers}
# Ask for archinstall-specific profiles (such as desktop environments etc) # Ask for archinstall-specific profiles (such as desktop environments etc)
if not archinstall.arguments.get('profile', None): if not archinstall.arguments.get('profile', None):
archinstall.arguments['profile'] = archinstall.select_profile() archinstall.arguments['profile'] = archinstall.select_profile()
else:
archinstall.arguments['profile'] = Profile(installer=None, path=archinstall.arguments['profile'])
# Check the potentially selected profiles preparations to get early checks if some additional questions are needed. # Check the potentially selected profiles preparations to get early checks if some additional questions are needed.
if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function(): if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function():
@ -437,33 +450,8 @@ if not check_mirror_reachable():
archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red") archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red")
exit(1) exit(1)
load_config()
if not archinstall.arguments.get('silent'): if not archinstall.arguments.get('silent'):
ask_user_questions() ask_user_questions()
else:
# Workarounds if config is loaded from a file
# The harddrive section should be moved to perform_installation_steps, where it's actually being performed
# Blockdevice object should be created in perform_installation_steps
# This needs to be done until then
archinstall.arguments['harddrive'] = archinstall.BlockDevice(path=archinstall.arguments['harddrive']['path'])
# Temporarily disabling keep_partitions if config file is loaded
archinstall.arguments['harddrive'].keep_partitions = False
# Temporary workaround to make Desktop Environments work
if archinstall.arguments.get('profile', None) is not None:
if type(archinstall.arguments.get('profile', None)) is dict:
archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None)['path'])
else:
archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None))
else:
archinstall.arguments['profile'] = None
if archinstall.arguments.get('mirror-region', None) is not None:
if type(archinstall.arguments.get('mirror-region', None)) is dict:
archinstall.arguments['mirror-region'] = archinstall.arguments.get('mirror-region', None)
else:
selected_region = archinstall.arguments.get('mirror-region', None)
archinstall.arguments['mirror-region'] = {selected_region: archinstall.list_mirrors()[selected_region]}
archinstall.arguments['sys-language'] = archinstall.arguments.get('sys-language', 'en_US')
archinstall.arguments['sys-encoding'] = archinstall.arguments.get('sys-encoding', 'utf-8')
if archinstall.arguments.get('gfx_driver', None) is not None:
archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(archinstall.arguments.get('gfx_driver', None), None)
perform_installation_steps() perform_installation_steps()