// TODO : Autojoin docker swarm // TODO : Autojoin teleport // TODO : Install CA certs // TODO : Install node exporter // TODO : ZFS? // DRIVE SELECTION use bluetooth::setup_bluetooth; use boot::setup_bootloader; use desktop::setup_desktop; use docker::setup_docker; use drives::{format_drives, mount_drives, setup_fstrim}; use firewall::setup_firewall; use firmware::{setup_fwupd, setup_microcode}; use first_boot::{first_boot_values, genfstab}; use gpu::setup_video_drivers; use kernel::setup_mkinitcpio; use navos::setup_navos; use ollama::setup_ollama; use security::{setup_secure_boot, setup_tpm_unlock}; use skel::setup_skel; use ssh::setup_ssh; use user::setup_users; use virt::{setup_virtualization, setup_vm}; use yansi::{Color, Paint}; use zram::setup_zram; pub mod bluetooth; pub mod boot; pub mod desktop; pub mod docker; pub mod drives; pub mod firewall; pub mod firmware; pub mod first_boot; pub mod gpu; pub mod kernel; pub mod navos; pub mod ollama; pub mod security; pub mod skel; pub mod ssh; pub mod user; pub mod virt; pub mod zram; // TODO : error handling // TODO : Power profile daemon // TODO : Make zsh default + completions use crate::{ config::InstallConfig, pkg::{self, install_pkgs, pacstrap}, }; /// Uncomment the first occurrence of a specified value in a file. /// /// This function searches for the first line in the specified file that contains /// the given `value` string. If the line is commented out with a `#` symbol, /// it removes the `#` and updates the file. /// /// # Arguments /// /// * `value` - A string that specifies the value to search for in the file. /// * `file` - A string specifying the path to the file. pub fn uncomment_first_value_of(value: &str, file: &str) { // read in the file let content = std::fs::read_to_string(file).unwrap(); let mut new = String::new(); let mut found = false; // search for the first instance of `value` in the file // uncomment the '#' symbol if there is one for line in content.lines() { if line.contains(value) && !found { new.push_str(&format!("{}\n", line.replace('#', ""))); found = true; } else { new.push_str(&format!("{line}\n")); } } // write back std::fs::write(file, new).unwrap(); } /// Uncomment lines that start with a specified tag in a file. /// /// This function processes all lines in the specified file. For any line that starts /// with the provided `tag`, it removes the `tag` and updates the file. /// /// # Arguments /// /// * `tag` - A string specifying the prefix tag to remove from matching lines. /// * `file` - A string specifying the path to the file. pub fn uncomment_tag(tag: &str, file: &str) { // read in the file let content = std::fs::read_to_string(file).unwrap(); let mut new = String::new(); // search for the first instance of `value` in the file // uncomment the '#' symbol if there is one for line in content.lines() { if line.starts_with(tag) { new.push_str(&format!("{}\n", line.trim_start_matches(tag))); } else { new.push_str(&format!("{line}\n")); } } // write back std::fs::write(file, new).unwrap(); } /// Install a config on a new system pub fn install(conf: InstallConfig, bare: bool) { // Drive Setup format_drives(&conf.drive); mount_drives(&conf.drive); install_mnt(conf, bare); } pub fn install_mnt(conf: InstallConfig, bare: bool) { // Base Install pacstrap(&conf.pkg); genfstab(); // Configuration first_boot_values(&conf.general); setup_skel(&conf.general); setup_users(&conf.user.as_ref().unwrap_or(&Vec::new())); setup_ssh(&conf.ssh); // Presets match conf.general.mode { crate::config::InstallMode::Base => {} crate::config::InstallMode::Desktop => { setup_desktop(&conf); } crate::config::InstallMode::Server => { setup_navos(); install_pkgs(&pkg::SERVER_PKG); } crate::config::InstallMode::Kiosk => { // TODO } } // Applications if conf.pkg.virtualization.unwrap_or_default() { setup_virtualization(&conf); } if conf.pkg.docker.unwrap_or_default() { let user_conf = if let Some(user_conf) = &conf.user { user_conf.clone() } else { Vec::new() }; setup_docker(&user_conf); } if let Some(ai) = conf.ai { setup_ollama(&ai); } // Connectivity if conf.general.bluetooth.unwrap_or_default() { setup_bluetooth(); } if conf.general.firewall.unwrap_or(true) { setup_firewall(conf.ssh.is_some()); } // System setup_zram(); setup_vm(); if let Some(gpu_vendor) = &conf.general.gpu_driver { setup_video_drivers(gpu_vendor); } setup_fwupd(); setup_microcode(); setup_fstrim(); setup_bootloader(); setup_mkinitcpio(&conf.drive); if bare { setup_secure_boot(); } if conf.drive.encryption.is_some() { setup_tpm_unlock(&conf.drive); } println!("{}", "System install complete".bold().paint(Color::Green)); }