Jeremy Katz 95521b
#! /bin/sh
Jeremy Katz 95521b
Jeremy Katz 95521b
# heavily based upon find-suggests.ksyms by Andreas Gruenbacher <agruen@suse.de>.
Jeremy Katz 95521b
# with modifications by Michael Brown <michael_e_brown@dell.com>
Jeremy Katz 95521b
#
Jeremy Katz 95521b
# -- added module versioning info to modalias() symbols
Jeremy Katz 95521b
# -- removed code which inspects spec files.
Jeremy Katz 95521b
Jeremy Katz 95521b
IFS=$'\n'
Jeremy Katz 95521b
20a456
#
Jeremy Katz 95521b
# Initially, dont generate modalias() lines for kernel package. This needs
20a456
# additional discussion. Would like to eventually add them for
20a456
# completeness, so that we can determine when drivers are folded into
Jeremy Katz 95521b
# mainline kernel.
20a456
#
Jeremy Katz 95521b
case "$1" in
Jeremy Katz 95521b
kernel-module-*)    ;; # Fedora kernel module package names start with
Jeremy Katz 95521b
		       # kernel-module.
Jeremy Katz 95521b
kernel*)	   is_kernel_package=1 ;;
Jeremy Katz 95521b
esac
Jeremy Katz 95521b
Jeremy Katz 95521b
if ! [ -z "$is_kernel_package" ]; then
Jeremy Katz 95521b
    cat > /dev/null
Jeremy Katz 95521b
    exit 0
Jeremy Katz 95521b
fi
Jeremy Katz 95521b
Jeremy Katz 95521b
print_modaliases() {
Jeremy Katz 95521b
    declare class=$1 variants=$2 pos=$3
Jeremy Katz 95521b
    if [ -n "$variants" ]; then
Jeremy Katz 95521b
	echo "${class:0:pos}[$variants]${class:pos+1}"
Jeremy Katz 95521b
    else
Jeremy Katz 95521b
	[ -z "$class" ] || echo "$class"
Jeremy Katz 95521b
    fi
Jeremy Katz 95521b
}
Jeremy Katz 95521b
Jeremy Katz 95521b
combine_modaliases() {
Jeremy Katz 95521b
    declare tag class variants pos n
Jeremy Katz 95521b
    read class
Jeremy Katz 95521b
    while read tag; do
Jeremy Katz 95521b
	for ((n=0; n<${#class}; n++)); do
Jeremy Katz 95521b
	    if [ "*" != "${class:n:1}" -a \
Jeremy Katz 95521b
		 "${class:0:n}" = "${tag:0:n}" -a \
Jeremy Katz 95521b
		 "${class:n+1}" = "${tag:n+1}" ] &&
Jeremy Katz 95521b
	       ( [ -z "$pos" ] || [ $n = $pos ] ); then
Jeremy Katz 95521b
		variants="${variants:-${class:n:1}}${tag:n:1}"
Jeremy Katz 95521b
		pos=$n
Jeremy Katz 95521b
		break
Jeremy Katz 95521b
	    fi
Jeremy Katz 95521b
	done
Jeremy Katz 95521b
	if [ $n -eq ${#class} ]; then
Jeremy Katz 95521b
	    print_modaliases "$class" "$variants" "$pos"
Jeremy Katz 95521b
	    variants=
Jeremy Katz 95521b
	    pos=
Jeremy Katz 95521b
	    class=$tag
Jeremy Katz 95521b
	fi
Jeremy Katz 95521b
    done
Jeremy Katz 95521b
    print_modaliases "$class" "$variants" "$pos"
Jeremy Katz 95521b
}
Jeremy Katz 95521b
Jeremy Katz 95521b
for module in $(grep -E '/lib/modules/.+\.ko$') $*; do
Jeremy Katz 95521b
    # | head -n1 because some modules have *two* version tags. *cough*b44*cough*
Jeremy Katz 95521b
    modver=$(/sbin/modinfo -F version "$module"| head -n1)
Jeremy Katz 95521b
    modver=${modver// /_}
Jeremy Katz 95521b
Jeremy Katz 95521b
    # only add version tag if it has a version
Jeremy Katz 95521b
    if [ -n "$modver" ]; then
Jeremy Katz 95521b
        /sbin/modinfo -F alias "$module" \
Jeremy Katz 95521b
        | sed -nre "s,(.+),modalias(\\1) = $modver,p"
Jeremy Katz 95521b
    else
Jeremy Katz 95521b
        /sbin/modinfo -F alias "$module" \
Jeremy Katz 95521b
        | sed -nre "s,(.+),modalias(\\1),p"
Jeremy Katz 95521b
    fi
Jeremy Katz 95521b
done \
Jeremy Katz 95521b
| sort -u \
Jeremy Katz 95521b
| combine_modaliases