use std::io::Write; use config::InstallConfig; mod args; mod config; mod create_iso; mod install; mod linux; mod pkg; mod print; use create_iso::create_iso; use install::install; use linux::is_root; use print::print_config; use yansi::{Color, Paint}; fn print_status(msg: &str) { println!( "{} {}", "-->".paint(Color::Red), msg.paint(Color::Blue.bold()) ); } fn main() { println!( "{}", "⚠️ Warning: This is an alpha version of the installer. DO NOT USE in PROD" .paint(Color::Yellow) ); let args = args::get_args(); match args.subcommand() { Some(("create-iso", iso_args)) => { let without_gui = iso_args.get_flag("without_gui"); let kb_layout_default = "us".to_string(); let kb_layout: &String = iso_args.get_one("kb_layout").unwrap_or(&kb_layout_default); let kb_variant: Option<&str> = iso_args.get_one("kb_variant").map(|x: &String| x.as_str()); create_iso(without_gui, kb_layout, kb_variant); std::process::exit(0); } Some(("create-tar", _)) => { println!("Tar creation is not yet supported"); unimplemented!() } Some(("create-img", install_args)) => { let config_file: &String = install_args.get_one("config").unwrap(); let config_content = std::fs::read_to_string(config_file); let conf: InstallConfig = 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); } }; println!("Installing to a disk image is not yet supported"); unimplemented!() } Some(("install", install_args)) => { if !is_root() { eprintln!("Error: You need root to install"); std::process::exit(1); } let config_file: &String = install_args.get_one("config").unwrap(); let config_content = std::fs::read_to_string(config_file); let conf: InstallConfig = 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); } }; print_config(&conf); print!("Do you want to proceed with this configuration? (yes/no) "); let mut input = String::new(); std::io::stdout().flush().expect("Error flushing stdout."); std::io::stdin() .read_line(&mut input) .expect("Error reading input."); let input = input.trim().to_lowercase(); if input != "yes" { println!("Installation aborted."); std::process::exit(0); } // Run the install(conf); } _ => {} } }