#!/bin/bash
# Developed by Anders Juel Jensen - andersjjensen at gmail dot com
# This script is in the public domain - do what the heck ever you like
# with it. And you dont even have to pass credits (bonus huh?)
MATCHLIST=$(tempfile)
FILELIST=$(tempfile)
TEMPLIST=$(tempfile)
DEPLIST=$(tempfile)
# Check if user has a clue...
if [ -z $1 ]; then
echo "DUDE!!! You must point me to a package log.."
echo "Those from /var/log/packages/, you know?"
exit 127
fi
# Pry the file list out of the packagelog. Prefix each line with / .
# Find the relevant types of files. Save to file.
for i in $(grep -v : $1 | grep -v install\/); do
j="/$i"
file $j | grep "executable" | grep ELF | cut -f 1 -d : >> $FILELIST
file $j | grep "shared object" | grep ELF | cut -f 1 -d : >> $FILELIST
done
# Get the binaries to spill their little dirty secrets about hard runtime-linking dependencies.
for i in $(cat $FILELIST); do
objdump -p $i | grep NEEDED | cut -d ' ' -f 18 >> $TEMPLIST
done
# Sort and strip out dublicates to speed up grepping /var/log/packages/*
cat $TEMPLIST | sort -u > $MATCHLIST
# Find the relevant packages. Make sure a package doesn't show up as depending on itself.
# Strip of the version and build numbers. Strip strip the /var/log/packages/ part. Collect the results.
grep -l -f $MATCHLIST /var/log/packages/* | grep -v $(basename $1) | sed 's/\(.*\)-.*-.*-.*/\1/;' | cut -d \/ -f 5 >> $DEPLIST
# Which package are we inspecting?
PACK=$(echo -n $(basename $1 | sed 's/\(.*\)-.*-.*-.*/\1/;'))
# If the package has dependencies, write out tsort'able pairs (the order is not relevant)
if [ -s $DEPLIST ]; then
for i in $(cat $DEPLIST); do
echo "$PACK $i"
done
fi
rm $MATCHLIST $FILELIST $TEMPLIST $DEPLIST