tonarchy

tonarchy

https://git.tonybtw.com/tonarchy.git git://git.tonybtw.com/tonarchy.git

Fixed issue 7 with simple chpasswd_pipe helper

Commit
dbcfd877438f9c49eb952dc8a4980dc537d8d4a3
Parent
d5ffc8e
Author
tonybanters <tonybanters@gmail.com>
Date
2026-01-26 21:40:26

Diff

diff --git a/src/tonarchy.c b/src/tonarchy.c
index 5eada4d..77135ff 100644
--- a/src/tonarchy.c
+++ b/src/tonarchy.c
@@ -1126,14 +1126,17 @@ static int configure_system_impl(
         "Failed to create user"
     );
 
+    FILE *chpasswd_pipe = popen("arch-chroot /mnt chpasswd 2>> /tmp/tonarchy-install.log", "w");
+    if (!chpasswd_pipe) {
+        show_message("Failed to open chpasswd");
+        return 0;
+    }
+    fprintf(chpasswd_pipe, "%s:%s\n", username, password);
+    fprintf(chpasswd_pipe, "root:%s\n", password);
+    int chpasswd_status = pclose(chpasswd_pipe);
     CHECK_OR_FAIL(
-        chroot_exec_fmt("echo '%s:%s' | chpasswd", username, password),
-        "Failed to set password"
-    );
-
-    CHECK_OR_FAIL(
-        chroot_exec_fmt("echo 'root:%s' | chpasswd", password),
-        "Failed to set root password"
+        chpasswd_status == 0,
+        "Failed to set passwords"
     );
 
     create_directory("/mnt/etc/sudoers.d", 0750);