Blame SOURCES/modalias.prov

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