making a .dot (graphviz) graph of RPM dependencies


I'm currently looking into Fedora/kickstart again and also cobbler.

For reasons I won't go into right now I wanted to visualize the relationships between installed RPM packages. I've found a couple of tools that claim they can do this, including rpmgraph, rpmorphan and references to some here.

But it seemed that I had to install some stuff to use it (if it worked at all). So instead of looking further, I hacked something together quickly that fits my needs. It's a bash script and it has almost no dependencies (uses only tools that can be found on any RPM-based system)


#!/bin/bash

# deps:
# bash
# rpm
# sed
# cut
# uniq
# sort

installedrpms=$(rpm -qa --queryformat "%{NAME}\n")


function printdeps() {
local package deps dep providedby out

package=$1
out=""
deps=$(rpm -qR $package | cut -d " " -f 1)

for dep in $deps;
do
providedby=$(rpm -q --queryformat "%{NAME}\n" --whatprovides "$dep")
if [ $? -eq 0 ];
then
# packages should not depend on themselves
if [ "$package" != "$providedby" ];
then
out="$out\"$package\" -> \"$providedby\";\n"
fi
fi
done

echo $out
}

alloutput=""

for i in $installedrpms;
do
output=$(printdeps $i)
alloutput="$alloutput$output"
done


echo "digraph deptree {"
echo -e "$alloutput" | sort | uniq
echo "}"