diff --git a/installs/testinstall.toml b/installs/testinstall.toml index fa67907..f227e54 100644 --- a/installs/testinstall.toml +++ b/installs/testinstall.toml @@ -34,3 +34,13 @@ virtualization = true # Enable docker docker = true + +[[user]] +# Username +name = "testuser" + +# User password +password = "testpass" + +# Allow user to use doas as root +doas_root= true diff --git a/src/config.rs b/src/config.rs index 6259a32..e733334 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,16 @@ pub struct InstallConfig { /// General Configuration pub general: GeneralConfig, /// Package Configuration - pub pkg: PackageConfig + pub pkg: PackageConfig, + /// User Configuration + pub user: Vec, +} + +#[derive(Debug, Deserialize)] +pub struct UserConfig { + pub name: String, + pub password: String, + pub doas_root: bool, } #[derive(Debug, Deserialize)] diff --git a/src/install.rs b/src/install.rs index bd4f92b..e439ab3 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,4 +1,3 @@ -// TODO : Setup users // TODO : Setup ssh (config + authorized_keys) // TODO : Setup virtualization // TODO : Setup docker @@ -8,8 +7,9 @@ // DRIVE SELECTION use crate::{ - config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig}, - pkg, pkg::install_pkgs, run_command, + config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig, UserConfig}, + pkg::{self, install_pkgs}, + run_command, }; pub fn str_vec(v: Vec<&str>) -> Vec { @@ -81,6 +81,7 @@ pub fn pacstrap(conf: &PackageConfig) { "git".into(), "networkmanager".into(), "nano".into(), + "doas".into(), ]; cmd.extend(conf.pkg.clone()); @@ -312,6 +313,30 @@ pub fn setup_bootloader() { ); } +pub fn setup_users(conf: &[UserConfig]) { + let mut doas_conf = String::new(); + + for user in conf { + run_command( + &str_vec(vec!["arch-chroot", "/mnt", "useradd", "-m", &user.name]), + None, + false, + ); + + run_command( + &str_vec(vec!["arch-chroot", "/mnt", "passwd", &user.name]), + Some(&format!("{}\n{}\n", user.password, user.password)), + false, + ); + + if user.doas_root { + doas_conf.push_str(&format!("permit {} as root\n", user.name)); + } + } + + std::fs::write("/mnt/etc/doas.conf", doas_conf).unwrap(); +} + pub fn install(conf: InstallConfig) { // Drive Setup format_drives(&conf.drive, conf.general.encryption); @@ -323,6 +348,8 @@ pub fn install(conf: InstallConfig) { // System Setup first_boot_values(&conf.general); + setup_users(&conf.user); + setup_bootloader(); match conf.general.mode { diff --git a/src/pkg.rs b/src/pkg.rs index 8c94148..73f2e84 100644 --- a/src/pkg.rs +++ b/src/pkg.rs @@ -11,4 +11,4 @@ pub fn install_pkgs(pkg: &[&str]) { cmd.extend_from_slice(pkg); run_command(&str_vec(cmd), None, true); -} \ No newline at end of file +}