From 6504feb66fca84b44c8905cc2f83e3e348c28cba Mon Sep 17 00:00:00 2001 From: Andrew Ammerlaan Date: Sat, 26 Oct 2024 14:41:39 +0200 Subject: [PATCH] bootloader: consider GRUB_CFG as location for grub config sys-kernel/installkernel[grub] supports setting GRUB_CFG in the environment to update a grub.cfg in a non-standard location. Specifically this is useful with sys-boot/grub[secureboot] where the built grub efi executable loads the grub.cfg from the same directory it is in. Recognize the same environment variable here so we don't accidentally update the wrong config. Signed-off-by: Andrew Ammerlaan --- ecleankernel/bootloader/grub.py | 6 +++++- ecleankernel/bootloader/grub2.py | 6 +++++- ecleankernel/bootloader/lilo.py | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ecleankernel/bootloader/grub.py b/ecleankernel/bootloader/grub.py index cc5f7c2..8e43ce2 100644 --- a/ecleankernel/bootloader/grub.py +++ b/ecleankernel/bootloader/grub.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import logging +import os import os.path import typing @@ -11,7 +12,10 @@ class GRUB(LILO): name = 'grub' kernel_re = r'^\s*(kernel|module)\s*(\([^)]+\))?(?P\S+)' - def_path = ('/boot/grub/menu.lst', '/boot/grub/grub.conf') + def_path = (os.environ.get("GRUB_CFG"), + '/boot/grub/menu.lst', + '/boot/grub/grub.conf', + ) def _get_kernels(self, content: str diff --git a/ecleankernel/bootloader/grub2.py b/ecleankernel/bootloader/grub2.py index 146cece..a2f9e82 100644 --- a/ecleankernel/bootloader/grub2.py +++ b/ecleankernel/bootloader/grub2.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import logging +import os import subprocess import typing @@ -17,7 +18,10 @@ class GRUB2(GRUB): name = 'grub2' kernel_re = r'^\s*linux\s*(\([^)]+\))?(?P\S+)' - def_path = ('/boot/grub/grub.cfg', '/boot/grub2/grub.cfg') + def_path = (os.environ.get("GRUB_CFG"), + '/boot/grub/grub.cfg', + '/boot/grub2/grub.cfg', + ) def __init__(self) -> None: super().__init__() diff --git a/ecleankernel/bootloader/lilo.py b/ecleankernel/bootloader/lilo.py index ff35b10..b8d1e4d 100644 --- a/ecleankernel/bootloader/lilo.py +++ b/ecleankernel/bootloader/lilo.py @@ -11,7 +11,7 @@ class LILO(Bootloader): name = 'lilo' kernel_re = r'^\s*image\s*=\s*(?P.+)\s*$' - def_path: typing.Tuple[str, ...] = ('/etc/lilo.conf',) + def_path: typing.Tuple[typing.Optional[str], ...] = ('/etc/lilo.conf',) def __init__(self, path: typing.Optional[str] = None @@ -23,6 +23,8 @@ def __init__(self, paths = (paths,) for p in paths: + if p is None: + continue try: with open(p) as f: logging.debug(f'{p} found')