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