[zaptel-commits] kpfleming: branch 1.4 r4398 - in /branches/1.4: ./ build_tools/

SVN commits to the Zaptel project zaptel-commits at lists.digium.com
Tue Jul 8 13:50:46 CDT 2008


Author: kpfleming
Date: Tue Jul  8 13:50:46 2008
New Revision: 4398

URL: http://svn.digium.com/view/zaptel?view=rev&rev=4398
Log:
add the new-and-improved uninstall-modules script here, and teach the Makefile hw to uninstall DAHDI kernel modules if they are installed

Modified:
    branches/1.4/Makefile
    branches/1.4/build_tools/uninstall-modules

Modified: branches/1.4/Makefile
URL: http://svn.digium.com/view/zaptel/branches/1.4/Makefile?view=diff&rev=4398&r1=4397&r2=4398
==============================================================================
--- branches/1.4/Makefile (original)
+++ branches/1.4/Makefile Tue Jul  8 13:50:46 2008
@@ -525,20 +525,39 @@
 uninstall-hotplug:
 	$(MAKE) -C firmware hotplug-uninstall DESTDIR=$(DESTDIR)
 
+ifeq ($(BUILDVER),linux24)
+install-modules: $(INSTALL_MODULES)
+	$(INSTALL) -d $(DESTDIR)$(MOD_DIR)
+	$(INSTALL) -m 644 $(INSTALL_MODULES) $(DESTDIR)$(MOD_DIR)
+else
+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)
-	@./build_tools/uninstall-modules $(DESTDIR)/lib/modules/$(KVERS) $(ALL_MODULES)
-endif
-
-ifeq ($(BUILDVER),linux24)
-install-modules: $(INSTALL_MODULES) uninstall-modules
-	$(INSTALL) -d $(DESTDIR)$(MOD_DIR)
-	$(INSTALL) -m 644 $(INSTALL_MODULES) $(DESTDIR)$(MOD_DIR)
-else
-install-modules: uninstall-modules
-	$(KMAKE_INST)
-endif
+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))

Modified: branches/1.4/build_tools/uninstall-modules
URL: http://svn.digium.com/view/zaptel/branches/1.4/build_tools/uninstall-modules?view=diff&rev=4398&r1=4397&r2=4398
==============================================================================
--- branches/1.4/build_tools/uninstall-modules (original)
+++ branches/1.4/build_tools/uninstall-modules Tue Jul  8 13:50:46 2008
@@ -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;
+
+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
+
+if test -n "${rmlist}"; then
+    for mod in ${rmlist}; do
+	rm -f ${mod}
+    done
 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
-done
-exit 0




More information about the zaptel-commits mailing list