]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Inline autologin resources
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 19 Sep 2023 11:59:14 +0000 (13:59 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 19 Sep 2023 12:22:52 +0000 (14:22 +0200)
When using a packaged mkosi with its resources in /usr, using a
tools tree breaks setting up autologin as the resources can't be loaded
anymore after mounting the tools tree. Let's fix the problem by inlining
the resources so they're immediately loaded. This isn't a problem
for the mkosi.md resource as it is never loaded after mounting a
tools tree.

NEWS.md
mkosi/__init__.py
mkosi/install.py [deleted file]
mkosi/resources/console_getty_autologin.conf [deleted file]
mkosi/resources/getty_autologin.conf [deleted file]
mkosi/resources/serial_getty_autologin.conf [deleted file]

diff --git a/NEWS.md b/NEWS.md
index a6009a9cce8c92993cd6af3aaa7977f7e89e1476..e93431d225ddeeda40a43415d244795dcb860766 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,10 @@
 # mkosi Changelog
 
+## v17.1
+
+- Fixed bug where `--autologin` was broken when used in combination with
+  a tools tree when using a packaged version of mkosi.
+
 ## v17
 
 - Added `ToolsTreePackages=` to add extra packages to the default tools
index c686902fd3b99b11d092674c972f460d951f0765..56fd11dfba71728bb8e2a269e8d7842f5fd59652 100644 (file)
@@ -38,7 +38,6 @@ from mkosi.config import (
     parse_config,
     summary,
 )
-from mkosi.install import add_dropin_config_from_resource
 from mkosi.installer import clean_package_manager_metadata, package_manager_scripts
 from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules
 from mkosi.log import ARG_DEBUG, complete_step, die, log_step
@@ -173,13 +172,47 @@ def configure_autologin(state: MkosiState) -> None:
         return
 
     with complete_step("Setting up autologin…"):
-        add_dropin_config_from_resource(state.root, "console-getty.service", "autologin",
-                                        "mkosi.resources", "console_getty_autologin.conf")
-        add_dropin_config_from_resource(state.root, "serial-getty@ttyS0.service", "autologin",
-                                        "mkosi.resources", "serial_getty_autologin.conf")
-        add_dropin_config_from_resource(state.root, "getty@tty1.service", "autologin",
-                                        "mkosi.resources", "getty_autologin.conf")
+        dropin = state.root / "usr/lib/systemd/system/console-getty.service.d/autologin.conf"
+        with umask(~0o755):
+            dropin.parent.mkdir(parents=True, exist_ok=True)
+        with umask(~0o644):
+            dropin.write_text(
+                """\
+                [Service]
+                ExecStart=
+                ExecStart=-/sbin/agetty -o '-f -p -- \\u' --autologin root --noclear --keep-baud console 115200,38400,9600 $TERM
+                StandardInput=tty
+                StandardOutput=tty
+                """
+            )
+
+        dropin = state.root / "usr/lib/systemd/system/getty@tty1.service.d/autologin.conf"
+        with umask(~0o755):
+            dropin.parent.mkdir(parents=True, exist_ok=True)
+        with umask(~0o644):
+            dropin.write_text(
+                """\
+                [Service]
+                ExecStart=
+                ExecStart=-/sbin/agetty -o '-f -p -- \\u' --autologin root --noclear - $TERM
+                StandardInput=tty
+                StandardOutput=tty
+                """
+            )
 
+        dropin = state.root / "usr/lib/systemd/system/serial-getty@ttyS0.service.d/autologin.conf"
+        with umask(~0o755):
+            dropin.parent.mkdir(parents=True, exist_ok=True)
+        with umask(~0o644):
+            dropin.write_text(
+                """\
+                [Service]
+                ExecStart=
+                ExecStart=-/sbin/agetty -o '-f -p -- \\u' --autologin root --keep-baud 115200,57600,38400,9600 - $TERM
+                StandardInput=tty
+                StandardOutput=tty
+                """
+            )
 
 
 @contextlib.contextmanager
diff --git a/mkosi/install.py b/mkosi/install.py
deleted file mode 100644 (file)
index 36a095d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-# SPDX-License-Identifier: LGPL-2.1+
-
-import importlib.resources
-from pathlib import Path
-
-from mkosi.util import make_executable, umask
-
-
-def write_resource(where: Path, resource: str, key: str, *, executable: bool = False) -> None:
-    text = importlib.resources.read_text(resource, key)
-    where.write_text(text)
-    if executable:
-        make_executable(where)
-
-
-def add_dropin_config_from_resource(
-    root: Path, unit: str, name: str, resource: str, key: str
-) -> None:
-    dropin = root / f"usr/lib/systemd/system/{unit}.d/{name}.conf"
-    with umask(~0o755):
-        dropin.parent.mkdir(parents=True, exist_ok=True)
-        write_resource(dropin, resource, key)
-
diff --git a/mkosi/resources/console_getty_autologin.conf b/mkosi/resources/console_getty_autologin.conf
deleted file mode 100644 (file)
index 1caa965..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Service]
-ExecStart=
-ExecStart=-/sbin/agetty -o '-f -p -- \\u' --autologin root --noclear --keep-baud console 115200,38400,9600 $TERM
-StandardInput=tty
-StandardOutput=tty
diff --git a/mkosi/resources/getty_autologin.conf b/mkosi/resources/getty_autologin.conf
deleted file mode 100644 (file)
index c00d288..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Service]
-ExecStart=
-ExecStart=-/sbin/agetty -o '-f -p -- \\u' --autologin root --noclear - $TERM
-StandardInput=tty
-StandardOutput=tty
diff --git a/mkosi/resources/serial_getty_autologin.conf b/mkosi/resources/serial_getty_autologin.conf
deleted file mode 100644 (file)
index 515ca11..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-[Service]
-ExecStart=
-ExecStart=-/sbin/agetty -o '-f -p -- \\u' --autologin root --keep-baud 115200,57600,38400,9600 - $TERM
-StandardInput=tty
-StandardOutput=tty