#!/bin/sh
set -e

# Get the package version
NAME=fwctl
PACKAGE_NAME=$NAME-dkms
CVERSION=`dpkg-query -W -f='${Version}' $PACKAGE_NAME | awk -F "-" '{print $1}' | cut -d\: -f2`
ARCH=`uname -m`

dkms_configure () {
	POSTINST="/usr/src/$NAME-$CVERSION/common.postinst"
	if [ -f "$POSTINST" ]; then
		"$POSTINST" "$NAME" "$CVERSION" "/usr/share/$PACKAGE_NAME" "$ARCH" "$2"
		return $?
	fi
	echo "WARNING: $POSTINST does not exist." >&2
	echo "ERROR: DKMS version is too old and $PACKAGE_NAME was not" >&2
	echo "built with legacy DKMS support." >&2
	echo "You must either rebuild $PACKAGE_NAME with legacy postinst" >&2
	echo "support or upgrade DKMS to a more current version." >&2
	return 1
}

case "$1" in
	configure)
		dkms_configure
	;;

	abort-upgrade|abort-remove|abort-deconfigure)
	;;

	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 1
	;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
