Ask Your Question
1

how to get dependencies from package name?

asked 2013-10-28 22:13:57 -0600

bioinfornatics gravatar image

updated 2014-09-28 12:08:47 -0600

mether gravatar image

Hi,

Actually i do:

 $ LANG=C yum deplist gtkd | grep -Po '(?<=^\s\sdependency: )[\w\-\.]+'  | sort -u

but sometime i got a libname instead the package where the lib come from.

I could to apply yum provides to each result which contain '.so'

but firstly i would like to know if there are not a better way?

Example of result with libname:

$ LANG=C yum deplist gtkd | grep -Po '(?<=^\s\sdependency: )[\w\-\.]+'  | sort -u
atk
cairo
gdk-pixbuf2
gstreamer
gstreamer-plugins-base
gtk2
gtksourceview2
ld-linux-x86-64.so.2
ld-linux.so.2
libc.so.6
libdl.so.2
libglade2
libm.so.6
libphobos-ldc.so.60
libpthread.so.0
librt.so.1
mesa-libGL
mesa-libGLU
pango
edit retag flag offensive close merge delete

Comments

1

You might also enjoy repoquery, if you aren't already aquainted. Depending on your purpose, you don't even need to parse out package names - yum install libphobos-ldc.so.60 will work just fine.

randomuser gravatar imagerandomuser ( 2013-10-30 00:26:29 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
5

answered 2013-10-29 06:57:15 -0600

remjg gravatar image

updated 2013-10-31 03:51:33 -0600

The output of yum deplist looks like this:

$ yum deplist gtkd
  ...
  dependency: librt.so.1()(64bit)
   provider: glibc.x86_64 2.18-11.fc20
  dependency: mesa-libGL
   provider: mesa-libGL.x86_64 9.2-1.20130919.fc20
   provider: mesa-libGL.i686 9.2-1.20130919.fc20
  dependency: mesa-libGLU
   provider: mesa-libGLU.x86_64 9.0.0-3.fc20
   provider: mesa-libGLU.i686 9.0.0-3.fc20
   ...

Since the dependency line can give a library and not a package name, I would only keep the provider lines with grep provider.

$ yum deplist gtkd | grep provider
   ...
   provider: glibc.x86_64 2.18-11.fc20
   provider: mesa-libGL.x86_64 9.2-1.20130919.fc20
   provider: mesa-libGL.i686 9.2-1.20130919.fc20
   provider: mesa-libGLU.x86_64 9.0.0-3.fc20
   provider: mesa-libGLU.i686 9.0.0-3.fc20
   ...

Then I remove the string "provider:", the extra spaces before and after, and I keep the word just following using sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" for example:

$ yum deplist gtkd | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/"
...
glibc.x86_64
mesa-libGL.x86_64
mesa-libGL.i686
mesa-libGLU.x86
mesa-libGLU.i686
...

I can now keep everything before the last period with sed "s/\(.*\)\.[^\.]*/\1/":

$ yum deplist gtkd | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" | sed "s/\(.*\)\.[^\.]*/\1/"
...
glibc
mesa-libGL
mesa-libGL
mesa-libGLU
mesa-libGLU
...

And I sort as you do removing the duplicates with sort -u:

$ yum deplist gtkd | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" | sed "s/\(.*\)\.[^\.]*/\1/" | sort -u
atk
cairo
gdk-pixbuf2
glibc
gstreamer
gstreamer-plugins-base
gtk2
gtksourceview2
libglade2
mesa-libGL
mesa-libGLU
pango

Edit: I have updated the answer according to @marcindulak remark, so it can now work with dependencies whose name contains a dot:

$ yum deplist icedtea-web | grep provider | sed "s/[ ]*provider:[ ]*\([^ ]*\).*/\1/" | sed "s/\(.*\)\.[^\.]*/\1/" | sort -u
bash
chkconfig
glib2
glibc
java-1.7.0-openjdk
libgcc
libstdc++
mozilla-filesystem
edit flag offensive delete link more

Comments

2

LC_ALL=C yum deplist gtkd | grep provider | cut -d: -f2 | cut -d. -f1 | LC_ALL=C sort | uniq

marcindulak gravatar imagemarcindulak ( 2013-10-29 07:14:52 -0600 )edit

Your answer is way easier than mine. I didn't know cut! Why do you use LC_ALL=C?

remjg gravatar imageremjg ( 2013-10-29 07:25:56 -0600 )edit
1

One needs LC_ALL=C because sort and many other commands may behave differently depending on locale

marcindulak gravatar imagemarcindulak ( 2013-10-29 08:35:14 -0600 )edit

That makes sense, thank you for your answer.

remjg gravatar imageremjg ( 2013-10-29 08:43:28 -0600 )edit
2

answered 2013-10-30 05:36:24 -0600

marcindulak gravatar image

updated 2013-10-30 05:37:07 -0600

I have noticed that the first answer does not produce correct results when dependencies have dot (.) in the package name, like java-1.7.0-openjdk dependency for icedtea-web:

LC_ALL=C yum deplist icedtea-web | grep provider | cut -d: -f2 | awk '{print $1}' | rev | cut -d. -f2- | rev | LC_ALL=C sort | uniq

Here the idea is to rev the characters in the dependency name, chop off the reverted "extensions" (.x86_64 -> 46_68x., .i686 ->686i., ...) from the beginning of the name by cut -d. -f2- and rev the dependency name back.

edit flag offensive delete link more

Comments

Indeed, I have updated my answer to take into account your remark. I like your answer, it is much more readable than mine!

remjg gravatar imageremjg ( 2013-10-31 03:54:59 -0600 )edit

Question Tools

Stats

Asked: 2013-10-28 22:13:57 -0600

Seen: 1,655 times

Last updated: Oct 31 '13