~ubuntu-branches/debian/stretch/dkms/stretch

1 by Matt Domsch
Import upstream version 2.0.17.4
1
#! /bin/sh
2
3
# heavily based upon find-suggests.ksyms by Andreas Gruenbacher <agruen@suse.de>.
4
# with modifications by Michael Brown <Michael_E_Brown@dell.com>
5
#
6
# -- added module versioning info to modalias() symbols
7
# -- removed code which inspects spec files.
8
9
IFS=$'\n'
10
11
print_modaliases() {
12
    declare class=$1 variants=$2 pos=$3
13
    if [ -n "$variants" ]; then
14
	echo "${class:0:pos}[$variants]${class:pos+1}"
15
    else
16
	[ -z "$class" ] || echo "$class"
17
    fi
18
}
19
20
combine_modaliases() {
21
    declare tag class variants pos n
22
    read class
23
    while read tag; do
24
	for ((n=0; n<${#class}; n++)); do
25
	    if [ "*" != "${class:n:1}" -a \
26
		 "${class:0:n}" = "${tag:0:n}" -a \
27
		 "${class:n+1}" = "${tag:n+1}" ] &&
28
	       ( [ -z "$pos" ] || [ $n = $pos ] ); then
29
		variants="${variants:-${class:n:1}}${tag:n:1}"
30
		pos=$n
31
		break
32
	    fi
33
	done
34
	if [ $n -eq ${#class} ]; then
35
	    print_modaliases "$class" "$variants" "$pos"
36
	    variants=
37
	    pos=
38
	    class=$tag
39
	fi
40
    done
41
    print_modaliases "$class" "$variants" "$pos"
42
}
43
44
get_modinfo() {
45
    module=$1
46
47
    # | head -n1 because some modules have *two* version tags. *cough*b44*cough*
48
    modver=$(/sbin/modinfo -F version "$module"| head -n1)
49
    modver=${modver// /_}
50
51
    # only add version tag if it has a version
52
    if [ -n "$modver" ]; then
53
        /sbin/modinfo -F alias "$module" \
54
        | sed -nre "s,(.+),modalias(\\1) = $modver,p"
55
    else
56
        /sbin/modinfo -F alias "$module" \
57
        | sed -nre "s,(.+),modalias(\\1),p"
58
    fi
59
}
60
61
62
TMPDIR=$(mktemp -d /tmp/dkms-findprovides-$$-$RANDOM-XXXXXX)
63
trap "rm -rf $TMPDIR >/dev/null 2>&1"  QUIT EXIT HUP INT TERM
64
65
modlist=
66
for cand in $(grep -E '(/lib/modules/.+\.ko$|tgz$|tbz$|tar\.(gz|bz2)$)') $*; do
67
    if echo $cand | grep -q -E '/lib/modules/.+\.ko$' > /dev/null 2>&1; then
68
        modlist="$modlist $cand"
69
    fi
70
71
    [ -f $cand ] || continue
72
73
    opts=x
74
    if gzip -t $cand >/dev/null 2>&1; then
75
        opts=${opts}z
76
    elif bzip2 -t $cand >/dev/null 2>&1; then
77
        opts=${opts}j
78
    fi
79
    tar ${opts}f $cand -C $TMPDIR > /dev/null 2>&1
80
done
81
82
for module in $(find $TMPDIR -name \*.ko) $modlist; do
83
    if echo $module | grep -q -E '.ko$' >/dev/null 2>&1; then
84
        # it is a straight module
85
        get_modinfo $module
86
        continue
87
    fi
88
done \
89
| sort -u \
90
| combine_modaliases