5 个版本

0.12.2 2023 年 10 月 7 日
0.12.1 2023 年 8 月 2 日
0.0.3 2023 年 2 月 8 日

#4#rpm

Download history 19/week @ 2024-03-14 2/week @ 2024-03-21 12/week @ 2024-03-28 11/week @ 2024-04-04 3/week @ 2024-04-11 2/week @ 2024-04-18 4/week @ 2024-04-25 5/week @ 2024-05-02 27/week @ 2024-05-09 24/week @ 2024-05-16 24/week @ 2024-05-23 27/week @ 2024-05-30 23/week @ 2024-06-06 17/week @ 2024-06-13 17/week @ 2024-06-20 9/week @ 2024-06-27

69 每月下载次数

Apache-2.0 或 MIT

265KB
4.5K SLoC

crates.io docs.rs MSRV

RPM-RS

用于解析和创建 RPM 文件的纯 Rust 库。

目标

  • 易于使用的 API
  • 纯 Rust 编写,便于在大型项目中使用
  • 与 Spec 文件独立。包装的纯编程接口。
  • 兼容 CentOS 7 / Fedora(我可能还会扩展 SUSE 的测试用例)

非目标

RPM 有很多晦涩的功能。我不想重新实现所有这些功能。这个库专注于我认为有用的功能。这个库不构建像 rpmbuild 这样的软件。它用于需要作为 RPM 打包的成品。

状态

  • RPM 创建
  • 基本 RPM 读取
  • RPM 签名和签名验证
  • RPM 读取的高级 API

示例

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

let raw_secret_key = std::fs::read("./test_assets/secret_key.asc")?;
// It's recommended to use timestamp of last commit in your VCS
let source_date = 1_600_000_000;
let pkg = rpm::PackageBuilder::new("test", "1.0.0", "MIT", "x86_64", "some awesome package")
    .compression(rpm::CompressionType::Gzip)
    .with_file(
        "./test_assets/awesome.toml",
        rpm::FileOptions::new("/etc/awesome/config.toml").is_config(),
    )?
    // file mode is inherited from source file
    .with_file(
        "./test_assets/awesome.py",
        rpm::FileOptions::new("/usr/bin/awesome"),
    )?
    .with_file(
        "./test_assets/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"),
    )?
    .pre_install_script("echo preinst")
    // If you don't need reproducible builds,
    // you can remove the following line
    .source_date(source_date)
    .build_host(gethostname::gethostname().to_str().unwrap_or("host"))
    .add_changelog_entry(
        "Max Mustermann <[email protected]> - 0.1-29",
        "- was awesome, eh?",
        chrono::DateTime::parse_from_rfc2822("Wed, 19 Apr 2023 23:16:09 GMT")
            .expect("Date 1 is correct. qed"),
    )
    .add_changelog_entry(
        "Charlie Yom <[email protected]> - 0.1-28",
        "- yeah, it was",
        // Raw timestamp for 1996-08-14 05:20:00
        840_000_000,
    )
    .requires(rpm::Dependency::any("wget"))
    .vendor("corporation or individual")
    .url("www.github.com/repo")
    .vcs("git:repo=example_repo:branch=example_branch:sha=example_sha")
    .build_and_sign(Signer::load_from_asc_bytes(&raw_secret_key)?)?;

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

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

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!("{}-{}-{}.{}", name, version, release, arch);

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

// verifying
pkg.verify_signature(Verifier::load_from_asc_bytes(&raw_pub_key)?)?;

依赖项

~7–16MB
~206K SLoC