#! /bin/sh
#
# re_jackmixer init.d script
# run re_jackmixer and jackd from this script

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DECODER="-o alsa_pcm -i player_in -f player_fallback"
ENCODER="-o ices -i spdif -f player_fallback"
MODE=$DECODER

if [ -e /etc/reboot.fm/re_codec_read_config ]; than
 OUT=`/etc/reboot.fm/re_codec_read_config re_jackmixer_out_1 | sed s/_1//g`
 IN=`/etc/reboot.fm/re_codec_read_config re_jackmixer_in_1 | sed s/_1//g``
 FALLBACK=`/etc/reboot.fm/re_codec_read_config re_jackmixer_fallback_1 | sed s/_1//g`
 MODE="-o $OUT -i $IN -f $FALLBACK"
fi

# Read config file if it is present.
#[ -r /etc/default/$NAME ] && . /etc/default/$NAME

set -e

case "$1" in
  start)
	echo -n "Starting jackd: re_jackmixer"
	sleep 1
	re_jackmixer $MODE &
	echo "."
	;;
  stop)
	echo -n "Stopping jackd: jackd,re_jackmixer "
	killall re_jackmixer
	echo "."
	;;
  restart|force-reload)
	$0 stop
	sleep 1
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
