#!/bin/sh
#
# sound:   This shell script saved mixer values your soundcards.
#
# chkconfig: 2345 99 01
# description: This shell script saved mixer values your soundcards.
# halt: yes

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/sound

start()
{
	ALSA_UDI=$(hal-find-by-property --key alsa.type --string control 2>/dev/null)
	if [ -n "$ALSA_UDI" ]; then
		for i in $ALSA_UDI; do
			action "Restoring mixer values for $(hal-get-property --udi $i --key alsa.card_id):" dbus-send --system --print-reply --dest=org.freedesktop.Hal $i org.freedesktop.Hal.Device.Alsa.RestoreMixer
		done
	fi
	touch "$LOCKFILE"
}

stop()
{
	ALSA_UDI=$(hal-find-by-property --key alsa.type --string control 2>/dev/null)
	if [ -n "$ALSA_UDI" ]; then
		for i in $ALSA_UDI; do
			action "Saving mixer values for $(hal-get-property --udi $i --key alsa.card_id):" dbus-send --system --print-reply --dest=org.freedesktop.Hal $i org.freedesktop.Hal.Device.Alsa.SaveMixer
		done
	fi
	rm -f "$LOCKFILE"
}

restart()
{
	stop
	start
}

case $1 in
	start)
		start
		;;
	stop|condstop)
		stop
		;;
	restart|reload)
		restart
		;;
	condrestart|condreload)
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condrestart}"
		exit 1
esac
