summaryrefslogtreecommitdiff
path: root/build_tools
diff options
context:
space:
mode:
authorkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2008-07-08 18:50:46 +0000
committerkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2008-07-08 18:50:46 +0000
commit0f27521bc7d0abc3604c5ca0164bbc95178cdae5 (patch)
treeacd7391f2bc43a4e576dc671247f5d79a29424ac /build_tools
parent255ac2f5bf1bd9b303775b21b2a2f3b451e36f8d (diff)
add the new-and-improved uninstall-modules script here, and teach the Makefile hw to uninstall DAHDI kernel modules if they are installed
git-svn-id: http://svn.digium.com/svn/zaptel/branches/1.4@4398 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'build_tools')
-rwxr-xr-xbuild_tools/uninstall-modules86
1 files changed, 53 insertions, 33 deletions
diff --git a/build_tools/uninstall-modules b/build_tools/uninstall-modules
index a654c21..45c635c 100755
--- a/build_tools/uninstall-modules
+++ b/build_tools/uninstall-modules
@@ -1,41 +1,61 @@
#!/bin/sh
-# uninstall-modules
+
+# This script takes two arguments: a top-level module name, and a kernel version string
#
-# Remove all the modules passed in on the command line from the modules
-# directory. This script is called by the makefile.
+# 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.
-KERNEL_MODULES_DIR=$1
-shift
-MODULES="$*"
+base="${1}"
+deptree="${base}"
+rmlist=""
+founddep=1
-usage() {
- echo "$0: Used to delete kernel modules from the modules directory."
- echo ""
- echo "Usage:"
- echo " $0 MODULES_BASE_DIR mod1 [mod2 [...]]"
- echo ""
- echo " MODULES_BASE_DIR - typically /lib/modules/KVERS"
- echo " modN - (optionally partial) module name to remove."
+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}"
}
-if [ -z "$KERNEL_MODULES_DIR" ]; then
- echo "Missing kernel module directory."
- usage
- exit 1;
-fi
-if [ -z "$MODULES" ]; then
- echo "Missing one or more modules to delete."
- usage
- exit 1;
-fi
-for mod in $MODULES; do
- BASE=`basename $mod`
- for file in `cat $KERNEL_MODULES_DIR/modules.dep | cut -d : -f 1 | grep "$BASE$"`; do
- if [ -e "$file" ]; then
- #echo "Deleting $file."
- rm -f $file
- fi
- done
+while test "${founddep}" = "1"; do
+ founddep=0
+ find /lib/modules/${2} -name \*.ko -print > /tmp/modlist
+ exec 9<&0 < /tmp/modlist
+ while read mod; do
+ checkmod ${mod}
+ done
+ exec 0<&9 9<&-
+ rm /tmp/modlist
done
-exit 0
+
+if test -n "${rmlist}"; then
+ for mod in ${rmlist}; do
+ rm -f ${mod}
+ done
+fi