summaryrefslogtreecommitdiff
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
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
-rw-r--r--Makefile33
-rwxr-xr-xbuild_tools/uninstall-modules86
2 files changed, 79 insertions, 40 deletions
diff --git a/Makefile b/Makefile
index 85e1c48..cb1a090 100644
--- a/Makefile
+++ b/Makefile
@@ -525,21 +525,40 @@ install-udev: devices
uninstall-hotplug:
$(MAKE) -C firmware hotplug-uninstall DESTDIR=$(DESTDIR)
-uninstall-modules:
-ifneq ($(BUILDVER),linux24)
- @./build_tools/uninstall-modules $(DESTDIR)/lib/modules/$(KVERS) $(ALL_MODULES)
-endif
-
ifeq ($(BUILDVER),linux24)
-install-modules: $(INSTALL_MODULES) uninstall-modules
+install-modules: $(INSTALL_MODULES)
$(INSTALL) -d $(DESTDIR)$(MOD_DIR)
$(INSTALL) -m 644 $(INSTALL_MODULES) $(DESTDIR)$(MOD_DIR)
else
-install-modules: uninstall-modules
+install-modules:
+ifndef DESTDIR
+ @if modinfo dahdi > /dev/null 2>&1; then \
+ echo -n "Removing DAHDI modules for kernel $(KVERS), please wait..."; \
+ build_tools/uninstall-modules dahdi $(KVERS); \
+ rm -rf /lib/modules/$(KVERS)/dahdi; \
+ echo "done."; \
+ fi
+endif
$(KMAKE_INST)
endif
[ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
+uninstall-modules:
+ifneq ($(BUILDVER),linux24)
+ifdef DESTDIR
+ echo "Uninstalling modules is not supported with a DESTDIR specified."
+ exit 1
+else
+ @if modinfo zaptel > /dev/null 2>&1 ; then \
+ echo -n "Removing Zaptel modules for kernel $(KVERS), please wait..."; \
+ build_tools/uninstall-modules zaptel $(KVERS); \
+ rm -rf /lib/modules/$(KVERS)/zaptel; \
+ echo "done."; \
+ fi
+ [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
+endif
+endif
+
config:
ifneq (,$(COPY_INITD))
$(COPY_INITD)
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