#!/bin/sh

# Alternate starty script for the YIFF sound server. Use this instead of
# the one generated by yiffconfig!
#
# Features start yiff and wait for Y client resources before printing
# success. Also checks if yiff server is already running.
#

# Locations of YIFF compoents and resources, make any changes as needed.
#
YRECINFO_PROGRAM=/usr/bin/yrecinfo
YIFF_PROGRAM=/usr/sbin/yiff
YIFF_CONFIGURATION=/etc/yiffrc

$YRECINFO_PROGRAM > /dev/null 2> /dev/null
if [ "$?" = "0" ]; then  
 echo "The YIFF Sound Server is already running:"
 ps aux|grep $YIFF_PROGRAM
 exit
fi


# Run the YIFF Sound Server, syntax is; "<program> <config_file>"
# YIFF will put the process into background by itself.
#
echo "Starting YIFF Sound Server..."
$YIFF_PROGRAM $YIFF_CONFIGURATION

# Wait for the YIFF 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 YIFF Sound 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 "\nYIFF Sound Server started successfully."

# Put list of Y hosts that you would like to allow connecting to the
# Y server in this section. Note that localhost (127.0.0.1) is always
# given permission to connect when the YIFF server is runned.
#
echo "Setting up Y host access list..."
#yhost 127.0.0.1

# Play a sound object on successful startup?
#yplay -m /usr/share/sounds/startup1.wav &
echo "Y client service initialization done."
