Added user configuration support to installer

This commit is contained in:
JMARyA 2024-12-28 00:41:57 +01:00
parent 73a30e4576
commit eabd898ccf
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 51 additions and 5 deletions

View file

@ -34,3 +34,13 @@ virtualization = true
# Enable docker # Enable docker
docker = true docker = true
[[user]]
# Username
name = "testuser"
# User password
password = "testpass"
# Allow user to use doas as root
doas_root= true

View file

@ -8,7 +8,16 @@ pub struct InstallConfig {
/// General Configuration /// General Configuration
pub general: GeneralConfig, pub general: GeneralConfig,
/// Package Configuration /// Package Configuration
pub pkg: PackageConfig pub pkg: PackageConfig,
/// User Configuration
pub user: Vec<UserConfig>,
}
#[derive(Debug, Deserialize)]
pub struct UserConfig {
pub name: String,
pub password: String,
pub doas_root: bool,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View file

@ -1,4 +1,3 @@
// TODO : Setup users
// TODO : Setup ssh (config + authorized_keys) // TODO : Setup ssh (config + authorized_keys)
// TODO : Setup virtualization // TODO : Setup virtualization
// TODO : Setup docker // TODO : Setup docker
@ -8,8 +7,9 @@
// DRIVE SELECTION // DRIVE SELECTION
use crate::{ use crate::{
config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig}, config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig, UserConfig},
pkg, pkg::install_pkgs, run_command, pkg::{self, install_pkgs},
run_command,
}; };
pub fn str_vec(v: Vec<&str>) -> Vec<String> { pub fn str_vec(v: Vec<&str>) -> Vec<String> {
@ -81,6 +81,7 @@ pub fn pacstrap(conf: &PackageConfig) {
"git".into(), "git".into(),
"networkmanager".into(), "networkmanager".into(),
"nano".into(), "nano".into(),
"doas".into(),
]; ];
cmd.extend(conf.pkg.clone()); 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) { pub fn install(conf: InstallConfig) {
// Drive Setup // Drive Setup
format_drives(&conf.drive, conf.general.encryption); format_drives(&conf.drive, conf.general.encryption);
@ -323,6 +348,8 @@ pub fn install(conf: InstallConfig) {
// System Setup // System Setup
first_boot_values(&conf.general); first_boot_values(&conf.general);
setup_users(&conf.user);
setup_bootloader(); setup_bootloader();
match conf.general.mode { match conf.general.mode {

View file

@ -11,4 +11,4 @@ pub fn install_pkgs(pkg: &[&str]) {
cmd.extend_from_slice(pkg); cmd.extend_from_slice(pkg);
run_command(&str_vec(cmd), None, true); run_command(&str_vec(cmd), None, true);
} }