#!/bin/sh
#
# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
# SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
#

#
# @(#)setup	1.44   02/01/12
#


#
# Check CTS_HOME env var - exit w/message if not set
#
if [ -z "${CTS_HOME}" ]
then
    echo "ERROR: CTS_HOME is NOT SET!! "
    echo "Please set CTS_HOME (ie: /files/j2eects ) before running setup."
    echo "Setup is INCOMPLETE - Exiting $0"
    exit 1
fi

#
# Inform user of the current CTS_HOME setting and platform
#
echo "PLATFORM is: UNIX" 
echo "CTS_HOME is set to: ${CTS_HOME}"

#
# Define the CTS common bin files (non-platform specific)
#
COMMON_BIN="java.security.auth.policy harness.policy login.config java.policy cts.jte cts.jtx ctssql.stmt ctssql.ddl.oracle ctssql.dml.oracle ctssql.ddl.cloudscape ctssql.dml.cloudscape genrpt server_policy.append login_config.append"

#
# Define the platform specific bin files - UNIX/SOLARIS
#
CONFIG_SOLARIS="cts_env cts_version cts sample.jtp startRMIIIOPServer startSunRIPortingServer sweep initdb ctsmake"

#
# Test for the existance of the CTS_HOME dir; report any errors and exit
#
if [ ! -d ${CTS_HOME} ]
then
	echo "ERROR: ${CTS_HOME} doesn't exist!"
	echo "You must set CTS_HOME to a valid path before running setup!"
	echo "Setup is INCOMPLETE - Exiting $0"
	exit 1
else
	if [ -d ${CTS_HOME}/bin ]
	then
		echo "Saving existing bin directory to bin.bak"
		echo
		if [ !  -d ${CTS_HOME}/bin.bak ]
		then
                	mv ${CTS_HOME}/bin ${CTS_HOME}/bin.bak
		else
			echo "ERROR: ${CTS_HOME}/bin.bak exists!"
			echo "You must move this backup directory and try again"
			echo "Setup is INCOMPLETE - Exiting $0"
			exit 1
		fi
			
	fi
#
# Create a fresh bin directory ; report any errors and exit if any are
# encountered.
#
	mkdir ${CTS_HOME}/bin
	if [ "$?" -ne 0 ]
	then
		echo "ERROR: Could not create ${CTS_HOME}/bin dir!"
		echo "Setup is INCOMPLETE - Exiting $0"
		exit 1
	fi

fi

#
# Copy the defined common bin files (non-platform specific) to the
# newly created bin dir; report any errors and exit if the copy fails.
#
for bin_file in ${COMMON_BIN}
do
	cp ${CTS_HOME}/install/common.bin/$bin_file ${CTS_HOME}/bin
	if [ "$?" -ne 0 ]
	then
		echo "ERROR: Copy of common.bin/$bin_file FAILED"
		echo "Setup is INCOMPLETE - Exiting $0"
		exit 1
	fi
done

#
# Copy the defined platform specific bin files to the
# newly created bin dir; report any errors and exit if the copy fails.
#
for bin_file in ${CONFIG_SOLARIS}
do
	cp ${CTS_HOME}/install/config.solaris/$bin_file ${CTS_HOME}/bin
	if [ "$?" -ne 0 ]
	then
		echo "ERROR: Copy of config.solaris/$bin_file FAILED"
		echo "Setup is INCOMPLETE - Exiting $0"
		exit 1
	fi
done


#
# Make the bin directory and all files write/execute by all
#
chmod -R 777 ${CTS_HOME}/bin


#
# Source in the cts_env file , report current values, and verify paths
#

. ${CTS_HOME}/bin/cts_env

echo "JAVA_HOME is set to: ${JAVA_HOME}"
echo "TZ is set to: ${TZ}"
echo
echo "Settings for Vendor Implementation"
echo "J2EE_HOME is set to: ${J2EE_HOME}"
echo "ORB_HOST is set to: ${ORB_HOST}"
echo "ORB_PORT is set to: ${ORB_PORT}"
echo "LOCAL_CLASSES is set to: ${LOCAL_CLASSES}"
echo
echo "Settings for Sun Implementation"
echo "J2EE_HOME_RI is set to: ${J2EE_HOME_RI}"
echo "ORB_HOST_RI is set to: ${ORB_HOST_RI}"
echo "ORB_PORT_RI is set to: ${ORB_PORT_RI}"
echo "LOCAL_CLASSES_RI is set to: ${LOCAL_CLASSES_RI}"
echo
echo "You must edit the file: ${CTS_HOME}/bin/cts_env and set the following"
echo "environment variables to valid values after setup completes:"
echo 
echo "JAVA_HOME J2EE_HOME ORB_HOST ORB_PORT LOCAL_CLASSES"
echo "J2EE_HOME_RI ORB_HOST_RI ORB_PORT_RI LOCAL_CLASSES_RI TZ"
echo 

#
# Report successful completion 
#
echo "Setup is COMPLETE."

