use crate::{ config::UserConfig, linux::{arch_chroot, install_file}, pkg::install_pkgs, print_status, }; pub fn change_passwd(user: &str, pw: &str) { arch_chroot(&["passwd", user], Some(&format!("{}\n{}\n", pw, pw)), false); } /// Setup the users of the system pub fn setup_users(conf: &[UserConfig]) { if !conf.is_empty() { install_pkgs(&["doas"]); install_file("/mnt/etc/doas.conf", "permit persist :wheel as root", 0o644); } for user in conf { let mut cmd = vec!["useradd"]; if let Some(home_dir) = &user.home_dir { if home_dir.is_empty() { cmd.push("-M"); } else { cmd.push("-m"); cmd.push("-d"); cmd.push(home_dir); } } else { cmd.push("-m"); } let uid = user.uid.map(|x| x.to_string()); if let Some(uid) = &uid { cmd.push("-u"); cmd.push(uid); } if let Some(shell) = &user.shell { cmd.push("-s"); cmd.push(shell); } cmd.push(&user.name); arch_chroot(&cmd, None, false); change_passwd(&user.name, &user.password); if user.wheel.unwrap_or_default() { print_status(&format!("Adding {} to wheel", user.name)); arch_chroot( &vec!["usermod", "-a", "-G", "wheel", user.name.as_str()], None, false, ); } } }