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
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
pub general: GeneralConfig,
/// 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)]

View file

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