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

ukify/man: Look for a config file in systemd folders if not specified

If the user does not specify a config file to use, ukify will try looking for one at {/run,/etc,/usr/local/lib,/usr/lib}/systemd/ukify.conf in order and then use the first one found. Also made sure the --config input is a pathlib.Path by specifying its type in its CONFIG_ITEMS entry.
Big cheers to Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> for helping!
This commit is contained in:
Alvin Alvarado 2023-09-08 14:02:52 +10:00 committed by Zbigniew Jędrzejewski-Szmek
parent b8f18c3089
commit a05fa30f88
2 changed files with 28 additions and 3 deletions

View File

@ -155,6 +155,13 @@
priority and overwrites the config file setting completely. If some setting behaves differently, this is
described below.</para>
<para>If no config file is provided via the option <option>--config=<replaceable>PATH</replaceable></option>,
<command>ukify</command> will try to look for a default configuration file in the following paths in this
order: <filename>/run/systemd/ukify.conf</filename>, <filename>/etc/systemd/ukify.conf</filename>,
<filename>/usr/local/lib/systemd/ukify.conf</filename>, and <filename>/usr/lib/systemd/ukify.conf</filename>,
and then load the first one found. <command>ukify</command> will proceed normally if no configuration file
is specified and no default one is found.</para>
<para>The <replaceable>LINUX</replaceable> and <replaceable>INITRD</replaceable> positional arguments, or
the equivalent <varname>Linux=</varname> and <varname>Initrd=</varname> settings, are optional. If more
than one initrd is specified, they will all be combined into a single PE section. This is useful to, for

View File

@ -65,6 +65,11 @@ EFI_ARCH_MAP = {
}
EFI_ARCHES: list[str] = sum(EFI_ARCH_MAP.values(), [])
# Default configuration directories and file name.
# When the user does not specify one, the directories are searched in this order and the first file found is used.
DEFAULT_CONFIG_DIRS = ['/run/systemd', '/etc/systemd', '/usr/local/lib/systemd', '/usr/lib/systemd']
DEFAULT_CONFIG_FILE = 'ukify.conf'
def guess_efi_arch():
arch = os.uname().machine
@ -1176,6 +1181,7 @@ CONFIG_ITEMS = [
ConfigItem(
('--config', '-c'),
metavar = 'PATH',
type = pathlib.Path,
help = 'configuration file',
),
@ -1394,9 +1400,21 @@ CONFIGFILE_ITEMS = { item.config_key:item
def apply_config(namespace, filename=None):
if filename is None:
filename = namespace.config
if filename is None:
return
if namespace.config:
# Config set by the user, use that.
filename = namespace.config
print(f'Using config file: {filename}')
else:
# Try to look for a config file then use the first one found.
for config_dir in DEFAULT_CONFIG_DIRS:
filename = pathlib.Path(config_dir) / DEFAULT_CONFIG_FILE
if filename.is_file():
# Found a config file, use it.
print(f'Using found config file: {filename}')
break
else:
# No config file specified or found, nothing to do.
return
# Fill in ._groups based on --pcr-public-key=, --pcr-private-key=, and --phases=.
assert '_groups' not in namespace