From: Daan De Meyer Date: Tue, 19 Sep 2023 11:59:14 +0000 (+0200) Subject: Inline autologin resources X-Git-Tag: v17.1~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d41f3494a3d6ed222ac2127a62fdba7acd912ba0;p=thirdparty%2Fmkosi.git Inline autologin resources 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. --- diff --git a/NEWS.md b/NEWS.md index a6009a9cc..e93431d22 100644 --- 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 diff --git a/mkosi/__init__.py b/mkosi/__init__.py index c686902fd..56fd11dfb 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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 index 36a095d78..000000000 --- a/mkosi/install.py +++ /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 index 1caa96586..000000000 --- a/mkosi/resources/console_getty_autologin.conf +++ /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 index c00d2880b..000000000 --- a/mkosi/resources/getty_autologin.conf +++ /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 index 515ca1151..000000000 --- a/mkosi/resources/serial_getty_autologin.conf +++ /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