#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          gom
# Required-Start:    $remote_fs
# Required-Stop:
# Default-Start:     S
# Default-Stop:
# Short-Description: Bootup for gom: Initialize audio mixer(s)
### END INIT INFO
#
# (c) 1998-2006 Stephan A Suerken <absurd@debian.org>
#

#
# Where adm default values can be stored
#
gom_defaults=/etc/default/gom
gom_cmd=/usr/bin/gom

#
# Variable script defaults; Customize in /etc/default/gom if needed.
#
auto_init="false"
valid_sound_devices="sound alsa"

#
# Variable admin default
#
[ ! -e ${gom_defaults} ] || . ${gom_defaults}

#
# Silent exits
#
# Explicit configuration
[ "${auto_init}" = "yes" -o "${auto_init}" = "true" ] || exit 0
# gom.deb is removed but not purged
[ -x ${gom_cmd} ] || exit 0

# valid sound device there? (this works for (at least) kernels 2.2.x and 2.4.x)
sound_device=""
for d in ${valid_sound_devices}; do
	if grep --quiet ${d} /proc/devices; then
		sound_device=${d};
		break;
	fi;
done
[ "${sound_device}" ] || exit 0

#
# Initialization
#
case "$1" in
	# At this point, gom is installed properly and the (oss) sound
	# driver is present.
	# Won't fail even if configuration is invalid.
	start|restart|reload|force-reload)
		echo -n "Gom initializing audio mixer(s)..."
		if ${gom_cmd} --quiet --initialize >/dev/null 2>&1 ; then
			echo "done."
		else
			echo "some errors. Check 'gom --initialize' and/or finetune via 'gomconfig'."
		fi
		;;
	stop)
		;;
	*)
		echo "Usage: /etc/init.d/gom {start|restart|reload|force-reload|stop}" >&2
		echo
		echo "       start|restart|reload|force-reload  initializes audio mixer(s)." >&2
		echo "       stop                               does nothing." >&2
		exit 1
		;;
esac

exit 0
