#!/bin/bash

# chkconfig: 345 85 15
# description: Saves and restores sound card mixer settings at \
#	       boot time and shutdown.

HOME=/etc

case "$1" in
  start)
	echo -n "Starting sound configuration: "

	# loads mixer settings from /etc/.aumixrc
	if [ -f /etc/.aumixrc ]; then
	  cat /dev/sndstat 2> /dev/null | grep -A 1  "Mixers:" | grep -q [0-9]:
	  if [ $? = 0 ]; then  
	      /usr/bin/aumix -L > /dev/null
	  fi
	fi
	
	echo -n sound
	echo
	touch /var/lock/subsys/sound
	;;
  stop)
	echo -n "Saving sound configuration: "

	# Save mixer settings to /etc/.aumixrc
        cat /dev/sndstat 2> /dev/null | grep -A 1  "Mixers:" | grep -q [0-9]:
	if [ $? = 0 ]; then
	    /usr/bin/aumix -S
	fi

	rm -f /var/lock/subsys/sound
	echo -n sound
	echo
	;;
  restart)
	$0 stop
        $0 start
	;;
  status)
	cat /dev/sndstat 2> /dev/null | grep -A 1 "Synth devices:" | grep -q [0-9]:
	if [ $? = 0 ]; then
	  lsmod | grep -q sound
	    if [ $? = 0 ]; then
		echo "Modular sound card detected."
	    else
		echo "Monolythic sound card detected."
	    fi
 
	  cat /dev/sndstat 2> /dev/null | grep -A 1 "Midi devices:" | grep -q [0-9]:	
	  if [ $? = 0 ]; then
	    echo "MIDI device present."
	  else
	    echo "MIDI device not detected."
	  fi	

	else
	  echo "Sound card not configured."
	fi
	;;
  *)
	echo "Usage: sound {start|stop|status|restart}"
	exit 1
esac

exit 0

