diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-11 20:53:53 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-11 20:53:53 +0000 |
| commit | de352f683f104c68106d488863f338afdb836e94 (patch) | |
| tree | 47812ded4b6a042c4a86e55f16bc661c4c657d57 /src/main.rs | |
Add independent Rust Hasher rootfs builder
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 54 |
1 files changed, 54 insertions, 0 deletions
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()); +} |