I'll try to explain what I'm trying to achieve. I have a file of paths that define my tool (all the needed paths to run my tool). I want to create a Dockerfile/Podman-file/Sing-file based on those dependencies so the container will be able to run the tool inside it. I want to find all the RPM packages of those paths. For that I use:
rpm -qf --queryformat "[%{NAME}]" [path]
But this command does not give me all the packages I need. I noticed that if I use
ldd [path] to get all shared libs and then for each lib, run the above RPM command, then I'll get all the needed packages.
So the my algorithm fow now is:
1. Run the above RPM command on the path and find related packages.
2. Run the ldd command on the path to find the shared libs.
3. For each shared lib path, repeat step 1 and step 2 (because shared lib can also have shared libs).
4. Keep track of all the paths that were already and stop once it's empty.
The algorithm works pretty well (until I came across with this special file). That way I will find all the related RPM packages. Now the problems:
1. I want to run step 2 only on dynamic files only (to prevent running ldd on all of the paths and it also solves
/proc/self/fd/1).
2. I'm familiar with the
file command. The problem with that command is that it's output is a syntax-based. Which means that I will have something like
if ($output =~ /dynamically linked/) # do stuff and if some output prints "not dynamically linked", it will be wrong. In other words, what I'm trying to say is that it's syntax-dependent.
Do you think that I need to parse the output of
file command? If so, what would be the best way to do it?
Also
ldconfig -p does not help me here since it gives me all the libs and not that are really being used.