5

How to a detect if a RPM is a source rpm or a binary rpm?

Obviously I do not want to rely on the file name.

sorin
  • 161,544
  • 178
  • 535
  • 806

4 Answers4

4

Source rpms are defined by the presence of the SOURCERPM tag in the header. If an rpm has a SOURCERPM tag, it means the rpm is a binary rpm (the SOURCERPM tag says what srpm was used to build the binary rpm). If there is no SOURCERPM tag, then the rpm is an srpm.

I'm not sure if this is any kind of "official" definition of an srpm, but it is the logic that rpmbuild and other utilities currently use to determine if a given rpm is an srpm or not in the reference rpm implementation (see headerIsSource() in lib/headerutil.c). So it seems pretty reasonable.

Here is a way to check if the SOURCERPM tag exists in an rpm using the rpm command-line utility:

$ rpm --query --package foo-1.2.3-1.src.rpm \
      --queryformat "%|SOURCERPM?{binary-rpm}:{source-rpm}|\n"
source-rpm
$ rpm --query --package foo-1.2.3-1.el7.x86_64.rpm \
      --queryformat "%|SOURCERPM?{binary-rpm}:{source-rpm}|\n"
binary-rpm
adeason
  • 155
  • 6
1

Source rpm contains actual source code and patch files for Linux application. All source rpm file has src.rpm extension

if you use RPM on an Intel-based computer, you'd normally expect to find i386 there. If you use x86_64 bit computer you will see x86_64 in RPM file names. Normal rpm file has only binary files and no source code at all.

The following link helped me regarding source vs binary RPM

EDIT:

  • Check an RPM Signature Package

rpm --checksig file

  • Display Package Information

rpm -qi file

I think there is no built in tool for this purpose. Utilize RPM related commands, or you may create a shell script as a tool to check any time (It may save your time).

Md Mahbubur Rahman
  • 2,065
  • 1
  • 24
  • 36
  • I was looking for a way to extract this information from the rpm file, like `rpm` tool or something similar. – sorin Sep 25 '12 at 15:25
  • 1
    @sorin I have edited my answer as your comment. I think there is no built in tool for this purpose. Utilize RPM related commands, or you may create a shell script as a tool to check any time (It may save your time). – Md Mahbubur Rahman Sep 25 '12 at 15:39
0

I don't believe there any definitive way to do what you want, though you may be able to apply some heuristics to make a reasoned guess.

  1. Use rpm -qi -p rpmfilename and look to see if there's a "Source RPM:" value.

  2. Use rpmls from the rpmdevtools package. Based solely on inspecting output, SRPMS appear to contain a .tar.gz or .tar.bz2 and a .spec file.

I think this will get you close to an answer, but it won't be definitive. Whether or not this is sufficient will depend on how important being exactly correct is in your situation.

Chris Cleeland
  • 4,760
  • 3
  • 26
  • 28
0

rpm -qlp rpmfilename | grep -c /usr/src/redhat would give a count of how many source files it includes (usually the source archive, a spec file, and a handful of patches). If you are doing it programmatically, grep -q would return match or no match.

Aaron D. Marasco
  • 6,506
  • 3
  • 26
  • 39