This commit is contained in:
JMARyA 2024-12-28 01:19:44 +01:00
parent eabd898ccf
commit f2b1a43f62
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
13 changed files with 453 additions and 390 deletions

97
src/install/mod.rs Normal file
View file

@ -0,0 +1,97 @@
// TODO : Setup ssh (config + authorized_keys)
// TODO : Setup virtualization
// TODO : Setup docker
// TODO : Autojoin docker swarm
// TODO : Autojoin teleport
// DRIVE SELECTION
use boot::setup_bootloader;
use drives::{format_drives, mount_drives};
use first_boot::{first_boot_values, genfstab};
use kernel::setup_mkinitcpio;
use security::{setup_secure_boot, setup_tpm_unlock};
use user::setup_users;
use yansi::{Color, Paint};
use zram::setup_zram;
pub mod boot;
pub mod drives;
pub mod first_boot;
pub mod kernel;
pub mod security;
pub mod user;
pub mod zram;
use crate::{
config::InstallConfig,
pkg::{self, install_pkgs, pacstrap},
};
pub fn str_vec(v: Vec<&str>) -> Vec<String> {
v.into_iter().map(|x| x.to_string()).collect()
}
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 install(conf: InstallConfig) {
// Drive Setup
format_drives(&conf.drive, conf.general.encryption);
mount_drives(&conf.drive, conf.general.encryption);
// Base Install
pacstrap(&conf.pkg);
genfstab();
// System Setup
first_boot_values(&conf.general);
setup_users(&conf.user);
setup_bootloader();
match conf.general.mode {
crate::config::InstallMode::Base => {}
crate::config::InstallMode::Desktop => {
install_pkgs(&pkg::DESKTOP_PKG);
}
crate::config::InstallMode::Server => {
install_pkgs(&pkg::SERVER_PKG);
}
crate::config::InstallMode::Kiosk => {
// TODO
}
}
if conf.pkg.virtualization {
// TODO : Enable virtualization
}
if conf.pkg.docker {
// TODO : Enable docker
}
setup_zram();
setup_secure_boot();
setup_mkinitcpio();
setup_tpm_unlock(&conf.drive);
println!("{}", "System install complete".paint(Color::Green));
}