#!/bin/sh
#                             YIFF Sound Systems
#
#                      Building and Installation Script
#
#       Run this script to compile the YIFF Sound System components and
#       install them.
#

PROG_NAME="YIFF Sound Server"
YIFF_CONFIG_DIR=/usr/etc
YIFF_CONFIG_FILE=yiffrc
NOSERVER_STR=noserver

# Find the make program and declare the MAKE variable
if [ "`uname | grep BSD`" != "" ]; then
       which gmake >/dev/null
       if [ $? -ne 0 ]; then
               echo "Error: cannot find gmake. gmake can\
 be installed from ports (devel/gmake) and should\
 be in your path."
               exit
       fi
       MAKE=gmake
else
       MAKE=make
fi;

# Print usage?
if [ "$1" = "" ]; then
 echo "Usage: $0 <ostype> [$NOSERVER_STR]"
 echo " "
 echo "    Where <ostype> can be any of the following:"
 echo " "
 echo "        freebsd                 FreeBSD"
 echo "        linux                   Linux"
 echo "        clean                   Removes any work in progress files"
 echo " "
 echo "    Add the option $NOSERVER_STR if you do not want to build the"
 echo "    sound server (for client-only installations)."
 echo " "
 echo "    Example: \"$0 linux\""
 echo " "
 exit
fi

# Clean?
if [ "$1" = "clean" ]; then  
 $MAKE clean
 exit
fi

# Build for particular OS?
case $1 in
linux | freebsd)
       if [ "$2" = "$NOSERVER_STR" ]; then
               $MAKE linux_noserver
       else
               $MAKE linux
       fi ;;
*) echo "Invalid ostype" && exit ;;
esac


# About to install, check if EUID is root?
if [ "$EUID" != "0" ]; then
 echo "-------------------------------------------------------------------------"
 echo "To continue with installation, root privileges are required."
 echo "Enter password for root."
fi

# Install
if [ "$2" = "$NOSERVER_STR" ]; then
 su root -c $MAKE\ install_noserver
else
 su root -c $MAKE\ install
fi

# Done installation message
echo "$PROG_NAME build and installation complete."

# If complete installation, then advise user to manually install default
# yiff sound server configuration file
if [ "$2" != "$NOSERVER_STR" ]; then
 echo " "
 echo "Note that if you do not have a YIFF Sound Server configuration"
 echo "file (yiffrc) installed on your system (ie if this is your"
 echo "first installation) then you should manually install the"
 echo "default one found in yiff/yiffrc to either /usr/etc or /etc."
 echo " "
 echo "If no errors were encountered, then you should run yiffconfig to"
 echo "set up the configuration file for the YIFF Sound Server."
fi
