Jon Masters 97a328
#! /bin/bash
Jon Masters 97a328
Jon Masters 97a328
IFS=$'\n'
Jon Masters 97a328
Jon Masters 97a328
all_provides() {
Jon Masters 97a328
    nm "$@" \
Jon Masters 97a328
    | sed -r -ne 's:^0*([0-9a-f]+) A __crc_(.+):\1\t\2:p' \
Jon Masters 97a328
    | sort -k2 -u
Jon Masters 97a328
}
Jon Masters 97a328
Jon Masters 97a328
all_requires() {
Jon Masters 97a328
    for module in "$@"; do
Jon Masters 97a328
        set -- $(/sbin/modinfo -F vermagic "$module" | sed -e 's: .*::' -e q)
Jon Masters 97a328
        /sbin/modprobe --dump-modversions "$module" \
Jon Masters 97a328
        | sed -r -e 's:^0x0*::' -e 's:$:\t'"$1"':'
Jon Masters 97a328
    done \
Jon Masters 97a328
    | sort -k2 -u
Jon Masters 97a328
}
Jon Masters 97a328
Jon Masters 97a328
if ! [ -e /sbin/modinfo -a -e /sbin/modprobe ]; then
Jon Masters 97a328
    cat > /dev/null
Jon Masters 97a328
    exit 0
Jon Masters 97a328
fi
Jon Masters 97a328
Jon Masters 97a328
modules=($(grep -E '/lib/modules/.+\.ko$'))
Jon Masters 97a328
if [ ${#modules[@]} -gt 0 ]; then
Jon Masters 97a328
    symset_table=$(mktemp -t ${0##*/}.XXXXX)
Jon Masters 97a328
    /usr/lib/rpm/redhat/symset-table | sort > $symset_table
Jon Masters 97a328
Jon Masters 97a328
    join -t $'\t' -j 1 -a 2 $symset_table <(
Jon Masters 97a328
        # Filter out requirements that we fulfill ourself.
Jon Masters 97a328
        join -t $'\t' -j 2 -v 1 \
Jon Masters 97a328
            <(all_requires "${modules[@]}") \
Jon Masters 97a328
            <(all_provides "${modules[@]}") \
Jon Masters 97a328
        | awk '
Jon Masters 97a328
        BEGIN { FS = "\t" ; OFS = "\t" }
Jon Masters 97a328
        { print $3 "/" $2 "/" $1 }
Jon Masters 97a328
        ' \
Jon Masters 97a328
        | sort -u) \
Jon Masters 97a328
    | sort -u \
Jon Masters 97a328
    | awk '
Jon Masters 97a328
    { FS = "\t" ; OFS = "\t" }
Jon Masters 97a328
    NF == 3 { print "kernel(" $2 ") = " $3
Jon Masters 97a328
              next }
Jon Masters 97a328
            { split($1, arr, "/")
Jon Masters 97a328
              print "ksym(" arr[3] ") = " arr[2] }
Jon Masters 97a328
    '
Jon Masters 97a328
fi