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