added new user options

This commit is contained in:
JMARyA 2025-01-08 09:02:04 +01:00
parent ffbc2e5e72
commit 26cd7c264c
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 43 additions and 1 deletions

View file

@ -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

View file

@ -41,6 +41,9 @@ pub struct SSHKey {
pub struct UserConfig {
pub name: String,
pub password: String,
pub uid: Option<u32>,
pub home_dir: Option<String>,
pub shell: Option<String>,
pub doas_root: Option<bool>,
pub docker: Option<bool>,
pub virtualization: Option<bool>,

View file

@ -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);