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