#!/bin/sh

set -e

if dpkg --compare-versions "$2" lt-nl "2.0.21.1-1~" ; then
	if [ -e "/etc/modprobe.d/dkms" ]; then
		md5sum=$(md5sum /etc/modprobe.d/dkms | sed -e 's/ .*//')
		old_md5sum=$(dpkg-query -W -f='${Conffiles}' dkms | \
			sed -n -e "\' /etc/modprobe.d/dkms ' { s/ obsolete$//; s/.* //; p }")
		if [ "$md5sum" = "$old_md5sum" ]; then
			rm -f /etc/modprobe.d/dkms
		else
			echo "Moving /etc/modprobe.d/dkms to /etc/modprobe.d/dkms.conf ..."
			mv /etc/modprobe.d/dkms /etc/modprobe.d/dkms.conf
			rm -f /etc/modprobe.d/dkms
		fi
	fi
fi

# Automatically added by dh_installmodules
if [ "$1" = configure ]; then
	if [ -e "/etc/modprobe.d/dkms" ]; then
		echo "Preserving user changes to /etc/modprobe.d/dkms.conf ..."
		if [ -e "/etc/modprobe.d/dkms.conf" ]; then
			mv -f "/etc/modprobe.d/dkms.conf" "/etc/modprobe.d/dkms.conf.dpkg-new"
		fi
		mv -f "/etc/modprobe.d/dkms" "/etc/modprobe.d/dkms.conf"
	fi
fi
# End automatically added section

