From 73a30e4576479ab7b8c93037c9dd893dc13f0767 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 28 Dec 2024 00:33:50 +0100 Subject: [PATCH 1/2] update --- installs/testinstall.toml | 15 ++++++++++++ src/config.rs | 18 +++++++++----- src/install.rs | 49 ++++++++------------------------------- src/pkg.rs | 11 +++++++++ 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/installs/testinstall.toml b/installs/testinstall.toml index 266262f..fa67907 100644 --- a/installs/testinstall.toml +++ b/installs/testinstall.toml @@ -6,16 +6,31 @@ root = "/dev/null" [general] # Use LUKS encryption on root drive encryption = true + # Preset mode = "Desktop" + # System Locale locale = "de_DE.UTF-8" + +# Keymap +keymap = "de-latin1" + +# Timezone +timezone = "Europe/Berlin" + +# Hostname +hostname = "navos" + +[pkg] # Additional packages pkg = [ "nano", "micro" ] + # Enable virtualization virtualization = true + # Enable docker docker = true diff --git a/src/config.rs b/src/config.rs index 39e01e1..6259a32 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,6 +7,18 @@ pub struct InstallConfig { pub drive: DriveConfig, /// General Configuration pub general: GeneralConfig, + /// Package Configuration + pub pkg: PackageConfig +} + +#[derive(Debug, Deserialize)] +pub struct PackageConfig { + /// Packages to install + pub pkg: Vec, + /// Enable libvirt + pub virtualization: bool, + /// Enable docker + pub docker: bool, } #[derive(Debug, Deserialize)] @@ -31,12 +43,6 @@ pub struct GeneralConfig { pub timezone: String, /// Hostname pub hostname: String, - /// Packages to install - pub pkg: Vec, - /// Enable libvirt - pub virtualization: bool, - /// Enable docker - pub docker: bool, } #[derive(Debug, Deserialize)] diff --git a/src/install.rs b/src/install.rs index bc75d78..bd4f92b 100644 --- a/src/install.rs +++ b/src/install.rs @@ -2,12 +2,14 @@ // TODO : Setup ssh (config + authorized_keys) // TODO : Setup virtualization // TODO : Setup docker +// TODO : Autojoin docker swarm +// TODO : Autojoin teleport // DRIVE SELECTION use crate::{ - config::{DriveConfig, GeneralConfig, InstallConfig}, - pkg, run_command, + config::{DriveConfig, GeneralConfig, InstallConfig, PackageConfig}, + pkg, pkg::install_pkgs, run_command, }; pub fn str_vec(v: Vec<&str>) -> Vec { @@ -67,7 +69,7 @@ pub fn mount_drives(conf: &DriveConfig, encrypted: bool) { // PACSTRAP -pub fn pacstrap(conf: &GeneralConfig) { +pub fn pacstrap(conf: &PackageConfig) { let mut cmd: Vec = vec![ "pacstrap".into(), "-K".into(), @@ -157,18 +159,7 @@ pub fn uncomment_first_value_of(value: &str, file: &str) { } pub fn setup_zram() { - run_command( - &str_vec(vec![ - "arch-chroot", - "/mnt", - "pacman", - "-Syu", - "--noconfirm", - "zram-generator", - ]), - None, - false, - ); + install_pkgs(&["zram-generator"]); std::fs::write( "/mnt/etc/systemd/zram-generator.conf", include_str!("root/zram-generator.conf"), @@ -282,18 +273,7 @@ pub fn setup_secure_boot() { // TPM Unlock pub fn setup_tpm_unlock(conf: &DriveConfig) { - run_command( - &str_vec(vec![ - "arch-chroot", - "/mnt", - "pacman", - "-Syu", - "--noconfirm", - "tpm2-tools", - ]), - None, - false, - ); + install_pkgs(&["tpm2-tools"]); // systemd-cryptenroll --tpm2-device=list @@ -324,15 +304,6 @@ pub fn setup_tpm_unlock(conf: &DriveConfig) { ); } -pub fn install_pkgs(pkg: &[&str]) { - let mut cmd = vec!["arch-chroot", "/mnt", "pacman", "-Syu"]; - - cmd.extend_from_slice(pkg); - cmd.push("--noconfirm"); - - run_command(&str_vec(cmd), None, true); -} - pub fn setup_bootloader() { run_command( &str_vec(vec!["arch-chroot", "/mnt", "bootctl", "install"]), @@ -347,7 +318,7 @@ pub fn install(conf: InstallConfig) { mount_drives(&conf.drive, conf.general.encryption); // Base Install - pacstrap(&conf.general); + pacstrap(&conf.pkg); genfstab(); // System Setup @@ -367,11 +338,11 @@ pub fn install(conf: InstallConfig) { } } - if conf.general.virtualization { + if conf.pkg.virtualization { // TODO : Enable virtualization } - if conf.general.docker { + if conf.pkg.docker { // TODO : Enable docker } diff --git a/src/pkg.rs b/src/pkg.rs index aa20e47..8c94148 100644 --- a/src/pkg.rs +++ b/src/pkg.rs @@ -1,3 +1,14 @@ +use crate::{install::str_vec, run_command}; + pub const DESKTOP_PKG: [&str; 2] = ["plasma", "sddm"]; pub const SERVER_PKG: [&str; 1] = ["tmux"]; + +pub fn install_pkgs(pkg: &[&str]) { + let mut cmd = vec!["arch-chroot", "/mnt", "pacman", "-Syu"]; + + cmd.push("--noconfirm"); + cmd.extend_from_slice(pkg); + + run_command(&str_vec(cmd), None, true); +} \ No newline at end of file From eabd898ccf20e94beeebc5775be11d7398d2e5d1 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 28 Dec 2024 00:41:57 +0100 Subject: [PATCH 2/2] Added user configuration support to installer --- installs/testinstall.toml | 10 ++++++++++ src/config.rs | 11 ++++++++++- src/install.rs | 33 ++++++++++++++++++++++++++++++--- src/pkg.rs | 2 +- 4 files changed, 51 insertions(+), 5 deletions(-) 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 +}