diff --git a/src/install/firewall.rs b/src/install/firewall.rs index aea7f2c..0a48a73 100644 --- a/src/install/firewall.rs +++ b/src/install/firewall.rs @@ -4,6 +4,7 @@ use crate::{ print_status, }; +/// Setup UFW pub fn setup_firewall(ssh: bool) { print_status("Enabling firewall"); install_pkgs(&["ufw"]); diff --git a/src/install/firmware.rs b/src/install/firmware.rs index 7bbd09e..5cd8fa6 100644 --- a/src/install/firmware.rs +++ b/src/install/firmware.rs @@ -1,11 +1,13 @@ use crate::{linux::systemd_service_enable, pkg::install_pkgs, print_status}; +/// Setup firmware update daemon pub fn setup_fwupd() { print_status("Enabling firmware updates"); install_pkgs(&["fwupd"]); systemd_service_enable("fwupd-refresh.timer"); } +/// Setup CPU Microcode pub fn setup_microcode() { print_status("Installing CPU Microcode"); let cpuinfo = std::fs::read_to_string("/proc/cpuinfo").unwrap(); diff --git a/src/install/gpu.rs b/src/install/gpu.rs index 0e872f7..9532dda 100644 --- a/src/install/gpu.rs +++ b/src/install/gpu.rs @@ -1,5 +1,6 @@ use crate::{config::GPUVendor, pkg::install_pkgs}; +/// Setup GPU video drivers pub fn setup_video_drivers(vendor: &GPUVendor) { match vendor { GPUVendor::AMD => { diff --git a/src/install/kernel.rs b/src/install/kernel.rs index c71c69b..539006b 100644 --- a/src/install/kernel.rs +++ b/src/install/kernel.rs @@ -6,6 +6,7 @@ use crate::{ print_status, }; +/// Setup initramfs pub fn setup_mkinitcpio(conf: &DriveConfig) { print_status("Writing /etc/mkinitcpio.d/linux.preset"); install_file( diff --git a/src/install/mod.rs b/src/install/mod.rs index b44cbf3..b30de83 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -47,6 +47,16 @@ use crate::{ 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(); @@ -67,6 +77,15 @@ pub fn uncomment_first_value_of(value: &str, file: &str) { 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(); @@ -96,15 +115,13 @@ pub fn install(conf: InstallConfig) { pacstrap(&conf.pkg); genfstab(); - // System Setup + // Configuration 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(); - + // Presets match conf.general.mode { crate::config::InstallMode::Base => {} crate::config::InstallMode::Desktop => { @@ -119,6 +136,8 @@ pub fn install(conf: InstallConfig) { } } + // Applications + if conf.pkg.virtualization.unwrap_or_default() { setup_virtualization(&conf); } @@ -137,8 +156,7 @@ pub fn install(conf: InstallConfig) { setup_ollama(&ai); } - setup_zram(); - + // Connectivity if conf.general.bluetooth.unwrap_or_default() { setup_bluetooth(); } @@ -147,12 +165,15 @@ pub fn install(conf: InstallConfig) { 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_bootloader(); setup_mkinitcpio(&conf.drive); setup_secure_boot(); diff --git a/src/install/ollama.rs b/src/install/ollama.rs index 1729105..0210abe 100644 --- a/src/install/ollama.rs +++ b/src/install/ollama.rs @@ -1,4 +1,9 @@ -use crate::{config::OllamaConfig, linux::systemd_service_enable, pkg::install_pkgs}; +use crate::{ + config::OllamaConfig, + linux::{arch_chroot, systemd_service_enable}, + pkg::install_pkgs, + print_status, +}; /// Setup Ollama AI Service pub fn setup_ollama(conf: &OllamaConfig) { @@ -10,7 +15,20 @@ pub fn setup_ollama(conf: &OllamaConfig) { systemd_service_enable("ollama.service"); - for model in conf.models.clone().unwrap_or_default() { - // TODO : Pull models + print_status("Pulling Models"); + + let mut ollama_server = std::process::Command::new("arch-chroot") + .arg("/mnt") + .arg("runuser -u ollama -- env OLLAMA_MODELS=/var/lib/ollama HOME=/var/lib/ollama /usr/bin/ollama serve") + .stdout(Stdio::piped()) + .spawn() + .expect("Failed to start ollama server"); + + let models = conf.models.clone().unwrap_or_default(); + + for model in models { + arch_chroot(&["ollama", "pull", &model], None, true); } + + ollama_server.kill().unwrap(); } diff --git a/src/install/virt.rs b/src/install/virt.rs index 1fc228c..7ff0602 100644 --- a/src/install/virt.rs +++ b/src/install/virt.rs @@ -1,7 +1,8 @@ use crate::{ config::{InstallConfig, InstallMode}, linux::{arch_chroot, run_command, systemd_service_enable}, - pkg::install_pkgs, print_status, + pkg::install_pkgs, + print_status, }; pub fn setup_virtualization(conf: &InstallConfig) { @@ -32,9 +33,9 @@ pub fn setup_virtualization(conf: &InstallConfig) { /// Setup guest utils if running inside a VM pub fn setup_vm() { - let is_vm = run_command(&[ - "systemd-detect-virt", "--vm" - ], None, false).0.trim(); + let is_vm = run_command(&["systemd-detect-virt", "--vm"], None, false) + .0 + .trim(); match is_vm { "qemu" | "kvm" => { @@ -42,7 +43,7 @@ pub fn setup_vm() { install_pkgs(&["qemu-guest-agent", "spice-vdagent"]); systemd_service_enable("qemu-guest-agent.service"); systemd_service_enable("spice-vdagentd.service"); - }, + } _ => {} } } diff --git a/src/linux.rs b/src/linux.rs index 3711f80..5cfd3ef 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -75,7 +75,6 @@ pub fn install_file(path: &str, content: &str, permissions: u32) { file.write_all(content.as_bytes()).unwrap(); let permissions = std::fs::Permissions::from_mode(permissions); - // TODO : Fix permission format - print_status(&format!("Wrote file {path} [{permissions:#?}]")); + print_status(&format!("Wrote file {path} [{:o}]", permissions.mode())); std::fs::set_permissions(path, permissions).unwrap(); }