How find file in RPM file - linux

I was looking for a file with a gpg extension, and when I do grep gpg */*, it looks like it's in the rpm file. I'm trying to locate it, but I'm not finding it.
I tried rpm -qpl Directory/filename.rpm, but it's not listing the gpg file. It must be in a subdirectory so it's not turning up.
Does anyone know a good way to get it to list the subdirs out in the rpm, so I can find the gpg file?

you can list all files in a rpm with:
rpm -qlp mypackage.rpm
If you need to extract the rpm:
rpm2cpio mypackage.rpm | cpio -idv

Related

Removing paths from .so files so that RPM check-buildroot succeeds

I am packaging some Python libraries as RPMs. Some of the libraries are only available as source distributions (no wheels).
In my RPM spec I do:
pip install --root=%{buildroot} --prefix=/x/y tornado
When rpmbuild finishes up it runs check-buildroot, and the build fails with errors like:
Binary file /a/b/c/BUILDROOT/my-rpm-1.0.0-1.el7.x86_64/x/y/lib64/python2.7/site-packages/tornado/speedups.so matches
I see the %{buildroot} path listed if I run strings tornado.so | grep BUILDROOT.
How can I sanitize the .so files? Or more generally, how can I make check-buildroot pass?
I figured out how to remove the paths from the SO files.
I determined that the paths were embedded debug information using this command:
readelf --debug-dump=line speedups.so | less
The strip command can remove debug information from SO files, so I added this to my RPM spec:
BuildRequires: binutils
set +e
find "%{buildroot}{%_prefix}/lib64/python2.7/site-packages" -type f -name "*.so" | while read so_file
do
strip --strip-debug "$so_file"
done
set -e
Note: strip segfaults on some SO files, and it's not clear why. I disabled immediate exits with set +e so that the build ignores them.

Backup installed RPM packages with tar

I would like to have a back-up of all RPMs installed in the system that have the keyword kernel.
So far, this is what I have:
RPMS=$(rpm -qa | grep kernel-firmware)
echo "$RPMS" | xargs -I '{}' rpm -ql '{}' | xargs tar cfz "$RPMS".tgz
This is for just one package, which works well. When I grep for kernel, things do not work as expected.
I wish to have each archive with the original package's name.
EDIT
I haven't been clear enough. I'm trying to back-up packages which are already installed. I do not have the RPM src files nor the original packages. I wish to do this to be able to rollback some old machines after kernel updates, or just simply be able to move the packages on another machine.
I know this is not the proper way to do it, and once they are extracted like this, they are no longer packages, but simple tarballs. However, this should suffice for what I wish to accomplish.
As can been seen from the above commands, I'm using rpm -qa | grep kernel to query the RPM DB for all of the packages which have kernel in their name. I then wish to use rpm -ql pacakge-name to to list all of the files on the system and pass them to tar to be able to easily move them to another machine.

Passing user defined argument to RPM is possible while installing?

Passing User defined argument to RPM is possible while installing?.
for example:
~>rpm -i sample.rpm -license_path=/path/
or
~>rpm -i -license_path=/path/ sample.rpm
or
~>rpm -i -somearg sample.rpm
-Sakthi
RPMs aren't meant to take user defined arguments.
See RPM - Install time parameters
Another similar question is at https://superuser.com/questions/408852/is-it-possible-to-get-users-input-during-installation-of-rpm
One workaround is to have the rpm's postinstall script ask for input from stdin, in which case you can pass in the answers by redirecting stdio from a file or here document.
>rpm -i sample.rpm <<__NOT_RECOMMENDED__
somearg
__NOT_RECOMMENDED__
It looks like you are trying to create a relocatable RPM.
In the preamble of your .spec file, put the prefix of the file path that can be relocated.
For example, if the full path to your file is
/base/path/to/my/file
then /base can be changed during RPM installation but /path/to/my/file will remain the same.
Here's what you put in your .spec file:
#Preamble: Summary, Name, etc.
Prefix: /base
Ensure that you mention this prefix while listing all relocatable files in the %install and %files sections in the .spec file. There are conditions where a relocatable RPM may not work, so check out these things to consider as well.
%files
%{prefix}/path/to/my/file
Now when you install the RPM, you can specify a different prefix.
rpm -i sample.rpm --prefix /tmp
This will install the file in /tmp/path/to/my/file.

how to update a pre-existing config file using rpmbuild?

I've been looking into how to use an rpmbuild spec file to update an already existing config file.
As an example, in my rpm I'd like to add lines to a config file e.g. /etc/stunnel/stunnel
[SomeAppName]
accept = 8006
connect = 127.0.0.1:5006
I've currently got this in my %install section:
cat stunnel/stunnel.conf >> %{buildroot}/etc/stunnel/stunnel.conf
Now clearly this is rubbish because each time I run the rpm it will add these same lines to the config file.
I also don't want the /etc/stunnel/stunnel.conf file to be part of my rpm as I don't want it removed when I erase my rpm package.
My questions are:
How can I exclude the /etc/stunnel/stunnel.conf from being part of my rpm?
What is the correct way to add lines to a config file during an rpm?
Please could someone provide some links where I can see how to get this working or example of a few lines that I can use in my spec file.
I've look at the official guide over at Max Rpm but so far I've not found the answer to my issue.
a) Many more modern tools also support a .d configuration directory parallel to flat files for this exact reason. For example, my Debian wheezy distribution treats /etc/stunnel as a directory in which each .conf file is a separate stunnel configuration.
b) The established alternative seems to be a conditional construct like
grep -q '[SomeAppName]' %{buildroot}/etc/stunnel/stunnel.conf || cat ...
(or, if not sure if stunnel.conf already exists)
grep -s '[SomeAppName]' %{buildroot}/etc/stunnel/stunnel.conf || cat ...

View RPM scripts with rpm --scripts -qp

When I run rpm -qlp I get the file contents of the RPM as you can see below, but when I run rpm --scripts -qp CBS0.0.0_10.0.i386.rpm I get the scripts' contents, but not their filename.
My question is why can't I see the script names in the RPM contents (ie, where does the script s come from?)
$ rpm -qlp CS0.0.0_10.0.i386.rpm
/home/thy_diff/rt
/home/thy_diff/rt/Cerse-zip
/home/thy_diff/rt/Configure_rht.properties
/home/thy_diff/rt/UFE_Install.sh
/home/thy_diff/M_client
/home/thy_diff/M_client/Crse-CLIENT.zip
/home/thy_diff/M_client/Configure_client.properties
/home/thy_diff/M_client/UF_Install.sh
AFAIK scripts are part of RPM package meta-data, there are no files for scripts. The commands of scripts are written directly into spec-file just next to other meta-data like "description" or "license".
For example, see here the %post section. It contains a script of a single command. I believe all other scripts are written just the same.
Try with following command:
rpm -qlp --scripts CS0.0.0_10.0.i386.rpm
You can see the script contents

Resources