From: Zbigniew Jędrzejewski-Szmek Date: Mon, 17 Apr 2023 09:41:42 +0000 (+0200) Subject: Do not fail when writing root password and /etc/shadow is missing X-Git-Tag: v15~247^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f3e619a0fe4a22c517e2ebaeab68402df2f4f0d;p=thirdparty%2Fmkosi.git Do not fail when writing root password and /etc/shadow is missing 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 7d1dd4f3a..37cb834fc 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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: