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

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

set -e
URL="http://10.0.0.5:8000/bootcast.ogg"

# if re_codec is installed properly we prefere to read the configfile
[ -e /etc/reboot.fm/re_codec_read_config ] && URL=`/etc/reboot.fm/re_codec_read_config re_stream_config`

case "$1" in
  start)
	echo -n "Starting stream: alsaplayer"
	alsaplayer -s player_in -i text -o jack -d re_jackmixer:in_1,re_jackmixer:in_2  $URL 2>&1 >/dev/null &
	echo "."
	;;
  stop)
	echo -n "Stopping stream: alsaplayer"
	ap-control -s player_in quit
	kill -9 `ps ax  | awk '/alsaplayer\ .*player_in/ {print $1}'`
	echo "."
	;;
  restart|force-reload)
	echo -n "Restarting stream:"
  	$0 stop
	sleep 1
	$0 start
	echo "."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
