added new user options
This commit is contained in:
parent
ffbc2e5e72
commit
26cd7c264c
3 changed files with 43 additions and 1 deletions
|
@ -55,6 +55,17 @@ name = "u"
|
||||||
# User password
|
# User password
|
||||||
password = "pass"
|
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
|
# Allow user to use `doas` as root
|
||||||
doas_root= true
|
doas_root= true
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ pub struct SSHKey {
|
||||||
pub struct UserConfig {
|
pub struct UserConfig {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
|
pub uid: Option<u32>,
|
||||||
|
pub home_dir: Option<String>,
|
||||||
|
pub shell: Option<String>,
|
||||||
pub doas_root: Option<bool>,
|
pub doas_root: Option<bool>,
|
||||||
pub docker: Option<bool>,
|
pub docker: Option<bool>,
|
||||||
pub virtualization: Option<bool>,
|
pub virtualization: Option<bool>,
|
||||||
|
|
|
@ -13,7 +13,35 @@ pub fn setup_users(conf: &[UserConfig]) {
|
||||||
let mut doas_conf = String::new();
|
let mut doas_conf = String::new();
|
||||||
|
|
||||||
for user in conf {
|
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);
|
change_passwd(&user.name, &user.password);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue