3
0

depmod 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. BASE="${1:-/usr/lib/modules}"
  10. find "$BASE" -name '*.ko.gz' | while read I ; do
  11. N=`basename "$I" '.ko.gz'`
  12. echo -n "@$N"
  13. zcat "$I" | strings | grep '^depends=' | sed -e 's/^depends=$//' -e 's/^depends=/,/' -e 's/,/ @/g'
  14. done | awk '
  15. {
  16. # modules which has no dependencies are resolved
  17. if ( NF == 1 ) { res[$1] = ""; next }
  18. # others have to be resolved based on those which already resolved
  19. i = $1; $1 = ""; deps[i] = $0; ++ndeps
  20. }
  21. END {
  22. # resolve implicit dependencies
  23. while ( ndeps ) for (mod in deps) {
  24. if ( index(deps[mod], "@") > 0 ) {
  25. $0 = deps[mod]
  26. for ( i=1; i<=NF; ++i ) {
  27. if ( substr($i,1,1) == "@" ) {
  28. if ( $i in res ) {
  29. $i = res[$i] " " substr($i,2)
  30. }
  31. }
  32. }
  33. deps[mod] = $0
  34. } else {
  35. res[mod] = deps[mod]
  36. delete deps[mod]
  37. --ndeps
  38. }
  39. }
  40. # output dependencies in modules.dep format
  41. for ( mod in res ) {
  42. $0 = res[mod]
  43. s = ""
  44. delete a
  45. for ( i=1; i<=NF; ++i ) {
  46. if ( ! ($i in a) ) {
  47. a[$i] = $i
  48. s = " ," $i s
  49. }
  50. }
  51. print "," substr(mod,2) ":" s
  52. }
  53. }
  54. ' | sort | sed -r -e "s!,([^,: ]*)!/usr/lib/modules/\\1.ko.gz!g"