问题原文
原帖链接 · nolandda · CC BY-SA 4.0
I am working on a non-redhat based machine and I need to extract Version: x.y.z and Release: a.b.c information from some .rpms that pass across the machine.
Typically one would do:
rpm -qip ./Foo.x.y.z.rpm | grep Version | awk ...
But this isn't a redhat-based machine so I don't have rpm and I don't really want to install a 2nd package manager anyway.
I thought that if I did:
rpm2cpio ./Foo.x.y.z.rpm | cpio -idmv
Then when the cpio was extracted I would find some file named .preamble or something that would have the data in it. But no luck. Anyone know another way?
已采纳解答
原帖链接 · John Mahowald · CC BY-SA 4.0
rpm2cpio use case is to extract files without the metadata, the opposite of what you want. It like other tools requires linking against librpm. Even Midnight Commander exploring an rpm file uses the rpm binary.
On an system with yum, use createrepo to create a repository from these rpms. XML and sqlite will be generated with the metadata. While easier to parse than the rpm binary format, you will have to write the queries yourself if you are not using yum. Keep the repodata so you have a functional yum repo.
Going up yet another level of abstraction, systems lifecycle tools include content management. Namely, Katello or Red Hat Satellite. A bit heavyweight compared to a shell script, but you can get hosts and the packages they subscribe to with an API.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
