diff --git a/Cargo.lock b/Cargo.lock index 5b16fa4..bdd1207 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,9 +172,9 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.2.29" +version = "1.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" +checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7" dependencies = [ "jobserver", "libc", @@ -296,12 +296,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "cpio" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938e716cb1ade5d6c8f959c13a7248b889c07491fc7e41167c3afe20f8f0de1e" - [[package]] name = "displaydoc" version = "0.2.5" @@ -890,14 +884,12 @@ name = "init" version = "2.4.1" dependencies = [ "base64 0.22.1", - "cpio", "dkl", "env_logger", "eyre", "itertools", "libc", "log", - "lz4", "nix", "openssl", "regex", @@ -909,7 +901,6 @@ dependencies = [ "termios", "tokio", "unix_mode", - "zstd", ] [[package]] @@ -1065,25 +1056,6 @@ version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" -[[package]] -name = "lz4" -version = "1.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20b523e860d03443e98350ceaac5e71c6ba89aea7d960769ec3ce37f4de5af4" -dependencies = [ - "lz4-sys", -] - -[[package]] -name = "lz4-sys" -version = "1.11.1+lz4-1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bd8c0d6c6ed0cd30b3652886bb8711dc4bb01d637a68105a3d5158039b418e6" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "memchr" version = "2.7.5" @@ -1645,9 +1617,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index b7a909b..4f912f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,10 +24,7 @@ serde_yaml = "0.9.34" shell-escape = "0.1.5" tokio = { version = "1.38.0", features = ["rt", "net", "fs", "process", "io-std", "io-util", "sync", "macros", "signal"] } termios = "0.3.3" -zstd = "0.13.3" unix_mode = "0.1.4" -cpio = "0.4.1" -lz4 = "1.28.1" base64 = "0.22.1" sys-info = "0.9.1" dkl = { git = "https://novit.tech/direktil/dkl", version = "1.0.0" } diff --git a/Dockerfile b/Dockerfile index fed050e..7bf5c2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,16 +26,10 @@ copy etc/sshd_config etc/ssh/sshd_config copy --from=rust /dist/bin/init /system/init -run mv dev /layer \ - && chroot . ldd /init |sed -e 's,.*>\s,,' -e 's,^\s*,,' -e 's,\s.*,,' -e 's,^/,,' |sort |uniq >/required_libs \ - && tar c init -T /required_libs | tar xv -C /layer |xargs rm -v \ - && find |cpio -H newc -o |zstd -19 >/layer/system.azstd - -workdir /layer run mkdir -p bin run var/log; cd bin && for cmd in init-version init-connect bootstrap; do ln -s ../init $cmd; done # check viability -run ldd bin/init-version; chroot . init-version +run chroot . init-version run find * |cpio -H newc -oF /initrd diff --git a/build-test-initrd b/build-test-initrd index b57437e..c178fd5 100755 --- a/build-test-initrd +++ b/build-test-initrd @@ -17,5 +17,5 @@ cpio --quiet --extract --file $base_initrd --directory $dir cpio --quiet -tF test-initrd.cpio if cpio -tF test-initrd.cpio 2>&1 |grep bytes.of.junk; then echo "bad cpio archive"; exit 1; fi -lz4 -l9v test-initrd.cpio && mv test-initrd.cpio.lz4 test-initrd.cpio +zstd -19 -T0 -vf test-initrd.cpio && mv test-initrd.cpio.zst test-initrd.cpio diff --git a/src/cmd/init.rs b/src/cmd/init.rs index e888cf7..ab466d7 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -62,24 +62,6 @@ pub async fn run() { log::set_max_level(log::LevelFilter::Debug); } - // extract system archive - retry_or_ignore(async || { - if fs::try_exists("system.azstd").await? { - info!("unpacking system.azstd"); - let zarch = fs::read("system.azstd").await?; - let arch = zstd::Decoder::new(zarch.as_slice())?; - extract_cpio(arch).await - } else if fs::try_exists("system.alz4").await? { - info!("unpacking system.alz4"); - let zarch = fs::read("system.alz4").await?; - let arch = lz4::Decoder::new(zarch.as_slice())?; - extract_cpio(arch).await - } else { - Ok(()) - } - }) - .await; - // load config let cfg: Config = retry(async || { let cfg = (fs::read("config.yaml").await) @@ -190,72 +172,6 @@ async fn chmod(path: impl AsRef, mode: u32) -> std::io::Result<()> { fs::set_permissions(path, perms).await } -async fn extract_cpio(mut arch: impl std::io::Read) -> Result<()> { - loop { - let rd = cpio::NewcReader::new(&mut arch)?; - let entry = rd.entry(); - if entry.is_trailer() { - return Ok(()); - } - - let path = entry.name().to_string(); - - if let Err(e) = extract_cpio_entry(rd, &path).await { - return Err(format_err!("failed to extract {path}: {e}")); - } - } -} - -async fn extract_cpio_entry( - rd: cpio::NewcReader, - path: impl AsRef, -) -> Result<()> { - use std::os::unix::fs::chown; - use unix_mode::Type; - - let entry = rd.entry(); - let path = path.as_ref(); - - if let Some(parent) = path.parent() { - fs::create_dir_all(parent).await?; - } - - let _ = fs::remove_file(path).await; - - let mode = entry.mode(); - let uid = entry.uid(); - let gid = entry.gid(); - - match Type::from(mode) { - Type::Dir => { - fs::create_dir_all(path).await?; - } - Type::File => { - let mut data = vec![]; - rd.to_writer(&mut data)?; - - fs::write(path, data).await?; - } - Type::Symlink => { - let mut data = vec![]; - rd.to_writer(&mut data)?; - let target = &Path::new(std::str::from_utf8(&data)?); - - tokio::fs::symlink(target, path).await?; - return Ok(()); - } - _ => { - warn!("{path:?}: unknown file type: {:?}", Type::from(mode)); - return Ok(()); - } - } - - chmod(path, mode).await?; - chown(path, Some(uid), Some(gid))?; - - Ok(()) -} - async fn mount(src: Option<&str>, dst: &str, fstype: &str, opts: Option<&str>) { if let Err(e) = fs::create_dir_all(dst).await { error!("failed to create dir {dst}: {e}");