RPM-RS
A pure rust library for parsing and creating RPM files.
Goals
- Easy to use API
- Pure rust to make it easy to use in larger Projects
- Independence of Spec files. Pure programmatic interface for Packaging.
- Compatibility from Enterprise Linux 8 (RHEL, Alma, Rocky, CentOS Stream) to Fedora (I may extend test cases for SUSE)
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
- RPM Creation
- Basic RPM Reading
- RPM Signing and Signature Verification
- High Level API for RPM Reading
Examples
Read package and access metadata
use ;
let pkg = open?;
let name = pkg.metadata.get_name?;
let version = pkg.metadata.get_version?;
let release = pkg.metadata.get_release?;
let arch = pkg.metadata.get_arch?;
println!;
for changelog in pkg.metadata.get_changelog_entries?
Sign existing package and verify package signature
use ;
let signer = from_asc_file?;
let verifier = from_asc_file?;
let mut pkg = open?;
pkg.sign?;
pkg.write_to?;
let pkg = open?;
pkg.verify_signature?;
Sign with a specific subkey
use Signer;
let subkey_fingerprint = decode?;
let signer = from_asc_file?
.with_signing_key?;
let mut pkg = open?;
pkg.sign?;
Verify using a keyring with multiple certificates
use Verifier;
// Keyring files containing multiple OpenPGP certificates are supported.
// The verifier will try each certificate until it finds one that matches.
let verifier = from_asc_file?;
let pkg = open?;
pkg.verify_signature?;
// You can also narrow down to a specific certificate by fingerprint:
let verifier = from_asc_file?
.with_key?;
Inspect package signatures
use SignatureVersion;
let pkg = open?;
for sig in pkg.signatures?
Build new package
use Signer;
// For reproducible builds, set source_date to the timestamp of the last commit in your VCS
let build_config = default
.compression
.source_date;
let signer = from_asc_file?;
let pkg = new
.using_config
// set default ownership and permissions for files and directories, similar to %defattr
// in an RPM spec file. Pass None for any field to leave it unchanged (like `-` in %defattr).
.default_file_attrs
.default_dir_attrs
// add a file with no special options
// by default, files will be owned by the "root" user and group, and inherit their permissions
// from the on-disk file.
.with_file?
// you can set permissions, capabilities and other metadata (user, group, etc.) manually
.with_file?
// Add a file - setting flags on it equivalent to `%config(noreplace)`
.with_file?
// symlinks don't require a source file
.with_symlink?
// directories can be created with explicit ownership and permissions
// this does not add any directory contents, just declares a directory
.with_dir_entry?
// ghost files / directories are not included in the package payload, but their metadata
// (ownership, permissions, etc.) is tracked by RPM. This is commonly used for files
// created at runtime (e.g. log files, PID files).
.with_ghost?
.pre_install_script
// Alternatively, use scriptlet builder api to specify flags and interpreter/arguments
.post_trans_script
.build_host
.add_changelog_entry
.add_changelog_entry
.requires
.vendor
.url
.vcs
.build_and_sign?;
// Write to a specific file
pkg.write_to?;
// Or write to a directory with auto-generated filename (`target/awesome-0.1.0-1.x86_64.rpm`)
pkg.write_to?;