#!/sbin/sh

########
# Product:  GraphicsPEX5RT
# Fileset:  PEX5-DEMOS
# configure
#
# $Source: /hmstmp/update.22059/./release/SD/GraphicsPEX5v2/PEX5-DEMOS/configure,v $
# $Revision: 550.2 $
# $Date: 96/07/16 12:22:14 $
#
########
#
# (c) Copyright Hewlett-Packard Company 1994
#
########

	set -a       					# export all vars
	exitval=0					# anticipate success

	UTILS="/usr/lbin/sw/control_utils"
	if [[ ! -f $UTILS ]]
	then
		echo "ERROR:    Cannot find UTILS"
		exit 1
	fi
	. $UTILS

################################################################################
#set -x # For debugging purposes.  _Never_ ship uncommented!!

	##
	## Set up local env. vars.
	##

	SW_INSTALL_DIR="/"

	##
	## Test to see if either SW_ROOT_DIRECTORY or SW_LOCATION is
	## set to something other than /.  If so, set up SW_INSTALL_DIR
	## so it will not have spurious /'s in the path name.
	##
	
	if [ $SW_ROOT_DIRECTORY != / -o $SW_LOCATION != / ]
	then
		if [ $SW_ROOT_DIRECTORY != / ]
		then
			if [ $SW_LOCATION != / ]
			then
				SW_INSTALL_DIR="${SW_ROOT_DIRECTORY}${SW_LOCATION}"
			else
				SW_INSTALL_DIR="${SW_ROOT_DIRECTORY}"
			fi
		else
			if [ $SW_LOCATION != / ]
			then
				SW_INSTALL_DIR="${SW_LOCATION}"
			fi
		fi
	fi

	PEX_DIR=$SW_INSTALL_DIR
	DEMOS_DIR=${PEX_DIR}demos
	DRIVE_DIR=${DEMOS_DIR}/drive
	DRIVE_README=drive.6

	SERVICES=${SW_ROOT_DIRECTORY}etc/services

	if [ -f "$SERVICES" ]
	then
		##
		## Check for NIS
		##
		if [ ! -z "`ps -ef | grep ypb | grep bind`" ]
		then
			echo "WARNING: This system is running NIS (formerly known as Yellow Pages)."
			echo "         Contact your NIS Master Server adminstrator to have drive"
			echo "         and drivequery added to the master /etc/services."
			echo "         Refer to the GETTING STARTED section in the"
			echo "         ${DRIVE_DIR}/${DRIVE_README} instructions file."
			exitval=$WARNING		
			exit $exitval
		fi
		
		##
		## Check to see if the services are already in use
		##
		if [ ! -z "`egrep '22747/tcp' $SERVICES`" -o \
		     ! -z "`egrep '22748/udp' ${SERVICES}`" ]
		then
			##
			## Make sure that drive services are the ones being used.
			##
			if [ -z "`egrep '^drive[ 	][ 	]*22747/tcp' ${SERVICES}`" ]
			then
				DRIVE_SERVICE_PRESENT=False
		
				echo "WARNING: The service 22747/tcp in ${SERVICES}"
				echo "         is currently in use by someting other than PEXdrive."
				exitval=$WARNING		
			else
				DRIVE_SERVICE_PRESENT=True
			fi
		
			if [ -z "`egrep '^drivequery[ 	][ 	]*22748/udp' ${SERVICES}`" ]
			then
				DRIVEQUERY_SERVICE_PRESENT=False
		
				echo "WARNING: The services 22748/udp in ${SERVICES}"
				echo "         is currently in use by something other than PEXdrive."
				exitval=$WARNING		
			else
				DRIVEQUERY_SERVICE_PRESENT=True
			fi
		
			##
			## Emit warning that one or both of the required services are unavailable.
			##
			if [ "X${DRIVE_SERVICE_PRESENT}" = "XFalse"	\
			      -o "X${DRIVEQUERY_SERVICE_PRESENT}" = "XFalse" ]
			then
				echo "WARNING: One or both of the required services for PEXdrive are currently"
				echo "         in use by something other than PEXdrive, the PEX5 drive demo."
				echo "         PEXdrive will not run without these services.  Contact your System"
				echo "         Administrator to configure the ${SERVICES} file to allow PEXdrive"
				echo "         to use these services.  Refer to the GETTING_STARTED section in the"
				echo "         ${DRIVE_DIR}/${DRIVE_README} instructions file for"
				echo "         additional information."
				exitval=$WARNING
			fi
		else	
	
			##
			## Add the drive services if not already present
			##
			if [ -z "`egrep '^drive[ 	][ 	]*' ${SERVICES}`" ]
			then
				echo "NOTE:    Added 'drive	22747/tcp	# Driving simulator' to"
				echo "         ${SERVICES} file."
				echo "drive		22747/tcp	# Driving simulator" >> ${SERVICES}
			fi
	
			if [ -z "`egrep '^drivequery[ 	][ 	]*' ${SERVICES}`" ]
			then
				echo "NOTE:    Added 'drivequery	22748/tcp	# Driving simulator server search' to"
				echo "         ${SERVICES} file."
				echo "drivequery	22748/udp	# Driving simulator server search" >> ${SERVICES}
			fi
		fi
	else
		echo "WARNING: The system services file, $SERVICES is not present on the"
		echo "         system at the time this configuration script was run and the"
		echo "         required \"drive\" and \"drivequery\" services were not added."
		echo "         PEXdrive will not run without these services.  Contact your System"
		echo "         Administrator to configure the ${SERVICES} file to allow PEXdrive"
		echo "         to use these services.  Refer to the GETTING_STARTED section in the"
		echo "         ${DRIVE_DIR}/${DRIVE_README} instructions file for"
		echo "         additional information."
	fi

	ETC_DIR="${SW_ROOT_DIRECTORY}etc/opt/PEX5"
	SERVER_CONFIG="$ETC_DIR/.server_config"

	##
	## Put the new .server_config file into place
	##
	newconfig_cp $SERVER_CONFIG
	STATUS=$?
	newconfig_msgs $STATUS

	exit $exitval
################################################################################
