#!/bin/sh

set -e

OWNER=root.audio
PERM=0660
MAXCARDS=4

create_device1() {
	if [ ! -c $1 ]; then
		mknod -m $PERM $1 c 14 $2
		chown $OWNER $1
	fi
}

create_devices() {
	tmp=0
	while [ $tmp -lt $MAXCARDS ]; do
		minor=`expr $2 + $tmp`
		create_device1 "$1$tmp" $minor
		tmp=`expr $tmp + 1`
	done
}

create_devices2() {
	tmp=0
	while [ $tmp -lt $MAXCARDS ]; do
		tmp2=0
		while [ $tmp2 -lt $3 ]; do
			minor=`expr $tmp \* $3`
			minor=`expr $2 + $minor + $tmp2`
			create_device1 "$1$tmp$tmp2" $minor
			tmp2=`expr $tmp2 + 1`
		done
		tmp=`expr $tmp + 1`
	done
}

case "$1" in
	configure)
		# continue as normal
		;;
	abort-upgrade|abort-remove|abort-deconfigure)
		exit 0;
	;;
	*)
		echo "postinst called with unknown argument \`$1'" >&2;
		exit 0;
	;;
esac

update-rc.d alsa defaults
if [ -x /usr/bin/update-menus ]; then
	update-menus
fi

if [ ! -c /dev/dsp ]; then
	echo "Normal audio devices don't exist, creating them"
	/dev/MAKEDEV audio
fi

