Chris@378: #!/bin/bash
Chris@378: 
Chris@378: target=$1
Chris@378: 
Chris@378: if [ ! -f "$target" ]; then 
Chris@378:     echo "Usage: $0 target-executable"
Chris@378:     exit 1
Chris@378: fi
Chris@378: 
Chris@378: pfile=/tmp/packages_$$
Chris@378: rfile=/tmp/redundant_$$
Chris@378: 
Chris@378: trap "rm -f $pfile $rfile" 0
Chris@863: echo 1>&2
Chris@378: 
Chris@460: ldd "$target" | awk '{ print $3; }' | grep '^/' | while read lib; do
Chris@378:     if test -n "$lib" ; then
Chris@378: 	dpkg-query -S "$lib"
Chris@378:     fi
Chris@378:     done | grep ': ' | awk -F: '{ print $1 }' | sort | uniq > $pfile
Chris@378: 
Chris@863: echo "Packages providing required libraries:" 1>&2
Chris@863: cat $pfile 1>&2
Chris@863: echo 1>&2
Chris@378: 
Chris@378: for p in `cat $pfile`; do 
Chris@460:     echo Looking at $p 1>&2
Chris@378:     apt-cache showpkg "$p" | grep '^  ' | grep ',' | awk -F, '{ print $1; }' | \
Chris@378: 	while read d; do 
Chris@378: 	    if grep -q '^'$d'$' $pfile; then
Chris@865: 		echo $p
Chris@378: 	    fi
Chris@378:     done
Chris@378: done | sort | uniq > $rfile
Chris@378: 
Chris@863: echo "Packages that can be eliminated because other packages depend on them:" 1>&2
Chris@863: cat $rfile 1>&2
Chris@863: echo 1>&2
Chris@378: 
Chris@1081: cat $pfile $rfile | sort | uniq -u | sed 's/$/,/' | fmt -1000 | sed 's/^/Depends: /' | sed 's/,$/, libc6/' | sed 's/libjack0,/jackd,/'
Chris@378: 
Chris@863: