]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
passwords: Implement setting the root password
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Mar 2025 16:00:47 +0000 (16:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Mar 2025 16:00:47 +0000 (16:00 +0000)
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 <michael.tremer@ipfire.org>
src/python/step.py

index d3403c90afdfae0148c55b51368f1f1cfa31d78b..557e15b756e7a540ac3c2b380df280b498c6ca24 100644 (file)
@@ -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):