3

I have reviewed several related questions - the closest being: Extract the spec file out of an RPM -- AND I must add I would have phrased my question the same way. However, it seems the .spec file is not in the .rpm file (when it is a binary package).

So, my question is: how to get the information that originated in a spec file - at least as much as possible.

  • I know there is a command to list the contents of the .rpm (at least two actually - rpm2cpio xxx.rpm | cpio -itv being one
  • other commands to get what is required
  • in particular: WHAT command(s) to get the pre/post/etc scripts that are run as part of the install process.

Ideally, the answer is a single command - but if it must be several commands, c'est la vie.

p.s. I have examined rpmbuild --rebuild (says it expects source RPM) and cannot locate rpmlint

Thank you.

2 Answers 2

6

Yes the rpm SPEC is not part of packaged RPM. However, you can query the RPM package for information which was present in the SPEC file.

For example:

1) Following command will give you the pre/post scripts which are executed when RPM package is installed or updated.

rpm -q --scripts (installed RPM name, this name will be without the .rpm extension)
rpm -qp --scripts (if you have a rpm file)

2) You can look at specific information present in the SPEC file, using the --queryformat option of rpm command.

rpm -q --queryformat '%{ARCH} %{NAME}\n' (RPM name, if it installed)
rpm -qp --queryformat '%{ARCH} %{NAME}\n' (if you have an RPM file)

Above will give the Architecture for which the RPM is designed and the actual name of the RPM. These information go in specific sections of the SPEC file, like Name, Arch, Requires(pre), Requires(post), BuildRequires etc. For valid query options check this link

1
  • 1
    Thanks - I was almost getting there. :) - was about to comment that rpm -q --scripts only worked for something already installed. And you gave the complete answer. Good to know I can also get the script info from what is already installed and/or document that there were/are none! Thanks! Dec 7, 2016 at 17:51
0

There is no way extract the build instructions that created an rpm unless you have the source rpm that generated that rpm.

If the rpm in question comes from official repos, you can enable the corresponding source repositories in your /etc/yum.repos.d (for RHEL/CentOS) folder, and then download the source rpms via yum. (You can do similar for DNF/Zypper/etc.)

3
  • I was not looking specifically for the build instructions - my concern is the install phase and the pre-/post- scripts - at a minimum. Dec 7, 2016 at 17:53
  • 1
    Ah, I missed that part of your question, sorry.
    – jayhendren
    Dec 7, 2016 at 17:55
  • 1
    Well, you did verify something I suspected to be true - the spec file is not there! Thanks! Dec 7, 2016 at 18:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .