#!/bin/sh

set -e

#DEBHELPER#

case "$1" in
  install|upgrade)
		# These are no longer used
		for mod in vboxdrv vboxnetflt vboxnetadp; do
			dkms status -m $mod | while read line; do
				if echo "$line" | grep -q added > /dev/null ||
					echo "$line" | grep -q built > /dev/null ||
					echo "$line" | grep -q installed > /dev/null;
				then
					version=`echo "$line" | sed "s/$mod,\([^,]*\)[,:].*/\1/;t;d"`
					echo "Removing obsolete module $mod version $version"
					dkms remove -m $mod -v $version --all
				fi
			done
		done
  ;;
esac
