diff --git a/installs/full.toml b/installs/full.toml index c138139..02e9c43 100644 --- a/installs/full.toml +++ b/installs/full.toml @@ -55,6 +55,17 @@ name = "u" # User password password = "pass" +# User ID +uid = 1001 + +# The home directory of the user +home_dir = "/home/u" +# You can leave the user without a home dir using: +# home_dir = "" + +# Set the shell of the user +shell = "/bin/bash" + # Allow user to use `doas` as root doas_root= true diff --git a/src/config.rs b/src/config.rs index 59531eb..4330d54 100644 --- a/src/config.rs +++ b/src/config.rs @@ -41,6 +41,9 @@ pub struct SSHKey { pub struct UserConfig { pub name: String, pub password: String, + pub uid: Option, + pub home_dir: Option, + pub shell: Option, pub doas_root: Option, pub docker: Option, pub virtualization: Option, diff --git a/src/install/user.rs b/src/install/user.rs index ad0ca32..25ed68f 100644 --- a/src/install/user.rs +++ b/src/install/user.rs @@ -13,7 +13,35 @@ pub fn setup_users(conf: &[UserConfig]) { let mut doas_conf = String::new(); for user in conf { - arch_chroot(&["useradd", "-m", &user.name], None, false); + 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);