#!/bin/sh

# YIFF Sound Server start up script
#

#
# Locations of Y compoents and resources (you may need to edit these):
#
YRECINFO_PROGRAM=/usr/bin/yrecinfo
YIFF_PROGRAM=/usr/sbin/yiff
YIFF_CONFIGURATION=/etc/yiffrc

#
# Check if a Y Sound Server is already running:
#
$YRECINFO_PROGRAM > /dev/null 2> /dev/null
if [ "$?" = "0" ]; then
	yplay -m /usr/share/sounds/ring.wav &
	echo "The YIFF Sound Server is already running:"
	ps aux|grep $YIFF_PROGRAM
	exit
fi


#
# Run the Y Sound Server:
#
# Syntax: <program> <config_file>
#
# The Y server will fork into background by itself
#
echo "Starting Y Server..."
$YIFF_PROGRAM $YIFF_CONFIGURATION

# Wait for the Y Sound Server to start...
#
COUNTER=1
START_TIME_MAX=30
$YRECINFO_PROGRAM > /dev/null 2> /dev/null
while [ "$?" != "0" ]; do
	if [ $COUNTER -gt $START_TIME_MAX ]; then
		echo "Failed to start the Y Server."
		exit
	fi

	echo -n -e "\rWaiting for Y client services ($COUNTER seconds)..."
	let COUNTER=COUNTER+1
	sleep 1
	$YRECINFO_PROGRAM > /dev/null 2> /dev/null
done
echo -e "\nY Server started successfully."

#
# Put your list of Y hosts that you would like to allow to connect to
# the Y Sound Server in this section:
#
# Note that localhost (127.0.0.1) is always given permission to connect
# when the YIFF server is runned so there is no need to add that here.
#
#echo "Setting up Y host access list..."
#yhost 127.0.0.1

#
# Play a sound object on successful startup:
#
#yplay -m /usr/share/sounds/ring.wav &

echo "Y client service initialization done."
