From c67bb0b549b35ce335941c9c1cbe22f99c28f7fe Mon Sep 17 00:00:00 2001 From: codefiles <11915375+codefiles@users.noreply.github.com> Date: Sun, 16 Jul 2023 18:17:21 -0400 Subject: Refactor `_add_systemd_bootloader()` loader configuration (#1911) --- archinstall/lib/installer.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'archinstall/lib/installer.py') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 9582df77..02d48768 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -733,24 +733,26 @@ class Installer: # Modify or create a loader.conf loader_conf = loader_dir / 'loader.conf' + default = f'default {self.init_time}_{self.kernels[0]}.conf\n' + try: with loader_conf.open() as loader: - loader_data = loader.read().split('\n') + loader_data = loader.readlines() except FileNotFoundError: loader_data = [ - f"default {self.init_time}", - "timeout 15" + default, + 'timeout 15\n' ] + else: + for index, line in enumerate(loader_data): + if line.startswith('default'): + loader_data[index] = default + elif line.startswith('#timeout'): + # We add in the default timeout to support dual-boot + loader_data[index] = line.removeprefix('#') with loader_conf.open('w') as loader: - for line in loader_data: - if line[:8] == 'default ': - loader.write(f'default {self.init_time}_{self.kernels[0]}\n') - elif line[:8] == '#timeout' and 'timeout 15' not in loader_data: - # We add in the default timeout to support dual-boot - loader.write(f"{line[1:]}\n") - else: - loader.write(f"{line}\n") + loader.writelines(loader_data) # Ensure that the $BOOT/loader/entries/ directory exists before we try to create files in it entries_dir = loader_dir / 'entries' -- cgit v1.2.3-70-g09d2