#!/bin/sh

set -e

. /usr/share/debconf/confmodule
db_version 2.0

case "$1" in
	configure)
		db_get alsa-source/has_pnp
		if [ "$RET" = "false" ]; then
		    nopnp=y
		fi
		db_get alsa-source/debug
		if [ "$RET" = "true" ]; then
		    debug=y
		fi
		db_get alsa-source/cards_to_be_built || true
		cards="$RET"
		case "$cards" in
			*all*)
				cards="all"
				;;
		esac
		cards=$(echo "$cards" | sed -e 's/ ([^()]*)//g' -e 's/ ([^()]*)//g')
		if [ -e /etc/alsa -a ! -d /etc/alsa ]; then
		    mv /etc/alsa /etc/alsa.existed
		fi
		if [ ! -d /etc/alsa ]; then
		    mkdir /etc/alsa
		fi
		if [ ! -f /etc/alsa/alsa-source.conf ]; then
			cp /usr/share/alsa-source/alsa-source.conf /etc/alsa
		fi

		/bin/sed -e "s/^ALSA_NOPNP=.*/ALSA_NOPNP=\"$nopnp\"/" -e "s/^ALSA_DEBUG=.*/ALSA_DEBUG=\"$debug\"/" -e "s&^ALSA_CARDS=.*&ALSA_CARDS=\"$cards\"&" /etc/alsa/alsa-source.conf > /etc/alsa/alsa-source.conf.tmp
		mv /etc/alsa/alsa-source.conf.tmp /etc/alsa/alsa-source.conf
		;;
	abort-upgrade|abort-remove|abort-deconfigure)
		exit 0
		;;
	*)
		echo "postinst called with unknown argument \`$1'" >&2;
		exit 0;
	;;
esac



