// TODO : Autojoin docker swarm // TODO : Autojoin teleport // DRIVE SELECTION use bluetooth::setup_bluetooth; use boot::setup_bootloader; use desktop::setup_desktop; use docker::setup_docker; use drives::{format_drives, mount_drives}; use first_boot::{first_boot_values, genfstab}; 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; 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 first_boot; 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; use crate::{ config::InstallConfig, pkg::{self, install_pkgs, pacstrap}, }; 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(); } 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) { // Drive Setup format_drives(&conf.drive); mount_drives(&conf.drive); // Base Install pacstrap(&conf.pkg); genfstab(); // System Setup first_boot_values(&conf.general); setup_skel(&conf.general); setup_users(&conf.user.as_ref().unwrap_or(&Vec::new())); setup_ssh(&conf.ssh); setup_bootloader(); 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 } } 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); } setup_zram(); if conf.general.bluetooth.unwrap_or_default() { setup_bluetooth(); } setup_mkinitcpio(&conf.drive); setup_secure_boot(); if conf.drive.encryption.is_some() { setup_tpm_unlock(&conf.drive); } println!("{}", "System install complete".paint(Color::Green)); }