From 63c76d7af921a237aee10c4b326f6b2a8cf4f8e3 Mon Sep 17 00:00:00 2001 From: comrumino Date: Mon, 30 Nov 2020 21:50:32 -0600 Subject: [PATCH] Fixed default font traceback; added logic to prevent crash reporting if grub install fails and user manually partitioned so that we get less noise on irc; fixed sanity check by changing from os-release to pacman exists to be more flexible with distro --- asinstaller/__main__.py | 4 +-- asinstaller/install.py | 61 +++++++++++++++++++++++------------------ asinstaller/utils.py | 20 +++++++------- 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/asinstaller/__main__.py b/asinstaller/__main__.py index eb11ed5..7977b64 100755 --- a/asinstaller/__main__.py +++ b/asinstaller/__main__.py @@ -18,8 +18,8 @@ def main(): logger = get_logger(__name__) logger.debug(f'Version: {__version__}') # Pre-checks - if not is_arch_linux(): - print_error("At this time, only Arch Linux is supported") + if not pacman_exists(): + print_error("Please install pacman") exit() if geteuid() != 0: print_error("Please run as root") diff --git a/asinstaller/install.py b/asinstaller/install.py index bc64d24..6934ba8 100644 --- a/asinstaller/install.py +++ b/asinstaller/install.py @@ -5,6 +5,7 @@ import time import shutil import os +import sys logger = get_logger(__name__) @@ -143,37 +144,45 @@ def initramfs(): def grub(): - logger.debug("Installing GRUB") - system("clear") - print_title("Setting up GRUB bootloader...") - time.sleep(1) + try: + logger.debug("Installing GRUB") + system("clear") + print_title("Setting up GRUB bootloader...") + time.sleep(1) - system("pacman -S grub --noconfirm", True) + system("pacman -S grub --noconfirm", True) - if system_output("cat /proc/cpuinfo | grep -m1 vendor_id |" - + "awk '{print $NF}'") == 'GenuineIntel': - if query_yes_no('We have detected you have an Intel CPU. ' - + 'Is that correct?', 'yes'): - system("pacman -S intel-ucode --noconfirm", True) + if system_output("cat /proc/cpuinfo | grep -m1 vendor_id |" + + "awk '{print $NF}'") == 'GenuineIntel': + if query_yes_no('We have detected you have an Intel CPU. ' + + 'Is that correct?', 'yes'): + system("pacman -S intel-ucode --noconfirm", True) - if usr_cfg['partition_type'] == '2': - system("sed -i 's!quiet!cryptdevice=/dev/lvm/lvroot:root " - + "root=/dev/mapper/root!' /mnt/etc/default/grub") - else: - system("sed -i 's/quiet//' /mnt/etc/default/grub") - - if usr_cfg['uefi']: - system('grub-install --efi-directory=/boot --target=x86_64-efi ' - + '--bootloader-id=boot', True) - system('mv /mnt/boot/EFI/boot/grubx64.efi ' - + '/mnt/boot/EFI/boot/bootx64.efi') + if usr_cfg['partition_type'] == '2': + system("sed -i 's!quiet!cryptdevice=/dev/lvm/lvroot:root " + + "root=/dev/mapper/root!' /mnt/etc/default/grub") + else: + system("sed -i 's/quiet//' /mnt/etc/default/grub") - if usr_cfg['partition_type'] != '2': - system(f"mkinitcpio -p {usr_cfg['kernel']}", True) - else: - system("grub-install {0}".format(usr_cfg['drive']), True) + if usr_cfg['uefi']: + system('grub-install --efi-directory=/boot --target=x86_64-efi ' + + '--bootloader-id=boot', True) + system('mv /mnt/boot/EFI/boot/grubx64.efi ' + + '/mnt/boot/EFI/boot/bootx64.efi') - system("grub-mkconfig -o /boot/grub/grub.cfg ", True) + if usr_cfg['partition_type'] != '2': + system(f"mkinitcpio -p {usr_cfg['kernel']}", True) + else: + system("grub-install {0}".format(usr_cfg['drive']), True) + + system("grub-mkconfig -o /boot/grub/grub.cfg ", True) + except Exception: + if usr_cfg['partition_type'] == '3': + logger.exception("Grub install failed") + print_error("Failed to install grub most likely due to user error during manual partitioning...") + sys.exit(1) + else: + raise # TODO: Implement diff --git a/asinstaller/utils.py b/asinstaller/utils.py index 176585b..4cd8bda 100644 --- a/asinstaller/utils.py +++ b/asinstaller/utils.py @@ -240,13 +240,10 @@ def internet_enabled(): return True -def is_arch_linux(): +def pacman_exists(): try: - logger.debug(f"Checking that os release is Arch Linux") - os_release_path = Path("/etc/os-release") - with os_release_path.open() as fhandle: - fcontent = fhandle.read() - return 'Arch Linux' in fcontent + logger.debug(f"Checking for pacman") + return system("pacman -V") == 0 except Exception: return False @@ -267,8 +264,8 @@ def set_keymap(): print_info("Setting your keyboard layout now, default is US.") layout = 'us' + font = None if query_yes_no("> Would you like to change the keyboard layout? ", 'no'): - print(system_output("find /usr/share/X11/xkb/symbols -type f | awk -F '/' '{print $NF}' | sort | uniq""")) layout = None keymaps_path = Path('/usr/share/kbd/keymaps/') while layout is None: @@ -277,7 +274,9 @@ def set_keymap(): layout = _layout break if layout is None: - print_error(f"Keymap was not found {keymaps_path}/**/{_layout}.map.gz") + for p in keymaps_path.glob(f'**/*.map.gz'): + print_info(p.stem.rstrip('.map.gz')) + print_error(f"Keymap {_layout} was not found. Try one of the above...") elif query_yes_no(f'>Setting "{layout}" as your keymap, is that correct? ', 'yes'): system(f"loadkeys {layout}") else: @@ -286,7 +285,6 @@ def set_keymap(): system('showconsolefont --verbose') consolefonts_path = Path('/usr/share/kbd/consolefonts/') font_prompt = '> Would you like to change the console font?' - font = None if query_yes_no(font_prompt, 'no'): while font is None: _font = input("> Enter your console font: ") @@ -294,7 +292,9 @@ def set_keymap(): if consolefonts_path.joinpath(_file).exists(): font = _font else: - print_error(f"Font not found: {consolefonts_path}/{_file}") + for p in consolefonts_path.glob(f'*.psfu.gz'): + print_info(p.stem.rstrip('.psfu.gz')) + print_error(f"Font {_file.rstrip('.psfu.gz')} not found. Try one of the above...") system(f'setfont {font}') usr_cfg['keymap'] = layout usr_cfg['font'] = font