Page 1 of 1

realdep - moar dependency

Posted: Thu Feb 04, 2016 12:04 pm
by machinebacon
realdep shows the next level dependencies of dependencies. "WTF" you ask? Here is the answer:

imagine you check the dependency count of a certain package you want to install, usually you use apt-cache depends <package>, like for xterm:

Code: Select all

xterm
  Depends: xbitmaps
  Depends: libc6
  Depends: libfontconfig1
  Depends: libice6
  Depends: libtinfo5
  Depends: libutempter0
  Depends: libx11-6
  Depends: libxaw7
  Depends: libxft2
  Depends: libxmu6
  Depends: libxpm4
  Depends: libxt6
  Recommends: x11-utils
  Suggests: xfonts-cyrillic
This does not show you the next dependency level. Using the realdep script, the output gets a bit more verbose:

Code: Select all

xterm depends on:
 xbitmaps
 libc6
 libfontconfig1
 libice6
 libtinfo5
 libutempter0
 libx11-6
 libxaw7
 libxft2
 libxmu6
 libxpm4
 libxt6
xbitmaps depends on: 
libc6 depends on: 
 libgcc1
libfontconfig1 depends on: 
 fontconfig-config
 libc6
 libexpat1
 libfreetype6
 multiarch-support
libice6 depends on: 
 libc6
 multiarch-support
 x11-common
libtinfo5 depends on: 
 libc6
libutempter0 depends on: 
 libc6
libx11-6 depends on: 
 libc6
 libx11-data
 libxcb1
 multiarch-support
libxaw7 depends on: 
 libc6
 libx11-6
 libxext6
 libxmu6
 libxpm4
 libxt6
libxft2 depends on: 
 libc6
 libfontconfig1
 libfreetype6
 libx11-6
 libxrender1
 multiarch-support
libxmu6 depends on: 
 libc6
 libx11-6
 libxext6
 libxt6
libxpm4 depends on: 
 libc6
 libx11-6
 multiarch-support
libxt6 depends on: 
 libc6
 libice6
 libsm6
 libx11-6
So here is the script:

Code: Select all

#!/bin/sh

PKG=$@
DEPLIST=/tmp/deplist.$$$
NEXTDEPLIST=/tmp/nextdeplist.$$$

apt-cache depends $PKG | grep epends | gawk -F: '{ print $2 } ' | sed '/^$/d' > $DEPLIST

printf "$PKG depends on:\n"
cat $DEPLIST

for line in $(cat $DEPLIST); do
    apt-cache depends $line | grep epends | gawk -F: '{ print $2 } ' | sed '/^$/d' | tr -d '<>' | sort -u | uniq > $NEXTDEPLIST
    printf "$line depends on: \n"
        cat $NEXTDEPLIST
done
It does not iterate through the second dependency level, because in (literally) all of the cases you will arrive at libc6 or libgcc1.

Re: realdep - moar dependency

Posted: Thu Feb 04, 2016 12:11 pm
by franksinistra
wonder why i never thought of creating useful thing like this.... mucho thanks MB!

Re: realdep - moar dependency

Posted: Thu Feb 04, 2016 12:17 pm
by machinebacon
^ you can have a try and write a function that puts the depends into an array, prints the dependencies, then repeats it again until there's nothing left ;)

some (if not all) of dpkg is written in Perl, maybe it lends itself as a better option than a shell script.

Re: realdep - moar dependency

Posted: Thu Feb 04, 2016 12:29 pm
by ivanovnegro
Insanely good.

Re: realdep - moar dependency

Posted: Thu Feb 04, 2016 12:47 pm
by rhowaldt
great! - is this different from the bloat-script i once made? yeah it is, right? that didn't go as deep, iirc...

Re: realdep - moar dependency

Posted: Thu Feb 04, 2016 1:53 pm
by machinebacon
^ I was thinking about that, too -- IIRC it checks which packages share dependencies.

Re: realdep - moar dependency

Posted: Fri Feb 05, 2016 7:22 am
by rhowaldt
yeah, something like that. i think i made it so you could see the impact it would have on your system. so relative bloat only, where it says "this will pull in this dependency list, but of those deps you already have this this and this on your system so its not as bad as it seems"

Re: realdep - moar dependency

Posted: Fri Feb 05, 2016 7:27 am
by wuxmedia
nice work.

Re: realdep - moar dependency

Posted: Fri Feb 05, 2016 8:10 am
by Snap
Great. Thank you.

Re: realdep - moar dependency

Posted: Fri Feb 05, 2016 7:44 pm
by Theo
Funny I was thinking about something like this the otherday and now it's here :)
A big thank you!

Re: realdep - moar dependency

Posted: Fri Feb 05, 2016 7:54 pm
by machinebacon
This version just cleans up the list a bit:

Code: Select all

#!/bin/sh

PKG=$@
DEPLIST=/tmp/deplist.$$$
NEXTDEPLIST=/tmp/nextdeplist.$$$
ALLDEPS=/tmp/alldeplist.$$$

apt-cache depends $PKG | grep epends | gawk -F: '{ print $2 } ' | sed '/^$/d' > $DEPLIST

printf "$PKG depends on:\n"
cat $DEPLIST

for line in $(cat $DEPLIST); do
    apt-cache depends $line | grep epends | gawk -F: '{ print $2 } ' | sed '/^$/d' | tr -d '<>' | sort -u | uniq > $NEXTDEPLIST
        cat $NEXTDEPLIST >> $ALLDEPS
done

cat $ALLDEPS | sort -u | uniq 
rm $ALLDEPS $NEXTDEPLIST $DEPLIST


Re: realdep - moar dependency

Posted: Sat Feb 06, 2016 6:30 pm
by ChefIronBelly
Thanks added to the arsenal.