Logoj0ke.net Open Build Service > Projects > GFS > kernel-source > extract-modaliases
Sign Up | Log In

File extract-modaliases of Package kernel-source (Revision db43c5e4b69f00d007dea2869c112efe)

Currently displaying revision db43c5e4b69f00d007dea2869c112efe, show latest

 
1
#! /bin/bash
2
3
LC_ALL=POSIX
4
5
usage() {
6
    cat <<EOF
7
Usage: ${0##*/} [-i module] [-x module] [-Nv] {module|rpm} ...
8
9
-i  Include the specified modules (glob expression).
10
11
-x  Exclude the specified modules (glob expression).
12
13
-N  Don't try to combine modalias tags that only differ in one character.
14
15
-v  Verbose: report which modules define which aliases.
16
EOF
17
    exit $1
18
}
19
20
ARGS=("$@")
21
22
options=`getopt -o i:x:vNh -- "$@"`
23
24
if [ $? -ne 0 ]
25
then
26
    usage 2
27
fi
28
29
eval set -- "$options"
30
31
opt_combine=1
32
while :; do
33
    case "$1" in
34
    -i)
35
    include="$include ${2%.ko}"
36
    shift 2
37
    ;;
38
    -x)
39
    exclude="$exclude ${2%.ko}"
40
    shift 2
41
    ;;
42
    -v)
43
    opt_verbose=1
44
    shift ;;
45
    -N)
46
    opt_combine=
47
    shift ;;
48
    -h)
49
    usage 0
50
    ;;
51
    --)
52
    shift
53
    break
54
    ;;
55
    esac
56
done
57
58
process_module() {
59
    declare module=$1 base=${1##*/} aliases
60
61
    if [ -n "$include" ]; then
62
    included=
63
    for x in $include; do
64
        eval "case \"\${base%.ko}\" in (${x%.ko}) included=1;; esac"
65
    done
66
    else
67
    included=1
68
    fi
69
    for x in $exclude; do
70
    eval "case \"\${base%.ko}\" in (${x%.ko}) included=;; esac"
71
    done
72
    [ -n "$included" ] || return
73
74
    aliases="$(/sbin/modinfo -F alias "$module" \
75
           | sed -nre 's@^.+:.+$@Supplements: modalias(&)@p')"
76
    if [ -n "$aliases" ]; then
77
    eval "processed_module_${base//[^a-zA-Z0-9_]/_}=$base"
78
    echo "$aliases" \
79
    | if [ -n "$opt_verbose" ]; then
80
        sed -e "s@\$@ # $base@"
81
    else
82
        cat
83
    fi
84
    fi
85
}
86
87
print_modaliases() {
88
    declare class=$1 variants=$2 pos=$3
89
    if [ -n "$variants" ]; then
90
    echo "${class:0:pos}[$variants]${class:pos+1}"
91
    else
92
    [ -z "$class" ] || echo "$class"
93
    fi
94
}
95
96
combine_modaliases() {
97
    declare tag class variants pos n
98
    read class
99
    while read tag; do
100
    for ((n=0; n<${#class}; n++)); do
101
        if [ "*" != "${class:n:1}" -a \
102
         "${class:0:n}" = "${tag:0:n}" -a \
103
         "${class:n+1}" = "${tag:n+1}" ] &&
104
           ( [ -z "$pos" ] || [ $n = $pos ] ); then
105
        variants="${variants:-${class:n:1}}${tag:n:1}"
106
        pos=$n
107
        break
108
        fi
109
    done
110
    if [ $n -eq ${#class} ]; then
111
        print_modaliases "$class" "$variants" "$pos"
112
        variants=
113
        pos=
114
        class=$tag
115
    fi
116
    done
117
    print_modaliases "$class" "$variants" "$pos"
118
}
119
120
tmp=$(mktemp -t ${0##*/}.XXXXXX)
121
trap "rm -f $tmp" EXIT
122
123
for file in "$@"; do
124
    case "$(file -b "$file")" in
125
    RPM*)
126
    tmpdir=$(mktemp -td ${0##*/}.XXXXXX)
127
    rpm2cpio "$file" | ( cd $tmpdir && cpio -dim --quiet )
128
    for module in $(find $tmpdir -type f -name '*.ko'); do
129
        process_module "$module" >> $tmp
130
    done
131
    rm -rf $tmpdir
132
    ;;
133
    ELF*)
134
    process_module "$file" >> $tmp
135
    ;;
136
    *)
137
    if [ -e "$file" ]; then
138
        echo "File type of $file not supported" >&2
139
        exit 1
140
    fi
141
    file2=$(/sbin/modinfo -F filename "${file%.ko}")
142
    if ! [ -e "$file2" ]; then
143
        echo "No module $file found" >&2
144
        exit 1
145
    fi
146
    process_module "$file2" >> $tmp
147
    ;;
148
    esac
149
done
150
151
if [ -n "${!processed_module_*}" ]; then
152
    echo "# Modules:" $(for m in ${!processed_module_*}; do echo ${!m}; done \
153
            | sort -u)
154
155
    sort -u $tmp \
156
    | if [ -n "$opt_combine" ]; then
157
    combine_modaliases
158
    else
159
    cat
160
    fi
161
162
    echo "# Generated with: ${0##*/} ${ARGS[*]}"
163
fi
164
165
# vim:softtabstop=4 shiftwidth=4
166