summaryrefslogtreecommitdiff
path: root/build_tools/uninstall-modules
blob: 02b89c984c0054c288318fadc8399d2720ea0fb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

# This script takes two arguments: a top-level module name, and a kernel version string
#
# It will search the entire /lib/modules directory tree for the given kernel version,
# and find all modules that are dependent (even indirectly) on the specified module.
# After producing that list, it will remove all those modules.

base="${1}"
deptree="${base}"
rmlist=""
founddep=1

checkmod() {
    SAVEIFS="${IFS}"
    IFS=","
    modname=`basename ${1}`
    modname=${modname%.ko}
    if test "${modname}" = "${base}"; then
	rmlist="${rmlist} ${1}"
	IFS="${SAVEIFS}"
	return
    fi
    for dep in `modinfo -F depends ${1}`; do
	for mod in ${deptree}; do
	    if test "${dep}" = "${mod}"; then
		addit=1
		for checkmod in ${deptree}; do
		    if test "${checkmod}" = "${modname}"; then
			addit=0
			break
		    fi
		done
		if test "${addit}" = "1"; then
		    deptree="${deptree},${modname%.ko}"
		    rmlist="${rmlist} ${1}"
		    founddep=1
		fi
	    fi
	done
    done
    IFS="${SAVEIFS}"
}


while test "${founddep}" = "1"; do
    founddep=0
    find /lib/modules/${2}/misc -name \*.ko -print > /tmp/modlist.$$ 2> /dev/null
    find /lib/modules/${2}/extra -name \*.ko -print >> /tmp/modlist.$$ 2> /dev/null
    find /lib/modules/${2}/zaptel -name \*.ko -print >> /tmp/modlist.$$ 2> /dev/null
    find /lib/modules/${2}/dahdi -name \*.ko -print >> /tmp/modlist.$$ 2> /dev/null
    exec 9<&0 < /tmp/modlist.$$
    while read mod; do
	checkmod ${mod}
    done
    exec 0<&9 9<&-
    rm /tmp/modlist.$$
done

if test -n "${rmlist}"; then
    for mod in ${rmlist}; do
	rm -f ${mod}
    done
fi