#!/bin/sh
set -e

case "$1" in
    remove)
	conffile=/etc/modprobe.d/oss-compat.conf
	# If the installed file matches a known version, remove it
	if [ -f ${conffile} ]; then
	    md5sum=$(md5sum ${conffile} | cut -d\  -f1)
	    # Wheezy version
	    md5wheezy=88222606b0a3ba8b0825c5000c754e6f
	    # Jessie version
	    md5jessie=cb772524a069ec273d7ca6db520388c1
	    if [ "${md5sum}" = "${md5wheezy}" -o "${md5sum}" = "${md5jessie}" ]; then
		rm -f /etc/modprobe.d/oss-compat.conf
	    fi
	fi
	# Remove the modules once nothing uses them
	if grep -q ^snd_seq_oss /proc/modules; then
	    (rmmod -w snd-seq-oss) &
	fi
	if grep -q ^snd_pcm_oss /proc/modules; then
	    if grep -q ^snd_mixer_oss /proc/modules; then
		(rmmod -w snd-pcm-oss; rmmod -w snd-mixer-oss) &
	    else
		(rmmod -w snd-pcm-oss) &
	    fi
	elif grep -q ^snd_mixer_oss /proc/modules; then
	    (rmmod -w snd-mixer-oss) &
	fi
	;;
esac

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

#DEBHELPER#

exit 0
