index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Aggam Rahamim <agamclass@gmail.com> | 2021-04-25 14:56:03 +0300 |
---|---|---|
committer | Aggam Rahamim <agamclass@gmail.com> | 2021-04-25 14:56:03 +0300 |
commit | e25018131756757999bbe8ba8e54ec3ae8224c7d (patch) | |
tree | 828fb3ad3882d4dfac3e522c52a16369c6042990 /archinstall/lib | |
parent | 5c9859d316b8064949370c03745cfd99e0d67670 (diff) | |
parent | 4db40c06eb37390eaa19b6d8b0afa7b21c5e65b3 (diff) |
-rw-r--r-- | archinstall/lib/disk.py | 59 | ||||
-rw-r--r-- | archinstall/lib/general.py | 54 | ||||
-rw-r--r-- | archinstall/lib/hardware.py | 57 | ||||
-rw-r--r-- | archinstall/lib/installer.py | 49 | ||||
-rw-r--r-- | archinstall/lib/locale_helpers.py | 13 | ||||
-rw-r--r-- | archinstall/lib/profiles.py | 46 | ||||
-rw-r--r-- | archinstall/lib/user_interaction.py | 72 |
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index bada4076..67c2bdcd 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -5,6 +5,7 @@ from .exceptions import DiskError from .general import * from .output import log, LOG_LEVELS from .storage import storage +from .hardware import hasUEFI ROOT_DIR_PATTERN = re.compile('^.*?/devices') GPT = 0b00000001 @@ -73,7 +74,7 @@ class BlockDevice(): raise DiskError(f'Could not locate backplane info for "{self.path}"') if self.info['type'] == 'loop': - for drive in json.loads(b''.join(sys_command(f'losetup --json', hide_from_log=True)).decode('UTF_8'))['loopdevices']: + for drive in json.loads(b''.join(sys_command(['losetup', '--json'], hide_from_log=True)).decode('UTF_8'))['loopdevices']: if not drive['name'] == self.path: continue return drive['back-file'] @@ -94,10 +95,10 @@ class BlockDevice(): @property def partitions(self): - o = b''.join(sys_command(f'partprobe {self.path}')) + o = b''.join(sys_command(['partprobe', self.path])) #o = b''.join(sys_command('/usr/bin/lsblk -o name -J -b {dev}'.format(dev=dev))) - o = b''.join(sys_command(f'/usr/bin/lsblk -J {self.path}')) + o = b''.join(sys_command(['/usr/bin/lsblk', '-J', self.path])) if b'not a block device' in o: raise DiskError(f'Can not read partitions off something that isn\'t a block device: {self.path}') @@ -427,7 +428,7 @@ class Filesystem(): # TODO: # When instance of a HDD is selected, check all usages and gracefully unmount them # as well as close any crypto handles. - def __init__(self, blockdevice, mode=GPT): + def __init__(self, blockdevice,mode): self.blockdevice = blockdevice self.mode = mode @@ -440,6 +441,11 @@ class Filesystem(): return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') + elif self.mode == MBR: + if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos').exit_code == 0: + return self + else: + raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos') else: raise DiskError(f'Unknown mode selected to format in: {self.mode}') @@ -482,28 +488,39 @@ class Filesystem(): def use_entire_disk(self, root_filesystem_type='ext4'): log(f"Using and formatting the entire {self.blockdevice}.", level=LOG_LEVELS.Debug) - self.add_partition('primary', start='1MiB', end='513MiB', format='fat32') - self.set_name(0, 'EFI') - self.set(0, 'boot on') - # TODO: Probably redundant because in GPT mode 'esp on' is an alias for "boot on"? - # https://www.gnu.org/software/parted/manual/html_node/set.html - self.set(0, 'esp on') - self.add_partition('primary', start='513MiB', end='100%') - - self.blockdevice.partition[0].filesystem = 'vfat' - self.blockdevice.partition[1].filesystem = root_filesystem_type - log(f"Set the root partition {self.blockdevice.partition[1]} to use filesystem {root_filesystem_type}.", level=LOG_LEVELS.Debug) - - self.blockdevice.partition[0].target_mountpoint = '/boot' - self.blockdevice.partition[1].target_mountpoint = '/' - - self.blockdevice.partition[0].allow_formatting = True - self.blockdevice.partition[1].allow_formatting = True + if hasUEFI(): + self.add_partition('primary', start='1MiB', end='513MiB', format='fat32') + self.set_name(0, 'EFI') + self.set(0, 'boot on') + # TODO: Probably redundant because in GPT mode 'esp on' is an alias for "boot on"? + # https://www.gnu.org/software/parted/manual/html_node/set.html + self.set(0, 'esp on') + self.add_partition('primary', start='513MiB', end='100%') + + self.blockdevice.partition[0].filesystem = 'vfat' + self.blockdevice.partition[1].filesystem = root_filesystem_type + log(f"Set the root partition {self.blockdevice.partition[1]} to use filesystem {root_filesystem_type}.", level=LOG_LEVELS.Debug) + + self.blockdevice.partition[0].target_mountpoint = '/boot' + self.blockdevice.partition[1].target_mountpoint = '/' + + self.blockdevice.partition[0].allow_formatting = True + self.blockdevice.partition[1].allow_formatting = True + else: + #we don't need a seprate boot partition it would be a waste of space + self.add_partition('primary', start='1MB', end='100%') + self.blockdevice.partition[0].filesystem=root_filesystem_type + log(f"Set the root partition {self.blockdevice.partition[0]} to use filesystem {root_filesystem_type}.", level=LOG_LEVELS.Debug) + self.blockdevice.partition[0].target_mountpoint = '/' + self.blockdevice.partition[0].allow_formatting = True def add_partition(self, type, start, end, format=None): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) previous_partitions = self.blockdevice.partitions + if self.mode == MBR: + if len(self.blockdevice.partitions)>3: + DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions") if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 else: diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 6e3b66f1..dc0f018a 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -76,7 +76,7 @@ class sys_command():#Thread): """ Stolen from archinstall_gui """ - def __init__(self, cmd, callback=None, start_callback=None, environment_vars={}, *args, **kwargs): + def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars={}, *args, **kwargs): kwargs.setdefault("worker_id", gen_uid()) kwargs.setdefault("emulate", False) kwargs.setdefault("suppress_errors", False) @@ -86,13 +86,22 @@ class sys_command():#Thread): if kwargs['emulate']: self.log(f"Starting command '{cmd}' in emulation mode.", level=LOG_LEVELS.Debug) - self.raw_cmd = cmd - try: - self.cmd = shlex.split(cmd) - except Exception as e: - raise ValueError(f'Incorrect string to split: {cmd}\n{e}') + if type(cmd) is list: + # if we get a list of arguments + self.raw_cmd = shlex.join(cmd) + self.cmd = cmd + else: + # else consider it a single shell string + # this should only be used if really necessary + self.raw_cmd = cmd + try: + self.cmd = shlex.split(cmd) + except Exception as e: + raise ValueError(f'Incorrect string to split: {cmd}\n{e}') + self.args = args self.kwargs = kwargs + self.peak_output = peak_output self.environment_vars = environment_vars self.kwargs.setdefault("worker", None) @@ -151,6 +160,38 @@ class sys_command():#Thread): 'exit_code': self.exit_code } + def peak(self, output :str): + if type(output) == bytes: + try: + output = output.decode('UTF-8') + except UnicodeDecodeError: + return None + + output = output.strip('\r\n ') + if len(output) <= 0: + return None + + if self.peak_output: + from .user_interaction import get_terminal_width + + # Move back to the beginning of the terminal + sys.stdout.flush() + sys.stdout.write("\033[%dG" % 0) + sys.stdout.flush() + + # Clear the line + sys.stdout.write(" " * get_terminal_width()) + sys.stdout.flush() + + # Move back to the beginning again + sys.stdout.flush() + sys.stdout.write("\033[%dG" % 0) + sys.stdout.flush() + + # And print the new output we're peaking on: + sys.stdout.write(output) + sys.stdout.flush() + def run(self): self.status = 'running' old_dir = os.getcwd() @@ -182,6 +223,7 @@ class sys_command():#Thread): for fileno, event in poller.poll(0.1): try: output = os.read(child_fd, 8192) + self.peak(output) self.trace_log += output except OSError: alive = False diff --git a/archinstall/lib/hardware.py b/archinstall/lib/hardware.py index 5828fd09..d6cf982c 100644 --- a/archinstall/lib/hardware.py +++ b/archinstall/lib/hardware.py @@ -1,14 +1,42 @@ -import os +import os, subprocess, json from .general import sys_command from .networking import list_interfaces, enrichIfaceTypes +from typing import Optional -def hasWifi(): +AVAILABLE_GFX_DRIVERS = { + # Sub-dicts are layer-2 options to be selected + # and lists are a list of packages to be installed + 'AMD / ATI' : { + 'amd' : ['xf86-video-amdgpu'], + 'ati' : ['xf86-video-ati'] + }, + 'intel' : ['xf86-video-intel'], + 'nvidia' : { + 'open-source' : ['xf86-video-nouveau'], + 'proprietary' : ['nvidia'] + }, + 'mesa' : ['mesa'], + 'fbdev' : ['xf86-video-fbdev'], + 'vesa' : ['xf86-video-vesa'], + 'vmware' : ['xf86-video-vmware'] +} + +def hasWifi()->bool: return 'WIRELESS' in enrichIfaceTypes(list_interfaces().values()).values() -def hasUEFI(): +def hasAMDCPU()->bool: + if subprocess.check_output("lscpu | grep AMD", shell=True).strip().decode(): + return True + return False +def hasIntelCPU()->bool: + if subprocess.check_output("lscpu | grep Intel", shell=True).strip().decode(): + return True + return False + +def hasUEFI()->bool: return os.path.isdir('/sys/firmware/efi') -def graphicsDevices(): +def graphicsDevices()->dict: cards = {} for line in sys_command(f"lspci"): if b' VGA ' in line: @@ -16,13 +44,28 @@ def graphicsDevices(): cards[identifier.strip().lower().decode('UTF-8')] = line return cards -def hasNvidiaGraphics(): +def hasNvidiaGraphics()->bool: return any('nvidia' in x for x in graphicsDevices()) -def hasAmdGraphics(): +def hasAmdGraphics()->bool: return any('amd' in x for x in graphicsDevices()) -def hasIntelGraphics(): +def hasIntelGraphics()->bool: return any('intel' in x for x in graphicsDevices()) + +def cpuVendor()-> Optional[str]: + cpu_info = json.loads(subprocess.check_output("lscpu -J", shell=True).decode('utf-8'))['lscpu'] + for info in cpu_info: + if info.get('field',None): + if info.get('field',None) == "Vendor ID:": + return info.get('data',None) + +def isVM() -> bool: + try: + subprocess.check_call(["systemd-detect-virt"]) # systemd-detect-virt issues a none 0 exit code if it is not on a virtual machine + return True + except: + return False + # TODO: Add more identifiers diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index d952a6ed..7d3364dd 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -9,6 +9,11 @@ from .mirrors import * from .systemd import Networkd from .output import log, LOG_LEVELS from .storage import storage +from .hardware import * + +# Any package that the Installer() is responsible for (optional and the default ones) +__packages__ = ["base", "base-devel", "linux", "linux-firmware", "efibootmgr", "nano", "ntp", "iwd"] +__base_packages__ = __packages__[:6] class Installer(): """ @@ -18,7 +23,7 @@ class Installer(): :param partition: Requires a partition as the first argument, this is so that the installer can mount to `mountpoint` and strap packages there. :type partition: class:`archinstall.Partition` - + :param boot_partition: There's two reasons for needing a boot partition argument, The first being so that `mkinitcpio` can place the `vmlinuz` kernel at the right place during the `pacstrap` or `linux` and the base packages for a minimal installation. @@ -29,7 +34,7 @@ class Installer(): :param profile: A profile to install, this is optional and can be called later manually. This just simplifies the process by not having to call :py:func:`~archinstall.Installer.install_profile` later on. :type profile: str, optional - + :param hostname: The given /etc/hostname for the machine. :type hostname: str, optional @@ -142,7 +147,7 @@ class Installer(): if not os.path.isfile(f'{self.target}/etc/fstab'): raise RequirementError(f'Could not generate fstab, strapping in packages most likely failed (disk out of space?)\n{fstab}') - + return True def set_hostname(self, hostname :str, *args, **kwargs): @@ -224,7 +229,7 @@ class Installer(): # If we haven't installed the base yet (function called pre-maturely) if self.helper_flags.get('base', False) is False: self.base_packages.append('iwd') - # This function will be called after minimal_installation() + # This function will be called after minimal_installation() # as a hook for post-installs. This hook is only needed if # base is not installed yet. def post_install_enable_iwd_service(*args, **kwargs): @@ -274,6 +279,7 @@ class Installer(): ## (encrypted partitions default to btrfs for now, so we need btrfs-progs) ## TODO: Perhaps this should be living in the function which dictates ## the partitioning. Leaving here for now. + MODULES = [] BINARIES = [] FILES = [] @@ -299,10 +305,20 @@ class Installer(): if 'encrypt' not in HOOKS: HOOKS.insert(HOOKS.index('filesystems'), 'encrypt') + if not(hasUEFI()): # TODO: Allow for grub even on EFI + self.base_packages.append('grub') + self.pacstrap(self.base_packages) self.helper_flags['base-strapped'] = True #self.genfstab() - + if not isVM(): + vendor = cpuVendor() + if vendor == "AuthenticAMD": + self.base_packages.append("amd-ucode") + elif vendor == "GenuineIntel": + self.base_packages.append("intel-ucode") + else: + self.log("Unknown cpu vendor not installing ucode") with open(f"{self.target}/etc/fstab", "a") as fstab: fstab.write( "\ntmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0\n" @@ -346,6 +362,8 @@ class Installer(): self.log(f'Adding bootloader {bootloader} to {boot_partition}', level=LOG_LEVELS.Info) if bootloader == 'systemd-bootctl': + if not hasUEFI(): + raise HardwareIncompatibilityError # TODO: Ideally we would want to check if another config # points towards the same disk and/or partition. # And in which case we should do some clean up. @@ -373,13 +391,20 @@ class Installer(): ## For some reason, blkid and /dev/disk/by-uuid are not getting along well. ## And blkid is wrong in terms of LUKS. #UUID = sys_command('blkid -s PARTUUID -o value {drive}{partition_2}'.format(**args)).decode('UTF-8').strip() - # Setup the loader entry with open(f'{self.target}/boot/loader/entries/{self.init_time}.conf', 'w') as entry: entry.write(f'# Created by: archinstall\n') entry.write(f'# Created on: {self.init_time}\n') entry.write(f'title Arch Linux\n') entry.write(f'linux /vmlinuz-linux\n') + if not isVM(): + vendor = cpuVendor() + if vendor == "AuthenticAMD": + entry.write("initrd /amd-ucode.img\n") + elif vendor == "GenuineIntel": + entry.write("initrd /intel-ucode.img\n") + else: + self.log("unknow cpu vendor, not adding ucode to systemd-boot config") entry.write(f'initrd /initramfs-linux.img\n') ## blkid doesn't trigger on loopback devices really well, ## so we'll use the old manual method until we get that sorted out. @@ -397,7 +422,17 @@ class Installer(): self.helper_flags['bootloader'] = bootloader return True - raise RequirementError(f"Could not identify the UUID of {root_partition}, there for {self.target}/boot/loader/entries/arch.conf will be broken until fixed.") + raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.target}/boot/loader/entries/arch.conf will be broken until fixed.") + elif bootloader == "grub-install": + if hasUEFI(): + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.target} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') + else: + root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{root_partition.path.strip("/dev/")}/..")', shell=True).decode().strip() + if root_device == "block": + root_device = f"{root_partition.path}" + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.target} grub-install --target=--target=i386-pc /dev/{root_device}')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") diff --git a/archinstall/lib/locale_helpers.py b/archinstall/lib/locale_helpers.py index 82964dc9..736bfc47 100644 --- a/archinstall/lib/locale_helpers.py +++ b/archinstall/lib/locale_helpers.py @@ -4,27 +4,22 @@ import os from .exceptions import * # from .general import sys_command -def list_keyboard_languages(layout='qwerty'): +def list_keyboard_languages(): locale_dir = '/usr/share/kbd/keymaps/' if not os.path.isdir(locale_dir): raise RequirementError(f'Directory containing locales does not exist: {locale_dir}') for root, folders, files in os.walk(locale_dir): - # Since qwerty is under /i386/ but other layouts are - # in different spots, we'll need to filter the last foldername - # of the path to verify against the desired layout. - if os.path.basename(root) != layout: - continue for file in files: if os.path.splitext(file)[1] == '.gz': yield file.strip('.gz').strip('.map') -def search_keyboard_layout(filter, layout='qwerty'): - for language in list_keyboard_languages(layout): +def search_keyboard_layout(filter): + for language in list_keyboard_languages(): if filter.lower() in language.lower(): yield language def set_keyboard_language(locale): - return subprocess.call(['loadkeys',locale]) == 0 + return subprocess.call(['loadkeys', locale]) == 0 diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 21ec5f6f..c5f63e72 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -177,7 +177,7 @@ class Profile(Script): if hasattr(imported, '_prep_function'): return True return False - """ + def has_post_install(self): with open(self.path, 'r') as source: source_data = source.read() @@ -193,7 +193,6 @@ class Profile(Script): with self.load_instructions(namespace=f"{self.namespace}.py") as imported: if hasattr(imported, '_post_install'): return True - """ def is_top_level_profile(self): with open(self.path, 'r') as source: @@ -224,6 +223,49 @@ class Profile(Script): return None + def has_post_install(self): + with open(self.path, 'r') as source: + source_data = source.read() + + # Some crude safety checks, make sure the imported profile has + # a __name__ check and if so, check if it's got a _prep_function() + # we can call to ask for more user input. + # + # If the requirements are met, import with .py in the namespace to not + # trigger a traditional: + # if __name__ == 'moduleName' + if '__name__' in source_data and '_post_install' in source_data: + with self.load_instructions(namespace=f"{self.namespace}.py") as imported: + if hasattr(imported, '_post_install'): + return True + + def is_top_level_profile(self): + with open(self.path, 'r') as source: + source_data = source.read() + return 'top_level_profile = True' in source_data + + @property + def packages(self) -> list: + """ + Returns a list of packages baked into the profile definition. + If no package definition has been done, .packages() will return None. + """ + with open(self.path, 'r') as source: + source_data = source.read() + + # Some crude safety checks, make sure the imported profile has + # a __name__ check before importing. + # + # If the requirements are met, import with .py in the namespace to not + # trigger a traditional: + # if __name__ == 'moduleName' + if '__name__' in source_data and '__packages__' in source_data: + with self.load_instructions(namespace=f"{self.namespace}.py") as imported: + if hasattr(imported, '__packages__'): + return imported.__packages__ + return None + + class Application(Profile): def __repr__(self, *args, **kwargs): return f'Application({os.path.basename(self.profile)})' diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 3da24684..b93f88b3 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -6,6 +6,8 @@ from .locale_helpers import search_keyboard_layout from .output import log, LOG_LEVELS from .storage import storage from .networking import list_interfaces +from .general import sys_command +from .hardware import AVAILABLE_GFX_DRIVERS ## TODO: Some inconsistencies between the selection processes. ## Some return the keys from the options, some the values? @@ -325,6 +327,8 @@ def select_language(options, show_only_country_codes=True): :return: The language/dictionary key of the selected language :rtype: str """ + DEFAULT_KEYBOARD_LANGUAGE = 'us' + if show_only_country_codes: languages = sorted([language for language in list(options) if len(language) == 2]) else: @@ -334,9 +338,12 @@ def select_language(options, show_only_country_codes=True): for index, language in enumerate(languages): print(f"{index}: {language}") - print(' -- You can enter ? or help to search for more languages --') + print(' -- You can enter ? or help to search for more languages, or skip to use US layout --') selected_language = input('Select one of the above keyboard languages (by number or full name): ') - if selected_language.lower() in ('?', 'help'): + + if len(selected_language.strip()) == 0: + return DEFAULT_KEYBOARD_LANGUAGE + elif selected_language.lower() in ('?', 'help'): while True: filter_string = input('Search for layout containing (example: "sv-"): ') new_options = list(search_keyboard_layout(filter_string)) @@ -349,6 +356,7 @@ def select_language(options, show_only_country_codes=True): elif selected_language.isdigit() and (pos := int(selected_language)) <= len(languages)-1: selected_language = languages[pos] + return selected_language # I'm leaving "options" on purpose here. # Since languages possibly contains a filtered version of # all possible language layouts, and we might want to write @@ -356,9 +364,9 @@ def select_language(options, show_only_country_codes=True): # go through the search step. elif selected_language in options: selected_language = options[options.index(selected_language)] + return selected_language else: - RequirementError("Selected language does not exist.") - return selected_language + raise RequirementError("Selected language does not exist.") raise RequirementError("Selecting languages require a least one language to be given as an option.") @@ -382,26 +390,64 @@ def select_mirror_regions(mirrors, show_top_mirrors=True): selected_mirrors = {} if len(regions) >= 1: - print_large_list(regions, margin_bottom=2) + print_large_list(regions, margin_bottom=4) print(' -- You can skip this step by leaving the option blank --') selected_mirror = input('Select one of the above regions to download packages from (by number or full name): ') if len(selected_mirror.strip()) == 0: + # Returning back empty options which can be both used to + # do "if x:" logic as well as do `x.get('mirror', {}).get('sub', None)` chaining return {} - elif selected_mirror.isdigit() and (pos := int(selected_mirror)) <= len(regions)-1: + elif selected_mirror.isdigit() and int(selected_mirror) <= len(regions)-1: + # I'm leaving "mirrors" on purpose here. + # Since region possibly contains a known region of + # all possible regions, and we might want to write + # for instance Sweden (if we know that exists) without having to + # go through the search step. region = regions[int(selected_mirror)] selected_mirrors[region] = mirrors[region] - # I'm leaving "mirrors" on purpose here. - # Since region possibly contains a known region of - # all possible regions, and we might want to write - # for instance Sweden (if we know that exists) without having to - # go through the search step. elif selected_mirror in mirrors: selected_mirrors[selected_mirror] = mirrors[selected_mirror] else: - RequirementError("Selected region does not exist.") + raise RequirementError("Selected region does not exist.") return selected_mirrors - return None + raise RequirementError("Selecting mirror region require a least one region to be given as an option.") + +def select_driver(options=AVAILABLE_GFX_DRIVERS): + """ + Some what convoluted function, which's job is simple. + Select a graphics driver from a pre-defined set of popular options. + + (The template xorg is for beginner users, not advanced, and should + there for appeal to the general public first and edge cases later) + """ + if len(options) >= 1: + lspci = sys_command(f'/usr/bin/lspci') + for line in lspci.trace_log.split(b'\r\n'): + if b' vga ' in line.lower(): + if b'nvidia' in line.lower(): + print(' ** nvidia card detected, suggested driver: nvidia **') + elif b'amd' in line.lower(): + print(' ** AMD card detected, suggested driver: AMD / ATI **') + + selected_driver = generic_select(options, input_text="Select your graphics card driver: ", sort=True) + initial_option = selected_driver + + if type(options[initial_option]) == dict: + driver_options = sorted(options[initial_option].keys()) + + selected_driver_package_group = generic_select(driver_options, input_text=f"Which driver-type do you want for {initial_option}: ") + if selected_driver_package_group in options[initial_option].keys(): + print(options[initial_option][selected_driver_package_group]) + selected_driver = options[initial_option][selected_driver_package_group] + else: + raise RequirementError(f"Selected driver-type does not exist for {initial_option}.") + + return selected_driver_package_group + + return selected_driver + + raise RequirementError("Selecting drivers require a least one profile to be given as an option.") |