Skip to content

Commit

Permalink
Fixed default font traceback; added logic to prevent crash reporting …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
comrumino committed Dec 1, 2020
1 parent cc74b50 commit 63c76d7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
4 changes: 2 additions & 2 deletions asinstaller/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
61 changes: 35 additions & 26 deletions asinstaller/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import shutil
import os
import sys

logger = get_logger(__name__)

Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions asinstaller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -286,15 +285,16 @@ 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: ")
_file = f'{_font}.psfu.gz'
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
Expand Down

0 comments on commit 63c76d7

Please sign in to comment.