update
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2025-01-10 14:27:23 +01:00
parent dfa3a34484
commit 3ae066d593
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 60 additions and 16 deletions

View file

@ -4,6 +4,7 @@ use crate::{
print_status, print_status,
}; };
/// Setup UFW
pub fn setup_firewall(ssh: bool) { pub fn setup_firewall(ssh: bool) {
print_status("Enabling firewall"); print_status("Enabling firewall");
install_pkgs(&["ufw"]); install_pkgs(&["ufw"]);

View file

@ -1,11 +1,13 @@
use crate::{linux::systemd_service_enable, pkg::install_pkgs, print_status}; use crate::{linux::systemd_service_enable, pkg::install_pkgs, print_status};
/// Setup firmware update daemon
pub fn setup_fwupd() { pub fn setup_fwupd() {
print_status("Enabling firmware updates"); print_status("Enabling firmware updates");
install_pkgs(&["fwupd"]); install_pkgs(&["fwupd"]);
systemd_service_enable("fwupd-refresh.timer"); systemd_service_enable("fwupd-refresh.timer");
} }
/// Setup CPU Microcode
pub fn setup_microcode() { pub fn setup_microcode() {
print_status("Installing CPU Microcode"); print_status("Installing CPU Microcode");
let cpuinfo = std::fs::read_to_string("/proc/cpuinfo").unwrap(); let cpuinfo = std::fs::read_to_string("/proc/cpuinfo").unwrap();

View file

@ -1,5 +1,6 @@
use crate::{config::GPUVendor, pkg::install_pkgs}; use crate::{config::GPUVendor, pkg::install_pkgs};
/// Setup GPU video drivers
pub fn setup_video_drivers(vendor: &GPUVendor) { pub fn setup_video_drivers(vendor: &GPUVendor) {
match vendor { match vendor {
GPUVendor::AMD => { GPUVendor::AMD => {

View file

@ -6,6 +6,7 @@ use crate::{
print_status, print_status,
}; };
/// Setup initramfs
pub fn setup_mkinitcpio(conf: &DriveConfig) { pub fn setup_mkinitcpio(conf: &DriveConfig) {
print_status("Writing /etc/mkinitcpio.d/linux.preset"); print_status("Writing /etc/mkinitcpio.d/linux.preset");
install_file( install_file(

View file

@ -47,6 +47,16 @@ use crate::{
pkg::{self, install_pkgs, pacstrap}, 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) { pub fn uncomment_first_value_of(value: &str, file: &str) {
// read in the file // read in the file
let content = std::fs::read_to_string(file).unwrap(); 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(); 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) { pub fn uncomment_tag(tag: &str, file: &str) {
// read in the file // read in the file
let content = std::fs::read_to_string(file).unwrap(); let content = std::fs::read_to_string(file).unwrap();
@ -96,15 +115,13 @@ pub fn install(conf: InstallConfig) {
pacstrap(&conf.pkg); pacstrap(&conf.pkg);
genfstab(); genfstab();
// System Setup // Configuration
first_boot_values(&conf.general); first_boot_values(&conf.general);
setup_skel(&conf.general); setup_skel(&conf.general);
setup_users(&conf.user.as_ref().unwrap_or(&Vec::new())); setup_users(&conf.user.as_ref().unwrap_or(&Vec::new()));
setup_ssh(&conf.ssh); setup_ssh(&conf.ssh);
setup_bootloader(); // Presets
match conf.general.mode { match conf.general.mode {
crate::config::InstallMode::Base => {} crate::config::InstallMode::Base => {}
crate::config::InstallMode::Desktop => { crate::config::InstallMode::Desktop => {
@ -119,6 +136,8 @@ pub fn install(conf: InstallConfig) {
} }
} }
// Applications
if conf.pkg.virtualization.unwrap_or_default() { if conf.pkg.virtualization.unwrap_or_default() {
setup_virtualization(&conf); setup_virtualization(&conf);
} }
@ -137,8 +156,7 @@ pub fn install(conf: InstallConfig) {
setup_ollama(&ai); setup_ollama(&ai);
} }
setup_zram(); // Connectivity
if conf.general.bluetooth.unwrap_or_default() { if conf.general.bluetooth.unwrap_or_default() {
setup_bluetooth(); setup_bluetooth();
} }
@ -147,12 +165,15 @@ pub fn install(conf: InstallConfig) {
setup_firewall(conf.ssh.is_some()); setup_firewall(conf.ssh.is_some());
} }
// System
setup_zram();
setup_vm(); setup_vm();
if let Some(gpu_vendor) = &conf.general.gpu_driver { if let Some(gpu_vendor) = &conf.general.gpu_driver {
setup_video_drivers(gpu_vendor); setup_video_drivers(gpu_vendor);
} }
setup_fwupd(); setup_fwupd();
setup_microcode(); setup_microcode();
setup_bootloader();
setup_mkinitcpio(&conf.drive); setup_mkinitcpio(&conf.drive);
setup_secure_boot(); setup_secure_boot();

View file

@ -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 /// Setup Ollama AI Service
pub fn setup_ollama(conf: &OllamaConfig) { pub fn setup_ollama(conf: &OllamaConfig) {
@ -10,7 +15,20 @@ pub fn setup_ollama(conf: &OllamaConfig) {
systemd_service_enable("ollama.service"); systemd_service_enable("ollama.service");
for model in conf.models.clone().unwrap_or_default() { print_status("Pulling Models");
// TODO : Pull 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();
} }

View file

@ -1,7 +1,8 @@
use crate::{ use crate::{
config::{InstallConfig, InstallMode}, config::{InstallConfig, InstallMode},
linux::{arch_chroot, run_command, systemd_service_enable}, linux::{arch_chroot, run_command, systemd_service_enable},
pkg::install_pkgs, print_status, pkg::install_pkgs,
print_status,
}; };
pub fn setup_virtualization(conf: &InstallConfig) { pub fn setup_virtualization(conf: &InstallConfig) {
@ -32,9 +33,9 @@ pub fn setup_virtualization(conf: &InstallConfig) {
/// Setup guest utils if running inside a VM /// Setup guest utils if running inside a VM
pub fn setup_vm() { pub fn setup_vm() {
let is_vm = run_command(&[ let is_vm = run_command(&["systemd-detect-virt", "--vm"], None, false)
"systemd-detect-virt", "--vm" .0
], None, false).0.trim(); .trim();
match is_vm { match is_vm {
"qemu" | "kvm" => { "qemu" | "kvm" => {
@ -42,7 +43,7 @@ pub fn setup_vm() {
install_pkgs(&["qemu-guest-agent", "spice-vdagent"]); install_pkgs(&["qemu-guest-agent", "spice-vdagent"]);
systemd_service_enable("qemu-guest-agent.service"); systemd_service_enable("qemu-guest-agent.service");
systemd_service_enable("spice-vdagentd.service"); systemd_service_enable("spice-vdagentd.service");
}, }
_ => {} _ => {}
} }
} }

View file

@ -75,7 +75,6 @@ pub fn install_file(path: &str, content: &str, permissions: u32) {
file.write_all(content.as_bytes()).unwrap(); file.write_all(content.as_bytes()).unwrap();
let permissions = std::fs::Permissions::from_mode(permissions); let permissions = std::fs::Permissions::from_mode(permissions);
// TODO : Fix permission format print_status(&format!("Wrote file {path} [{:o}]", permissions.mode()));
print_status(&format!("Wrote file {path} [{permissions:#?}]"));
std::fs::set_permissions(path, permissions).unwrap(); std::fs::set_permissions(path, permissions).unwrap();
} }