1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-26 03:22:00 +03:00

kernel-install/60-ukify: add helper function for locating input files

Also rename config_file_location() to uki_conf_location() to make
it obvious which config file was meant.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-10-10 18:53:55 +02:00
parent 7a9d86bceb
commit 40c0c9d4bc

View File

@ -124,27 +124,35 @@ def we_are_wanted() -> bool:
return True
def config_file_location() -> Optional[Path]:
def input_file_location(
filename: str,
*search_directories: str) -> Optional[Path]:
if root := os.getenv('KERNEL_INSTALL_CONF_ROOT'):
p = Path(root) / 'uki.conf'
else:
p = Path('/etc/kernel/uki.conf')
if p.exists():
return p
search_directories = (root,)
elif not search_directories:
# This is the default search path.
search_directories = ('/etc/kernel',
'/usr/lib/kernel')
for dir in search_directories:
p = Path(dir) / filename
if p.exists():
return p
return None
def uki_conf_location() -> Optional[Path]:
return input_file_location('uki.conf',
'/etc/kernel')
def kernel_cmdline_base() -> list[str]:
if root := os.getenv('KERNEL_INSTALL_CONF_ROOT'):
return Path(root).joinpath('cmdline').read_text().split()
for cmdline in ('/etc/kernel/cmdline',
'/usr/lib/kernel/cmdline'):
try:
return Path(cmdline).read_text().split()
except FileNotFoundError:
continue
path = input_file_location('cmdline')
if path:
return path.read_text().split()
# If we read /proc/cmdline, we need to do some additional filtering.
options = Path('/proc/cmdline').read_text().split()
return [opt for opt in options
if not opt.startswith(('BOOT_IMAGE=', 'initrd='))]
@ -193,7 +201,7 @@ def call_ukify(opts):
# argument set to prepopulate the namespace with the defaults.
opts2 = ukify['create_parser']().parse_args(['build'])
opts2.config = config_file_location()
opts2.config = uki_conf_location()
opts2.uname = opts.kernel_version
opts2.linux = opts.kernel_image
opts2.initrd = initrd_list(opts)