uninstall-modules 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. # This script takes two arguments: a top-level module name, and a kernel version string
  3. #
  4. # It will search the entire /lib/modules directory tree for the given kernel version,
  5. # and find all modules that are dependent (even indirectly) on the specified module.
  6. # After producing that list, it will remove all those modules.
  7. base="${1}"
  8. deptree="${base}"
  9. rmlist=""
  10. founddep=1
  11. checkmod() {
  12. SAVEIFS="${IFS}"
  13. IFS=","
  14. modname=`basename ${1}`
  15. modname=${modname%.ko}
  16. if test "${modname}" = "${base}"; then
  17. rmlist="${rmlist} ${1}"
  18. IFS="${SAVEIFS}"
  19. return
  20. fi
  21. for dep in `modinfo -F depends ${1}`; do
  22. for mod in ${deptree}; do
  23. if test "${dep}" = "${mod}"; then
  24. addit=1
  25. for checkmod in ${deptree}; do
  26. if test "${checkmod}" = "${modname}"; then
  27. addit=0
  28. break
  29. fi
  30. done
  31. if test "${addit}" = "1"; then
  32. deptree="${deptree},${modname%.ko}"
  33. rmlist="${rmlist} ${1}"
  34. founddep=1
  35. fi
  36. fi
  37. done
  38. done
  39. IFS="${SAVEIFS}"
  40. }
  41. while test "${founddep}" = "1"; do
  42. founddep=0
  43. find /lib/modules/${2}/misc -name \*.ko -print > /tmp/modlist.$$ 2> /dev/null
  44. find /lib/modules/${2}/extra -name \*.ko -print >> /tmp/modlist.$$ 2> /dev/null
  45. find /lib/modules/${2}/zaptel -name \*.ko -print >> /tmp/modlist.$$ 2> /dev/null
  46. find /lib/modules/${2}/dahdi -name \*.ko -print >> /tmp/modlist.$$ 2> /dev/null
  47. exec 9<&0 < /tmp/modlist.$$
  48. while read mod; do
  49. checkmod ${mod}
  50. done
  51. exec 0<&9 9<&-
  52. rm /tmp/modlist.$$
  53. done
  54. if test -n "${rmlist}"; then
  55. for mod in ${rmlist}; do
  56. rm -f ${mod}
  57. done
  58. fi