From 23cec7cb87403d4d305f02a9312d6174c29ce16b Mon Sep 17 00:00:00 2001 From: smckown Date: Wed, 25 Nov 2009 20:10:52 +0000 Subject: [PATCH] dkms support in pre/post scripts. Ensure module is rmmod'ed on removal of pkg. --- Makefile | 2 +- debian.in/control | 1 + debian.in/postinst | 76 ++++++++++++++++++++++++++++++++++++++++++++-- debian.in/postrm | 27 +++++++++++++--- debian.in/prerm | 29 ++++++++++++++++++ debian.in/rules | 3 +- dkms.conf | 2 +- 7 files changed, 130 insertions(+), 10 deletions(-) create mode 100755 debian.in/prerm diff --git a/Makefile b/Makefile index ac84c4a..c05566d 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ $(BUILD)/src-stamp: Makefile.dkms dkms.conf $(wildcard src/*) cp -a src $(BUILD)/$(DEBSRC) cp Makefile.dkms $(BUILD)/$(DEBSRC) cp dkms.conf $(BUILD)/$(DEBSRC) - perl -i -pe 's/xxDEBVERxx/$(DEBVER)/g' $(BUILD)/$(DEBSRC)/dkms.conf + perl -i -pe 's/xxPKGVERxx/$(PKGVER)/g' $(BUILD)/$(DEBSRC)/dkms.conf find $(BUILD)/$(DEBSRC) -name .svn -type d -exec rm -rf "{}" ";" 2>/dev/null || exit 0 rm -rf $(BUILD)/$(DEBSRC)/.git || exit 0 tar -C $(BUILD) -czf $(BUILD)/$(TARFILE) $(DEBSRC) diff --git a/debian.in/control b/debian.in/control index 9acffae..1f16c50 100644 --- a/debian.in/control +++ b/debian.in/control @@ -9,6 +9,7 @@ Package: xxPACKAGExx Architecture: any Depends: dkms (>> 2.0.20), linux-headers, linux-image, binutils (>= 2.9.5.0.12), gcc (>= 4:4.2.2), dpatch, file, bzip2, lsb-release Conflicts: cp210x-module-2.6.24-19-generic, cp210x-module-2.6.24-21-generic, cp210x-module-2.6.24-22-generic, cp210x-module-2.6.24-23-generic, cp210x-module-2.6.24-24-generic, cp210x-module-2.6.24-25-generic +Replaces: cp210x-module-2.6.24-19-generic, cp210x-module-2.6.24-21-generic, cp210x-module-2.6.24-22-generic, cp210x-module-2.6.24-23-generic, cp210x-module-2.6.24-24-generic, cp210x-module-2.6.24-25-generic Priority: extra Description: Enhanced USB/serial kernel module for cp210x based devices. This module blacklists the standard cp2101 module installed in the kernel, diff --git a/debian.in/postinst b/debian.in/postinst index a818525..accd6fc 100755 --- a/debian.in/postinst +++ b/debian.in/postinst @@ -2,6 +2,76 @@ set -e -if [ "$1" = "configure" ]; then - modprobe -rq cp2101 || true -fi +NAME=xxPACKAGExx +VERSION=xxPKGVERxx + +case "$1" in + configure) + # Unload old cp210x modules, if in use + modprobe -rq cp2101 || true + modprobe -rq cp210x || true + + # Determine current arch / kernel + c_arch=`uname -m` + c_kern=`uname -r` + + if [ -e "/var/lib/dkms/$NAME/$VERSION" ]; then + echo "Removing old $NAME-$VERSION DKMS files..." + dkms remove -m $NAME -v $VERSION --all + fi + + echo "Loading new $NAME-$VERSION DKMS files..." + if [ -f "/usr/src/$NAME-$VERSION.dkms.tar.gz" ]; then + dkms ldtarball --archive "/usr/src/$NAME-$VERSION.dkms.tar.gz" + else + dkms add -m $NAME -v $VERSION + fi + + echo "Installing prebuilt kernel module binaries (if any)" + set +e + IFS=' +' + for kern in `dkms status -m $NAME -v $VERSION -a $c_arch | grep ": built" | awk {'print $3'} | sed 's/,$//'`; do + echo "Trying kernel: $kern" + dkms install --force -m $NAME -v $VERSION -k $kern -a $c_arch + done + unset IFS + set -e + + # If none installed, install. + ##if [ `dkms status -m $NAME -v $VERSION -k $c_kern -a $c_arch | grep -c ": installed"` -eq 0 ]; then + dkms_status=`dkms status -m $NAME -v $VERSION -k $c_kern -a $c_arch` + if [ `echo $dkms_status | grep -c ": installed"` -eq 0 ]; then + if [ `echo $c_kern | grep -c "BOOT"` -eq 0 ] && [ -e "/lib/modules/$c_kern/build/include" ]; then + # Only build if we need to. + if [ `echo $dkms_status | grep -c ": built"` -eq 0 ]; then + echo "Building module..." + dkms build -m $NAME -v $VERSION + fi + echo "Installing module..." + dkms install -m $NAME -v $VERSION + elif [ `echo $c_kern | grep -c "BOOT"` -gt 0 ]; then + echo "" + echo "Module build for the currently running kernel was skipped since you" + echo "are running a BOOT variant of the kernel." + else + echo "" + echo "Module build for the currently running kernel was skipped since the" + echo "kernel source for this kernel does not seem to be installed." + fi + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 + diff --git a/debian.in/postrm b/debian.in/postrm index fdd7b35..9bf77b5 100755 --- a/debian.in/postrm +++ b/debian.in/postrm @@ -1,7 +1,26 @@ -#! /bin/sh +#!/bin/sh + +NAME=xxPACKAGExx +VERSION=xxPKGVERxx set -e -if [ "$1" = "remove" ]; then - depmod -a -fi +case "$1" in + purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + depmod + if [ -d "/usr/src/$NAME-$VERSION" ]; then + echo "Removing old module source..." + rm -rf "/usr/src/$NAME-$VERSION" + fi + ;; + + *) + echo "postrm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 + diff --git a/debian.in/prerm b/debian.in/prerm new file mode 100755 index 0000000..d685190 --- /dev/null +++ b/debian.in/prerm @@ -0,0 +1,29 @@ +#!/bin/sh + +NAME=xxPACKAGExx +VERSION=xxPKGVERxx + +set -e + +case "$1" in + remove|upgrade|deconfigure) + rmmod cp2101 2>/dev/null || true + rmmod xxROOTNAMExx 2>/dev/null || true + if [ "`dkms status -m $NAME`" ]; then + dkms remove -m $NAME -v $VERSION --all + fi + ;; + + failed-upgrade) + ;; + + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 + diff --git a/debian.in/rules b/debian.in/rules index 57b40bd..4f324b6 100755 --- a/debian.in/rules +++ b/debian.in/rules @@ -10,7 +10,7 @@ # This file may have to be extensively modified package = xxPACKAGExx -inst_dir = debian/tmp/usr/src/xxPACKAGExx-xxDEBVERxx +inst_dir = debian/tmp/usr/src/xxPACKAGExx-xxPKGVERxx install_dir = install -d -m 755 install_file = install -m 644 @@ -52,6 +52,7 @@ binary-arch: checkroot build install : # install maintainer scripts $(install_dir) debian/tmp/DEBIAN $(install_script) debian/postinst debian/tmp/DEBIAN/postinst + $(install_script) debian/prerm debian/tmp/DEBIAN/prerm $(install_script) debian/postrm debian/tmp/DEBIAN/postrm : # install docs $(install_dir) debian/tmp/usr/share/doc/$(package)/ diff --git a/dkms.conf b/dkms.conf index e1c3c43..64fed9c 100644 --- a/dkms.conf +++ b/dkms.conf @@ -1,4 +1,4 @@ -PACKAGE_VERSION="xxDEBVERxx" +PACKAGE_VERSION="xxPKGVERxx" PACKAGE_NAME="cp210x-module-dkms" CLEAN="make -f Makefile.dkms clean" BUILT_MODULE_NAME[0]=cp210x -- 2.39.2