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.
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
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:
rpm --checksig file
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).
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.
Use rpm -qi -p
rpmfilename and look to see if there's a "Source RPM:" value.
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.
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.