From 40a1498c6f3a89a07c862767499124ac9931797d Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sun, 5 Jan 2025 04:48:28 +0100 Subject: [PATCH] root pw + min --- installs/full.toml | 3 +++ installs/min.toml | 38 ++++++++++++++++++++++++++++++++++++++ src/config.rs | 8 +++++--- src/install/first_boot.rs | 6 +++++- src/install/mod.rs | 6 +++--- src/install/user.rs | 10 +++++----- src/print.rs | 16 +++++++++++++--- 7 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 installs/min.toml diff --git a/installs/full.toml b/installs/full.toml index 370e634..42e8a1f 100644 --- a/installs/full.toml +++ b/installs/full.toml @@ -30,6 +30,9 @@ timezone = "Europe/Berlin" # Hostname hostname = "navos" +# Root password +root_password = "root" + [pkg] # Additional packages pkg = [ diff --git a/installs/min.toml b/installs/min.toml new file mode 100644 index 0000000..e2185ab --- /dev/null +++ b/installs/min.toml @@ -0,0 +1,38 @@ +# Minimal Install Template + +# Drive Selection for Install +[drive] +# Device node for the EFI boot filesystem +boot = "/dev/null" + +# Device node for the root filesystem +root = "/dev/null" + +# Root filesystem encryption passphrase +# If this option is set the root filesystem will be encrypted with LUKS +encryption = "password" + +# General configuration +[general] +# Preset +mode = "Base" + +# System Locale +locale = "de_DE.UTF-8" + +# Keymap +keyboard_layout = "de" +keyboard_variant = "mac" + +# Timezone +timezone = "Europe/Berlin" + +# Hostname +hostname = "navos_min" + +# Root password +root_password = "root" + +[pkg] +# Additional packages +pkg = [] diff --git a/src/config.rs b/src/config.rs index cc093c5..710fffd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,7 +12,7 @@ pub struct InstallConfig { /// Package Configuration pub pkg: PackageConfig, /// User Configuration - pub user: Vec, + pub user: Option>, /// SSH Configuration pub ssh: Option, /// Ollama AI Config @@ -49,9 +49,9 @@ pub struct PackageConfig { /// Packages to install pub pkg: Vec, /// Enable libvirt - pub virtualization: bool, + pub virtualization: Option, /// Enable docker - pub docker: bool, + pub docker: Option, } #[derive(Debug, Deserialize)] @@ -78,6 +78,8 @@ pub struct GeneralConfig { pub timezone: String, /// Hostname pub hostname: String, + // Root password + pub root_password: Option, } #[derive(Debug, Deserialize)] diff --git a/src/install/first_boot.rs b/src/install/first_boot.rs index 4cb450f..93dcf4f 100644 --- a/src/install/first_boot.rs +++ b/src/install/first_boot.rs @@ -6,7 +6,7 @@ use crate::{ print_status, }; -use super::uncomment_first_value_of; +use super::{uncomment_first_value_of, user::change_passwd}; /// Generate the `/etc/fstab` file pub fn genfstab() { @@ -51,6 +51,10 @@ pub fn first_boot_values(conf: &GeneralConfig) { arch_chroot(&["hwclock", "--systohc"], None, false); + if let Some(root_pw) = &conf.root_password { + change_passwd("root", root_pw); + } + systemd_service_enable("NetworkManager.service"); } diff --git a/src/install/mod.rs b/src/install/mod.rs index e9f0fc6..a197d79 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -88,7 +88,7 @@ pub fn install(conf: InstallConfig) { // System Setup first_boot_values(&conf.general); setup_skel(&conf.general); - setup_users(&conf.user); + setup_users(&conf.user.unwrap_or_default()); setup_ssh(conf.ssh); @@ -118,11 +118,11 @@ pub fn install(conf: InstallConfig) { } } - if conf.pkg.virtualization { + if conf.pkg.virtualization.unwrap_or_default() { // TODO : Enable virtualization } - if conf.pkg.docker { + if conf.pkg.docker.unwrap_or_default() { // TODO : Enable docker } diff --git a/src/install/user.rs b/src/install/user.rs index 0152dd9..de8c82c 100644 --- a/src/install/user.rs +++ b/src/install/user.rs @@ -4,6 +4,10 @@ use crate::{ print_status, }; +pub fn change_passwd(user: &str, pw: &str) { + arch_chroot(&["passwd", user], Some(&format!("{}\n{}\n", pw, pw)), false); +} + /// Setup the users of the system pub fn setup_users(conf: &[UserConfig]) { let mut doas_conf = String::new(); @@ -11,11 +15,7 @@ pub fn setup_users(conf: &[UserConfig]) { for user in conf { arch_chroot(&["useradd", "-m", &user.name], None, false); - arch_chroot( - &["passwd", &user.name], - Some(&format!("{}\n{}\n", user.password, user.password)), - false, - ); + change_passwd(&user.name, &user.password); if user.doas_root { print_status(&format!("Allowing root doas for {}", user.name)); diff --git a/src/print.rs b/src/print.rs index e8d066f..b8b3594 100644 --- a/src/print.rs +++ b/src/print.rs @@ -57,16 +57,23 @@ pub fn print_config(conf: &InstallConfig) { "Timezone:".paint(Color::Yellow), conf.general.timezone )); + if conf.general.root_password.is_some() { + general_info.add_str(format!( + "🔑 {} {}", + "Root Password".paint(Color::Yellow), + "✔️".paint(Color::Green) + )); + } root_info.add_tree("🔨 General", general_info); let mut pkg_info = Tree::new(); - if conf.pkg.docker { + if conf.pkg.docker.unwrap_or_default() { pkg_info.add_str(format!("🐳 Docker {}", "✔️".paint(Color::Green))); } - if conf.pkg.virtualization { + if conf.pkg.virtualization.unwrap_or_default() { pkg_info.add_str(format!("🎃 Virtualization {}", "✔️".paint(Color::Green))); } @@ -81,7 +88,10 @@ pub fn print_config(conf: &InstallConfig) { let mut users_info = Tree::new(); - for user in &conf.user { + let empty = Vec::new(); + let user_conf = conf.user.as_ref().unwrap_or(&empty); + + for user in user_conf { users_info.add_str(format!( "👤 {} {}", user.name,