]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Do not fail when writing root password and /etc/shadow is missing
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Apr 2023 09:41:42 +0000 (11:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 17 Apr 2023 09:48:48 +0000 (11:48 +0200)
I had this failure when testing https://github.com/systemd/mkosi/pull/1442. But
it would happen whenever the installed system has no /etc/shadow and we want to
set the password, so it's worth fixing regardless.

mkosi/__init__.py

index 7d1dd4f3a95fad5022cf535abeef7a472bb4f9bf..37cb834fc370db323a16cd15282dc5da3f08cd3e 100644 (file)
@@ -362,7 +362,11 @@ def configure_root_password(state: MkosiState) -> None:
                     return ":".join(["root", password] + line.split(":")[2:])
                 return line
 
-            patch_file(state.root / "etc/shadow", set_root_pw)
+            shadow = state.root / "etc/shadow"
+            try:
+                patch_file(shadow, set_root_pw)
+            except FileNotFoundError:
+                shadow.write_text(f"root:{password}:0:0:99999:7:::")
 
 
 def configure_autologin(state: MkosiState) -> None: