From de352f683f104c68106d488863f338afdb836e94 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Tue, 11 Aug 2026 20:53:53 +0000 Subject: Add independent Rust Hasher rootfs builder --- src/main.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..44cb296 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,54 @@ +use std::env; +use std::fs; +use std::path::PathBuf; +use std::process::Command; + +use alt_controller_image::{artifact_path, Profile}; + +fn run(command: &mut Command, description: &str) { + let status = command.status().unwrap_or_else(|error| panic!("{description}: {error}")); + assert!(status.success(), "{description} exited with {status}"); +} + +fn main() { + let project = env::current_dir().expect("current directory"); + let profile_path = project.join("profiles/alt-controller.profile"); + let profile = Profile::load(&profile_path).unwrap_or_else(|error| panic!("profile: {error}")); + let workdir: PathBuf = project.join("work/alt-controller"); + let rootfs = workdir.join("chroot"); + let artifact = artifact_path(&project); + + if workdir.exists() { + fs::remove_dir_all(&workdir).expect("remove previous Hasher workdir"); + } + fs::create_dir_all(&workdir).expect("create Hasher workdir"); + fs::create_dir_all(artifact.parent().expect("artifact parent")).expect("create output directory"); + + run( + Command::new("hsh") + .args(["--mountpoints=/proc", "--initroot-only", "--workdir"]) + .arg(&workdir), + "initialize isolated Hasher root", + ); + + let mut install = Command::new("hsh-install"); + install.args(["--mountpoints=/proc", "--workdir"]); + install.arg(&workdir); + install.args(profile.install_arguments()); + run(&mut install, "install target rootfs packages"); + + if artifact.exists() { + fs::remove_file(&artifact).expect("remove previous artifact"); + } + run( + Command::new("tar") + .args(["--numeric-owner", "--xattrs", "--acls", "--exclude=./.host", "-C"]) + .arg(&rootfs) + .args(["-cpf"]) + .arg(&artifact) + .arg("."), + "archive isolated rootfs", + ); + + println!("{}", artifact.display()); +} -- cgit v1.2.3