]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
ukify/man: Look for a config file in systemd folders if not specified
authorAlvin Alvarado <alvin@striczkof.io>
Fri, 8 Sep 2023 04:02:52 +0000 (14:02 +1000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 8 Sep 2023 14:21:28 +0000 (16:21 +0200)
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!

man/ukify.xml
src/ukify/ukify.py

index 0a9cd5ee38f9658acf6550199aaf29e05d95b875..3ee1306c6cb1dd87796a69e782411f052cc17e59 100644 (file)
     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
index b7e21dafed7b5550846178ba66b705ababa58133..890a694e685fca7b1c773c4c1ce49cbe8969ac62 100755 (executable)
@@ -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