From: Michael Tremer Date: Tue, 25 Mar 2025 16:00:47 +0000 (+0000) Subject: passwords: Implement setting the root password X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=967d4130b26a2f56bfe3003ad2c28eba50dc0e82;p=people%2Fms%2Fbricklayer.git passwords: Implement setting the root password This step can now be built out as we have the execute() call back which supports passing data into standard input. This step is also only executed in an interactive setup where we asked for the password before. Signed-off-by: Michael Tremer --- diff --git a/src/python/step.py b/src/python/step.py index d3403c9..557e15b 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -212,15 +212,30 @@ class RootPassword(InteractiveStep): self.bricklayer.settings["root-password"] = password -class SetRootPassword(Step): +class SetRootPassword(InteractiveStep): + first_install = True + def run(self): with self.tui.progress(_("Applying Configuration"), - _("Setting password for the '%s' user...")) as t: + _("Setting password for the 'root' user...")) as t: + # Fetch the password + password = self.bricklayer.settings.get("root-password") + + # Fail if no password has been set + if not password: + raise ValueError("No password has been set") + + # Encode the password + password = password.encode() + + # Send the password twice + input = b"%s\n%s\n" % (password, password) + + # Setup Pakfire p = self.bricklayer.setup_pakfire() - # XXX execute currently has no way to write to stdin, which is - # why we reset the root password here, so that we will have a working login - p.execute(["passwd", "--delete", "root"]) + # Set the password + p.execute(["passwd", "root"], input=input) class ToggleFirstInstallStatus(Step):