use std::{env, process::{Command, ExitCode}}; mod self_check; mod infrastructure; mod presentation; fn run(script: &str, args: &[String]) -> Result<(), String> { let status = Command::new("/usr/bin/bash") .args(["-euo", "pipefail", "-c", script, "archipelago-adapter"]) .args(args).status().map_err(|e| e.to_string())?; if status.success() { Ok(()) } else { Err(format!("operation failed: {status}")) } } fn main() -> ExitCode { let args: Vec = env::args().skip(1).collect(); let result = match args.iter().map(String::as_str).collect::>().as_slice() { [] | ["help"] | ["--help"] | ["-h"] => { presentation::help(); return ExitCode::SUCCESS; } ["--version"] | ["version"] => { println!("archipelago {}", env!("CARGO_PKG_VERSION")); return ExitCode::SUCCESS; } ["pipeline", ..] | ["release", "plan", ..] | ["release", "publish", ..] => infrastructure::dispatch(&args), ["build", "iso", "--purpose", "gnome", work, bootstrap] => archipelago_builder::build_gnome_probe_script() .and_then(|script| env::current_exe().map_err(|e| e.to_string()).and_then(|binary| run(&script, &[work.to_string(), bootstrap.to_string(), binary.display().to_string(), "gnome-probe".into()]))), ["desktop", "reconcile"] => archipelago_system::desktop::reconcile(), ["desktop", "seed-flatpaks"] => archipelago_system::desktop::seed_flatpaks(), ["desktop", "refresh-updates"] => archipelago_system::software::refresh(), ["desktop", "software-request", "refresh"] => archipelago_system::software::request("refresh", None), ["desktop", "software-request", "apply", id] => archipelago_system::software::request("apply", Some(id)), ["layer", "validate", path] => std::fs::read_to_string(path).map_err(|e| e.to_string()) .and_then(|text| archipelago_contracts::layer::validate(&text)) .map(|_| println!("Layer v1 syntax, schema and source-local checks passed; resolution/build checks still required")), ["registry", "init", path] => archipelago_registry::init(path), ["registry", "verify", path] => archipelago_registry::verify(path), ["build", "iso", work, bootstrap] => { match env::current_exe() { Ok(binary) => run(&archipelago_builder::build_iso_script(), &[work.to_string(), bootstrap.to_string(), binary.display().to_string()]), Err(e) => Err(e.to_string()), } } ["install", device, "--erase"] => run(archipelago_installer::INSTALL, &[device.to_string()]), ["firstboot"] => run(archipelago_system::FIRSTBOOT, &[]), ["self-check"] => self_check::check(), ["status"] => run(archipelago_system::HOST, &args).and_then(|_| archipelago_system::extensions::describe()), ["boot-sync"] => run(archipelago_system::HOST, &args), ["extension", "add", ..] => archipelago_system::extensions::add(&args[2..]), ["update", "check"] => archipelago_system::updates::plan(false), ["update", "check", "--json"] | ["update", "diff"] => archipelago_system::updates::plan_json(false), ["update", "plan", "--json"] => archipelago_system::updates::plan_json(true), ["update", "plan"] => archipelago_system::updates::plan(true), ["update", "apply", "--plan", id] => archipelago_system::updates::apply(id), ["overlay", "apply", "test-marker"] if cfg!(feature = "lab-fixtures") => { run(archipelago_system::HOST, &args) } _ => { eprintln!("{}", if presentation::russian() { "Неизвестная команда или неверные аргументы. Справка: archipelago --help" } else { "Unknown command or invalid arguments. See: archipelago --help" }); return ExitCode::from(2); } }; match result { Ok(()) => ExitCode::SUCCESS, Err(error) => { eprintln!("archipelago: {}: {error}", if presentation::russian() { "ошибка" } else { "error" }); ExitCode::FAILURE } } }