extract the spec file from rpm package
Asked Answered
F

8

45

Is there any way to extract the spec file from rpm package ( I have only RPM file )

not by

   rpm --scripts -qp my-great-app-1.1.2.rpm 

( this syntax not get the spec file only the scripts from the rpm)

Fecal answered 10/4, 2011 at 18:50 Comment(10)
are you sure the spec file is stored in the RPM? In a .src.rpm, certainly, but for a normal RPM i'm not certain about that at all.Door
so if I have only rpm file where I can get the spec file , please helpFecal
look for the source RPM, or that package's homepage.Door
I have only rpm file not sourceFecal
The spec file is useless without the source - it's only reason to exist is to be able to create the rpm from the source. What are you trying to achieve? What package is this?Door
I need to fix some of the scripts in the rpm then I need to pack the rpm again , in the spec I need to update the version .etc , so what to do , its urgunt and I need to finish this task until 24:00Fecal
find the spec, rebuild it using your knowledge of the package, look at the rpm with an editor to find all the scriptlets/dependencies you can extract, etc...Door
give me example how to do that , how with vi ? I see in the rpm many characters and Chinese word , I cant find the spec in this way -:(Fecal
Something here not acceptable , I need to update the rpm pkg file and its obvious that I need also to update the spec file and the rebuild again the rpm , but I not have the spec file I have only rpmFecal
@Fecal i stuck with the same situation,did you succeeded to get spec file of any rpm ?Berner
M
30

Install rpmrebuild and "extract" (actually re-create) the spec file of your rpm file or your already installed package.

Examples:

rpmrebuild --package --notest-install -e oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
rpmrebuild -s hercules.spec hercules
Mayonnaise answered 5/1, 2013 at 4:6 Comment(2)
Looking at rpmrebuild's code and then actually testing it, it doesn't "extract" the spec file; it regenerates most of a spec file (header, log, pre/post scripts). But, critically to rebuilding, it doesn't actually get the %prep or %build sections; it just leaves those at their default values (which are "make clean" and "make install," respectively). I suspect this is because /that/ information is not stored in RPMs. So, while this should work in the most general cases, it doesn't look like it will universally work (esp. for packages with complex compilation steps). :/Georgie
dannysauer: sure, actually it is no extraction because it is a rebuild of the spec file ("extract" was the question). The spec is not part of the RPM package and therefore the rebuild is the only way to get a "spec template". But this could be a good starting point in many cases. In the past it helped me sometimes to fix binary rpm packages.Mayonnaise
G
16

The spec file is not stored in binary rpms unless the packager specifically included it for some reason (and there's really no reason to do that). The only information you can get from a binary rpm is the information that rpm -qi <package> returns, and the files that rpm -ql <package> lists. If you need more than that, you have to find the source package. If Google / the vendor's web site fails to provide that for you, there should be contact information provided in the Packager field for anything packaged by anyone competent. For example, here's a package that ships with RHEL and a package from a third party vendor:

$ rpm --qf '%{Packager}\n' -q redhat-release
Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
$ rpm --qf '%{Packager}\n' -q cfengine-community
CFEngine AS ([email protected])

There you have a website and an email address, respectively, where you could ask about a spec file or srpm file.

Georgie answered 28/9, 2011 at 18:54 Comment(0)
R
11

spec files are usually not in rpm. They are in source rpm.

Revolutionize answered 10/4, 2011 at 19:35 Comment(4)
can I rebuild again the rpm without the spec file?Fecal
@jon: AFAIK, it's not possible to "build" it. But, I think, you can just write a spec file with just an install section by looking at the files packaged in the binary rpm.Revolutionize
"by looking at the files packaged in the binary rpm" please explain?Fecal
So how do you extract them from srpm?Telemachus
S
10

you could use

yumdownloader --source < something.rpm

then:

rpm2cpio packagename | cpio -ivd
Sines answered 4/5, 2012 at 2:14 Comment(3)
That only gets the files that will be installed, not the spec file.Tritheism
rpm -i pkg.src.rpm will extract it to the rpmbuild directoryKohima
The question is not about the source rpm but the binary rpm. If the OP would have the src.rpm then it would be easy and he would not ask this question.Mayonnaise
A
10

Per @RumpleStiltskin's answer, the original spec files are found in source rpms which can be extracted. To get the source rpms, run the following:

yum install yum-utils # Only required if yumdownloader is not installed
yumdownloader --source <package name, like 'emacs-nox'>

This will install the package to the current directory. To extract it run:

rpm2cpio <package name>.src.rpm | cpio -civ '*.spec'

The .spec file will be in your current directory.

If you can't install yum-utils for some reason, look at the files in /etc/yum.repos.d/ and look for sections referring to source rpm repositories. You can type in the values for baseurl into your browser and manually search for the source package. Extracting the .spec still requires rpm2cpio.

Admissible answered 19/10, 2017 at 22:15 Comment(0)
H
9

rpmrebuild is your friend. Use

rpmrebuild -e -p <rpm_file>

As it opens up the spec file in an editor, you can also make changes to rpm spec.

Have answered 18/2, 2015 at 20:18 Comment(0)
A
0

only src.rpm package , the source package, have the spec file

without src.rpm is difficult or almost impossible rebuild the package , for example rpm package provide by plesk for Linux , you can't extract neither the spec file neither the sources .

nowadays , in Fedora Linux you got rpmdevtools package , you can extract the files of one rpm, easily with rpmdev-extract

Amend answered 15/3 at 0:41 Comment(0)
S
-3

I could get all my .spec, source, Patches by this simple command

$ rpmbuild --recompile --noclean ./SRPMS/somerpm.src.rpm

Now one can change spec, src and rebuild RPM or SRPM.

Subarid answered 5/6, 2019 at 12:50 Comment(1)
This does NOT answer the question. It was clearly stated: "I have only RPM file"Mayonnaise

© 2022 - 2024 — McMap. All rights reserved.