crates.io docs.rs MSRV

RPM-RS

A pure rust library for parsing and creating RPM files.

Goals

Non Goals

RPM has a lot of cryptic features. I do not want to re-implement all of them. This library focuses on the ones that I assume as useful. This library does not build software like rpmbuild. It is meant for finished artifacts that need to be packaged as RPM.

Status

Examples

```rust use rpm::signature::pgp::{Signer, Verifier};

let rawsecretkey = std::fs::read("./testassets/secretkey.asc")?; // It's recommended to use timestamp of last commit in your VCS let sourcedate = 1600000000; let pkg = rpm::PackageBuilder::new("test", "1.0.0", "MIT", "x8664", "some awesome package") .compression(rpm::CompressionType::Gzip) .withfile( "./testassets/awesome.toml", rpm::FileOptions::new("/etc/awesome/config.toml").isconfig(), )? // file mode is inherited from source file .withfile( "./testassets/awesome.py", rpm::FileOptions::new("/usr/bin/awesome"), )? .withfile( "./testassets/awesome.toml", // you can set a custom mode and custom user too rpm::FileOptions::new("/etc/awesome/second.toml") .mode(rpm::FileMode::regular(0o644)) .user("hugo"), )? .preinstallscript("echo preinst") // If you don't need reproducible builds, // you can remove the following line .sourcedate(sourcedate) .buildhost(gethostname::gethostname().tostr().unwrapor("host")) .addchangelogentry( "Max Mustermann max@example.com - 0.1-29", "- was awesome, eh?", chrono::DateTime::parsefromrfc2822("Wed, 19 Apr 2023 23:16:09 GMT") .expect("Date 1 is correct. qed"), ) .addchangelogentry( "Charlie Yom test2@example.com - 0.1-28", "- yeah, it was", // Raw timestamp for 1996-08-14 05:20:00 840000000, ) .requires(rpm::Dependency::any("wget")) .vendor("corporation or individual") .url("www.github.com/repo") .vcs("git:repo=examplerepo:branch=examplebranch:sha=examplesha") .buildandsign(Signer::loadfromascbytes(&rawsecret_key)?)?;

pkg.write_file("./awesome.rpm")?;

// reading let rawpubkey = std::fs::read("/path/to/gpg.key.pub")?; let pkg = rpm::Package::open("testassets/389-ds-base-devel-1.3.8.4-15.el7.x8664.rpm")?;

let name = pkg.metadata.getname()?; let version = pkg.metadata.getversion()?; let release = pkg.metadata.getrelease()?; let arch = pkg.metadata.getarch()?;

println!("{}-{}-{}.{}", name, version, release, arch);

for changelog in pkg.metadata.getchangelogentries()? { println!("{}\n{}\n", changelog.name, changelog.description); }

// verifying pkg.verifysignature(Verifier::loadfromascbytes(&rawpubkey)?)?; ```