[3320] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # Simple depmod, use to generate modprobe.conf
|
---|
| 4 | #
|
---|
| 5 | # Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
|
---|
| 6 | #
|
---|
| 7 | # Licensed under GPLv2, see file LICENSE in this source tree.
|
---|
| 8 | #
|
---|
| 9 |
|
---|
| 10 | local BASE="${1:-/usr/lib/modules}"
|
---|
| 11 |
|
---|
| 12 | find "$BASE" -name '*.ko.gz' | while read I ; do
|
---|
| 13 | N=`basename "$I" '.ko.gz'`
|
---|
| 14 | echo -n "@$N"
|
---|
| 15 | zcat "$I" | strings | grep '^depends=' | sed -e 's/^depends=$//' -e 's/^depends=/,/' -e 's/,/ @/g'
|
---|
| 16 | done | awk '
|
---|
| 17 | {
|
---|
| 18 | # modules which has no dependencies are resolved
|
---|
| 19 | if ( NF == 1 ) { res[$1] = ""; next }
|
---|
| 20 | # others have to be resolved based on those which already resolved
|
---|
| 21 | i = $1; $1 = ""; deps[i] = $0; ++ndeps
|
---|
| 22 | }
|
---|
| 23 | END {
|
---|
| 24 | # resolve implicit dependencies
|
---|
| 25 | while ( ndeps ) for (mod in deps) {
|
---|
| 26 | if ( index(deps[mod], "@") > 0 ) {
|
---|
| 27 | $0 = deps[mod]
|
---|
| 28 | for ( i=1; i<=NF; ++i ) {
|
---|
| 29 | if ( substr($i,1,1) == "@" ) {
|
---|
| 30 | if ( $i in res ) {
|
---|
| 31 | $i = res[$i] " " substr($i,2)
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 | deps[mod] = $0
|
---|
| 36 | } else {
|
---|
| 37 | res[mod] = deps[mod]
|
---|
| 38 | delete deps[mod]
|
---|
| 39 | --ndeps
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | # output dependencies in modules.dep format
|
---|
| 44 | for ( mod in res ) {
|
---|
| 45 | $0 = res[mod]
|
---|
| 46 | s = ""
|
---|
| 47 | delete a
|
---|
| 48 | for ( i=1; i<=NF; ++i ) {
|
---|
| 49 | if ( ! ($i in a) ) {
|
---|
| 50 | a[$i] = $i
|
---|
| 51 | s = " ," $i s
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | print "," substr(mod,2) ":" s
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | ' | sort | sed -r -e "s!,([^,: ]*)!/usr/lib/modules/\\1.ko.gz!g"
|
---|