Article 5KEH6 How to find all the related RPM packages of the path?

How to find all the related RPM packages of the path?

by
verilog15
from LinuxQuestions.org on (#5KEH6)
Hello,
A small background: I'm trying to mimic my linux environment to Singularity container and run my tool. I have a list of all the paths that construct my tool (needed for it to run). For each path, I want to find all related RPM packages and install them using Zypper.

So now the question - Basically, given a path, I'm trying to figure how to find all the RPM packages that are related to that path. For that I used:

rpm -qi --queryformat "[%{NAME}]" $example_path

It gives me the related package, if there is one. But I noticed that it is not enough and I should also check the shared libs of the path (if there are any). So I use the ldd command:

ldd $example_path

Then for each shared lib path I run the above RPM command to check for more packages. This strategy works pretty well but I want to avoid using the ldd command. I'm familiar with the following command:

rpm -q --requires $example_package

Which prints the dependencies, given a package (a not the a path). But I'm not sure how to parse the output. I also want it to be recursive in order to get all the required packages.

Let's do an example:

> rpm -qf --queryformat "[%{NAME}]" /bin/tcsh
tcsh
> ldd /bin/tcsh
linux-vdso.so.1 => (0x00007ffff7ffe000)
libncurses.so.5 => /lib64/libncurses.so.5 (0x00007ffff7d95000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007ffff7b59000)
libc.so.6 => /lib64/libc.so.6 (0x00007ffff77dd000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ffff75d9000)
/lib64/ld-linux-x86-64.so.2 (0x0000555555554000)
> rpm -qf --queryformat "[%{NAME}]" /lib64/libncurses.so.5
libncurses5
> rpm -qf --queryformat "[%{NAME}]" /lib64/libcrypt.so.1
glibc
> ldd /lib64/libcrypt.so.1
linux-vdso.so.1 => (0x00007ffff7ffe000)
libc.so.6 => /lib64/libc.so.6 (0x00007ffff7a26000)
/lib64/ld-linux-x86-64.so.2 (0x0000555555554000)

And so on. Recursively I will check all the paths. In that case I get: glibc,libncurses5,tcsh.

So to sum up:
1. How would you find all the packages that related to the path so there won't be any missing dependency inside the container? Please suggest a strategy or a set of commands that can be done to solve this challenge?
2. How to avoid using the ldd command and stick with the RPM command?
3. How can we use the above (rpm -q --requires $example_package) command for our advantage?
Thank you!

EDIT: I'll also mention that I read this article. It shows how to find the package of a path but it does not show to find all of them (for example for /usr/bin/nslookup, with the ldd strategy, I found: 'libcap2','libattr','krb5','glibc','keyutils-libs','bind-utils','libopenssl0_9_8','libxml2','zlib','libcom_err2','bind-libs').latest?d=yIl2AUoC8zA latest?i=QMwmLOn5iek:I-YCOMMo-R8:F7zBnMy latest?i=QMwmLOn5iek:I-YCOMMo-R8:V_sGLiP latest?d=qj6IDK7rITs latest?i=QMwmLOn5iek:I-YCOMMo-R8:gIN9vFwQMwmLOn5iek
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments