diff --git a/installs/testinstall.toml b/installs/testinstall.toml index f227e54..266262f 100644 --- a/installs/testinstall.toml +++ b/installs/testinstall.toml @@ -6,41 +6,16 @@ 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 - -[[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 e733334..39e01e1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,27 +7,6 @@ pub struct InstallConfig { pub drive: DriveConfig, /// General Configuration pub general: GeneralConfig, - /// Package Configuration - 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)] -pub struct PackageConfig { - /// Packages to install - pub pkg: Vec, - /// Enable libvirt - pub virtualization: bool, - /// Enable docker - pub docker: bool, } #[derive(Debug, Deserialize)] @@ -52,6 +31,12 @@ 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 e439ab3..bc75d78 100644 --- a/src/install.rs +++ b/src/install.rs @@ -1,15 +1,13 @@ +// TODO : Setup users // 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, PackageConfig, UserConfig}, - pkg::{self, install_pkgs}, - run_command, + config::{DriveConfig, GeneralConfig, InstallConfig}, + pkg, run_command, }; pub fn str_vec(v: Vec<&str>) -> Vec { @@ -69,7 +67,7 @@ pub fn mount_drives(conf: &DriveConfig, encrypted: bool) { // PACSTRAP -pub fn pacstrap(conf: &PackageConfig) { +pub fn pacstrap(conf: &GeneralConfig) { let mut cmd: Vec = vec![ "pacstrap".into(), "-K".into(), @@ -81,7 +79,6 @@ pub fn pacstrap(conf: &PackageConfig) { "git".into(), "networkmanager".into(), "nano".into(), - "doas".into(), ]; cmd.extend(conf.pkg.clone()); @@ -160,7 +157,18 @@ pub fn uncomment_first_value_of(value: &str, file: &str) { } pub fn setup_zram() { - install_pkgs(&["zram-generator"]); + run_command( + &str_vec(vec![ + "arch-chroot", + "/mnt", + "pacman", + "-Syu", + "--noconfirm", + "zram-generator", + ]), + None, + false, + ); std::fs::write( "/mnt/etc/systemd/zram-generator.conf", include_str!("root/zram-generator.conf"), @@ -274,7 +282,18 @@ pub fn setup_secure_boot() { // TPM Unlock pub fn setup_tpm_unlock(conf: &DriveConfig) { - install_pkgs(&["tpm2-tools"]); + run_command( + &str_vec(vec![ + "arch-chroot", + "/mnt", + "pacman", + "-Syu", + "--noconfirm", + "tpm2-tools", + ]), + None, + false, + ); // systemd-cryptenroll --tpm2-device=list @@ -305,6 +324,15 @@ 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"]), @@ -313,43 +341,17 @@ 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); mount_drives(&conf.drive, conf.general.encryption); // Base Install - pacstrap(&conf.pkg); + pacstrap(&conf.general); genfstab(); // System Setup first_boot_values(&conf.general); - setup_users(&conf.user); - setup_bootloader(); match conf.general.mode { @@ -365,11 +367,11 @@ pub fn install(conf: InstallConfig) { } } - if conf.pkg.virtualization { + if conf.general.virtualization { // TODO : Enable virtualization } - if conf.pkg.docker { + if conf.general.docker { // TODO : Enable docker } diff --git a/src/pkg.rs b/src/pkg.rs index 73f2e84..aa20e47 100644 --- a/src/pkg.rs +++ b/src/pkg.rs @@ -1,14 +1,3 @@ -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); -}