151 lines
5.5 KiB
Rust
151 lines
5.5 KiB
Rust
use navinstall::config::InstallConfig;
|
|
use navinstall::fx::bluetooth::setup_bluetooth;
|
|
use navinstall::fx::docker::setup_docker;
|
|
use navinstall::fx::firewall::setup_firewall;
|
|
use navinstall::fx::gpu::setup_video_drivers;
|
|
use navinstall::fx::ollama::setup_ollama;
|
|
use navinstall::fx::ssh::setup_ssh;
|
|
use navinstall::fx::virt::{setup_virtualization, setup_vm_guest};
|
|
use navinstall::fx::zram::setup_zram;
|
|
use navinstall::install::navos::setup_navos;
|
|
use navinstall::install::{
|
|
drives::setup_disk_image, install, install_mnt, security::ensure_secure_boot,
|
|
};
|
|
use navinstall::linux::is_root;
|
|
use navinstall::pkg::pacstrap_at;
|
|
use navinstall::print::print_config;
|
|
use navinstall::print_status;
|
|
use navinstall::{create_iso::create_iso, expect_yes};
|
|
use yansi::{Color, Paint};
|
|
|
|
pub fn ensure_root() {
|
|
if !is_root() {
|
|
eprintln!("Error: You need root to install");
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
println!(
|
|
"{}",
|
|
"⚠️ Warning: This is an alpha version of the installer. DO NOT USE in PROD"
|
|
.paint(Color::Yellow)
|
|
);
|
|
|
|
let args: navinstall::args::NavinstallArgs = argh::from_env();
|
|
|
|
match args.cmd {
|
|
navinstall::args::NavinstallCommands::CreateISO(create_isocommand) => {
|
|
let kb_layout_default = "us".to_string();
|
|
let kb_layout = create_isocommand.kb_layout.unwrap_or(kb_layout_default);
|
|
|
|
let user = if create_isocommand.user.is_some() && create_isocommand.pass.is_some() {
|
|
Some((
|
|
create_isocommand.user.unwrap().to_string(),
|
|
create_isocommand.pass.unwrap().to_string(),
|
|
create_isocommand.uid.unwrap_or(1000),
|
|
))
|
|
} else {
|
|
None
|
|
};
|
|
|
|
create_iso(
|
|
create_isocommand.without_gui,
|
|
create_isocommand.no_tmp,
|
|
&kb_layout,
|
|
create_isocommand.kb_variant,
|
|
user,
|
|
create_isocommand.unit,
|
|
create_isocommand.install,
|
|
);
|
|
std::process::exit(0);
|
|
}
|
|
navinstall::args::NavinstallCommands::Install(install_command) => {
|
|
ensure_root();
|
|
|
|
let conf = read_conf(&install_command.config);
|
|
|
|
if !install_command.force {
|
|
print_config(&conf);
|
|
print!("Do you want to proceed with this configuration? (yes/no) ");
|
|
expect_yes();
|
|
}
|
|
|
|
if conf.general.secure_boot.unwrap_or(false) {
|
|
ensure_secure_boot();
|
|
}
|
|
|
|
// Run the
|
|
install(conf, true);
|
|
}
|
|
navinstall::args::NavinstallCommands::CreateTar(create_tar_command) => {
|
|
ensure_root();
|
|
print_status("Pacstrapping root fs");
|
|
pacstrap_at(&create_tar_command.dir, &[]);
|
|
setup_navos(&create_tar_command.dir.as_str());
|
|
}
|
|
navinstall::args::NavinstallCommands::CreateImage(create_image_command) => {
|
|
let conf = read_conf(&create_image_command.config);
|
|
setup_disk_image(
|
|
&create_image_command.image.as_str(),
|
|
create_image_command.gpt,
|
|
);
|
|
install_mnt(conf, false);
|
|
}
|
|
navinstall::args::NavinstallCommands::Feature(feature_command) => {
|
|
match feature_command.cmd {
|
|
navinstall::fx::Features::Bluetooth(_) => setup_bluetooth(),
|
|
navinstall::fx::Features::GPU(gpufeature) => {
|
|
let vendor = match gpufeature.vendor.to_lowercase().as_str() {
|
|
"amd" => navinstall::config::GPUVendor::AMD,
|
|
"intel" => navinstall::config::GPUVendor::INTEL,
|
|
"nvidia" => navinstall::config::GPUVendor::NVIDIA,
|
|
_ => {
|
|
println!("{} is no GPU vendor", gpufeature.vendor);
|
|
std::process::exit(1);
|
|
}
|
|
};
|
|
|
|
setup_video_drivers(&vendor);
|
|
}
|
|
navinstall::fx::Features::Docker(docker_feature) => {
|
|
setup_docker(&docker_feature.user);
|
|
}
|
|
navinstall::fx::Features::Firewall(firewall_feature) => {
|
|
setup_firewall(firewall_feature.ssh)
|
|
}
|
|
navinstall::fx::Features::Ollama(ollama_feature) => {
|
|
setup_ollama(&ollama_feature.into_config())
|
|
}
|
|
navinstall::fx::Features::SSH(sshfeature) => {
|
|
setup_ssh(&Some(sshfeature.into_config()))
|
|
}
|
|
navinstall::fx::Features::Virt(virt_feature) => setup_virtualization(&virt_feature),
|
|
navinstall::fx::Features::VirtGuest(_) => setup_vm_guest(),
|
|
navinstall::fx::Features::Zram(_) => setup_zram(),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn read_conf(config_file: &str) -> InstallConfig {
|
|
let config_content = std::fs::read_to_string(config_file);
|
|
|
|
match config_content {
|
|
Ok(content) => match toml::from_str(&content) {
|
|
Ok(config) => config,
|
|
Err(e) => {
|
|
eprintln!(
|
|
"{} {}",
|
|
"Error: Could not deserialize TOML file.".paint(Color::Red),
|
|
e.paint(Color::Red)
|
|
);
|
|
std::process::exit(1);
|
|
}
|
|
},
|
|
Err(_) => {
|
|
eprintln!("{}", "Error: Could not read config file.".paint(Color::Red));
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
}
|