krata/crates/kratart/examples/squashify.rs

30 lines
834 B
Rust
Raw Normal View History

2024-03-08 14:44:45 +00:00
use std::{env::args, path::PathBuf};
use anyhow::Result;
use env_logger::Env;
use kratart::image::{cache::ImageCache, compiler::ImageCompiler, name::ImageName};
use tokio::fs;
#[tokio::main]
async fn main() -> Result<()> {
2024-03-23 04:31:35 +00:00
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
2024-03-08 14:44:45 +00:00
let image = ImageName::parse(&args().nth(1).unwrap())?;
2024-03-13 14:20:22 +00:00
let seed = args().nth(2).map(PathBuf::from);
2024-03-08 14:44:45 +00:00
let cache_dir = PathBuf::from("krata-cache");
if !cache_dir.exists() {
fs::create_dir(&cache_dir).await?;
}
2024-03-13 14:20:22 +00:00
2024-03-08 14:44:45 +00:00
let cache = ImageCache::new(&cache_dir)?;
2024-03-13 14:20:22 +00:00
let compiler = ImageCompiler::new(&cache, seed)?;
2024-03-08 14:44:45 +00:00
let info = compiler.compile(&image).await?;
println!(
"generated squashfs of {} to {}",
image,
info.image_squashfs.to_string_lossy()
);
Ok(())
}