cli/src/main.rs

68 lines
3.9 KiB
Rust

use std::{env, process::{Command, ExitCode}};
mod self_check;
mod infrastructure;
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<String> = env::args().skip(1).collect();
let result = match args.iter().map(String::as_str).collect::<Vec<_>>().as_slice() {
["pipeline", ..] | ["release", "plan", ..] | ["release", "publish", ..] => infrastructure::dispatch(&args),
["build", "gnome-probe", 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(),
["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", "plan"] => archipelago_system::updates::plan(true),
["update", "apply", "--plan", id] => archipelago_system::updates::apply(id),
["overlay", "apply", "test-marker"] => {
run(archipelago_system::HOST, &args)
}
_ => {
eprintln!("Experimental Core profile\n\
archipelago build iso WORKDIR BOOTSTRAP.tar.zst\n\
archipelago build gnome-probe WORKDIR BOOTSTRAP.tar.zst (private integration probe)\n\
archipelago registry init|verify REPOSITORY\n\
archipelago layer validate MANIFEST.yaml\n\
archipelago desktop reconcile|seed-flatpaks\n\
archipelago install /dev/DEVICE --erase\n\
archipelago firstboot | status | self-check\n\
archipelago overlay apply test-marker\n\
archipelago extension add PACKAGE...\n\
archipelago update check|plan\n\
archipelago update apply --plan PLAN_SHA256\n\
archipelago pipeline status|logs|run --reason TEXT (configured infrastructure host)\n\
archipelago release plan|publish CANDIDATES.json --reason TEXT (infrastructure host)\n\
Activation happens on the next explicit reboot.");
return ExitCode::from(2);
}
};
match result {
Ok(()) => ExitCode::SUCCESS,
Err(error) => { eprintln!("archipelago: {error}"); ExitCode::FAILURE }
}
}