diff --git a/ecleankernel/bootloader/grub.py b/ecleankernel/bootloader/grub.py index cc5f7c2..9461ec4 100644 --- a/ecleankernel/bootloader/grub.py +++ b/ecleankernel/bootloader/grub.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later import logging -import os.path +import os import typing from ecleankernel.bootloader.lilo import LILO @@ -11,7 +11,7 @@ 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.getenv("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..609dea8 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,7 @@ 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.getenv("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..64ebdae 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.Union[str, None], ...] = ('/etc/lilo.conf',) def __init__(self, path: typing.Optional[str] = None @@ -23,14 +23,15 @@ def __init__(self, paths = (paths,) for p in paths: - try: - with open(p) as f: - logging.debug(f'{p} found') - self.path = p - self._content = f.read() - break - except FileNotFoundError: - pass + if p: + try: + with open(p) as f: + logging.debug(f'{p} found') + self.path = p + self._content = f.read() + break + except FileNotFoundError: + pass else: raise BootloaderNotFound()