It supports RPM 4.8.0 or later.
dependencies: rpm: github: lugia-kun/crystal-rpm
The development files (pkg-config file) of RPM is
required. Typically, it can be installed by
yum install rpm-devel on
CentOS or Red Hat,
dnf install rpm-devel on Fedora, and
zypper in rpm-devel on openSUSE or SLES.
pkg = RPM::Package.open("foobar-1.0-0.x86_64.rpm") puts pkg[RPM::Tag::Name] # => "foobar" puts pkg[RPM::Tag::Arch] # => "x86_64" puts pkg[RPM::Tag::Summary] # => (Content of Summary) # and so on... pkg.requires # => Array of Requires. pkg.provides # => Array of Provides. pkg.conflicts # => Array of Conflicts. pkg.obsoletes # => Array of Obsolstes.
RPM.transaction do |ts| path = "pkg_to_install-1.0-0.x86_64.rpm" pkg = RPM::Package.open(path) begin ts.install(pkg, path) # Add installation package. Package path is required. ts.commit # Run Transaction ensure ts.db.close # must close Database. end end
# with given name RPM.transaction do |ts| iter = ts.init_iterator # Create iterator of installed packages # Set condition iter.regexp(RPM::DbiTag::Name, # <= Entry to search (here, Name) RPM::MireMode::DEFAULT, # <= Default matching method "simple") # <= Name to search # Iterate over matching packages. iter.each do |pkg| puts pkg[RPM::Tag::Version].as(String) # => (Version of package "simple") end end # Iterate over all installed packages RPM.transaction do |ts| iter = ts.init_iterator iter.each do |pkg| # ... iterates over all installed packages. end end
Currently, the following code does not work unless you are using OpenSUSE (see #1).
RPM.transaction do |ts| begin ts.delete(pkg) # Add to removal package ts.order ts.clean ts.commit # Run Transaction ensure ts.db.close # must close Database. end end
ts = RPM::Transaction.new begin ts.install(...) ts.delete(...) ts.order ts.clean ts.commit ensure ts.db.close end ts.finalize # Not nesseary, but recommended.
RPM.transation do |ts| ts.install(...) ts.order ts.clean problems = ts.check problems.each do |problem| puts problem.to_s # => Output install (typically dependency) problems. end end
spec = RPM::Spec.open("foo.spec") packages = spec.packages packages[RPM::Tag::Name] # => (Name of the first package) packages[RPM::Tag::Name] # => (Name of the second package) # NOTE: The order is undefined. spec.buildrequires # => Array of BuildRequires.
spec = RPM::Spec.open("foo.spec") spec.build
The definitiions of structs are written by hand. Tests can check their size and member offsets if you have a C compiler (optional).
fakechroot (recommended) or root permission (i.e.,
required to run
crystal spec, since this spec uses
Alternatively, using Docker is another method to test:
$ shards install $ docker build -t [version] -f .travis/Dockerfile.rpm-[version] . $ docker run -v $(pwd):/work -w /work [version] crystal spec
Note that shards should be installed on local (because git in CentOS 6 is too old and does not work with shards).
git checkout -b my-new-feature)
git commit -am 'Add some feature')
git push origin my-new-feature)