summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/ukify.xml7
-rwxr-xr-xsrc/ukify/ukify.py24
2 files changed, 28 insertions, 3 deletions
diff --git a/man/ukify.xml b/man/ukify.xml
index 0a9cd5ee38..3ee1306c6c 100644
--- a/man/ukify.xml
+++ b/man/ukify.xml
@@ -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
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index b7e21dafed..890a694e68 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -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