]> oss.titaniummirror.com Git - cp210x.git/blobdiff - debian.in/postinst
dkms support in pre/post scripts. Ensure module is rmmod'ed on removal of pkg.
[cp210x.git] / debian.in / postinst
index a818525b67f953af3779a9a58d511aefc96d0c5c..accd6fcfd09b3bc4201d7a2a577a5ea9c72e13cf 100755 (executable)
@@ -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
+