#! /bin/sh
#
# functions for Setup scripts
#

bcnu_home_dir()
{
# set bcnu home directory
if [ -d /usr/local/bcnu ]
	then
	        BCNUHOME="/usr/local/bcnu"
else
	        printf  "Enter directory name of bcnu home:[/usr/local/bcnu] "
	        read home
	        if [ -z "$home" ]
	                then
	                      BCNUHOME="/usr/local/bcnu"
	                else
	  	              BCNUHOME=$home
	        fi
fi
export BCNUHOME
}

bcnu_system_type()
{
# get the system type

BCNUSERVER=`$BCNUHOME/scripts/unix_version`

printf "The system type appears to be:[$BCNUSERVER] "
read server
if [ ! -z "$server" ]
	then
		BCNUSERVER=$server
fi

if [ ! -s $BCNUHOME/etc/bcnuenv.$BCNUSERVER ]
	then
		echo "The bcnuenv.$BCNUSERVER file is missing"
		echo "If this an unsupported platform, you will need to build"
		echo "binaries and create a [$BCNUHOME/etc/bcnuenv.$BCNUSERVER] file"
		exit
fi

if [ ! -s $BCNUHOME/platform/bcnu.$BCNUSERVER ]
	then
		echo "The binaries are missing for [$BCNUSERVER]"
		echo "if you have installed a source only distribution"
		echo "you will need to build binaries and then run this script again"
		echo "If this an unsupported platform, you will need to build"
		echo "binaries and create a [$BCNUHOME/etc/bcnuenv.$BCNUSERVER] file"
		printf "Do you wish to build binaries for $BCNUSERVER:[y]/n "
		read yorn
		if [ "n" = "$yorn" ]
		        then
				exit
		else
				cd $BCNUHOME/src
				make $BCNUSERVER
				echo
				echo "Restarting setup"
				sleep 5
				exec $BCNUHOME/Setup
		fi
		exit
fi
export BCNUSERVER
}

bcnu_hostname()
{
# get the current host name

BCNUHOST=`uname -n`

printf "The master hostname appears to be:[$BCNUHOST] "
read host
if [ ! -z "$host" ]
	then
		BCNUHOST=$host
fi
export BCNUHOST
}

bcnu_port()
{
# get the service port

BCNUPORT=6666

printf "bcnu will run on the TCP port:[$BCNUPORT] "
read port
if [ ! -z "$port" ]
	then
		BCNUPORT=$port
fi

export BCNUPORT
}

bcnu_sample_agent()
{
# install sample agent config file if required

printf "Do you wish to install a sample agent config file for $BCNUSERVER:[y]/n "
read yorn
if [ "n" = "$yorn" ]
        then
		SAMPLEAGENT="no"
else
		SAMPLEAGENT="yes"
fi
}
