#!/bin/csh -f
# 
# $Header: create.sh,v 1.4 93/11/04 09:42:29 arhee:ar_xtp1 Exp $ 
# 
#  Copyright (c) 1991 by Oracle Corporation 
#    NAME
#      create.sh - <one-line expansion of the name>
#    DESCRIPTION
#      <short description of component this file declares/defines>
#    RETURNS
# 
#    NOTES
#      <other useful comments, qualifications, etc.>
#    MODIFIED   (MM/DD/YY)
#     arhee      11/16/93 -  update 
#     arhee      07/20/93 -  change ofs semantices 
#     gpriores   03/11/93 -  Make tpcb home directory 
#     gpriores   03/01/93 -  Creation 
#
# Create and load data into a database for the demo system.
# createfs.sh MUST have been run first to set up the filesystem.
# On entry, this script respects certain environment variables listed below:
#
# Variable:		Default Value if Unset in Environment:
# ---------		--------------------------------------
# ORACLE_PSRV		TPCD
# ORACLE_HOSTHOME	/usr/scratch/oracle71/orahost
# ORACLE_HOME		$ORACLE_HOSTHOME/orahome //df00/usr/oracle71
# TPCD_HOME		/home/R8D/dba/TPCD
# NROOTLOCAL		/usr/ncube/current/local
#
# Also, the scripts expects the file $TPCB_HOME/config/$ORACLE_PSRV.params
# to exist and contain your configuration information.  If you have no such
# file, then copy TPCB.params from the same directory and modify it accordingly.

# Set up our environment
#
# We could be invoked from Bourne shell, so we need to check environment 
# variables twice, once for not being set, and once for being set to nothing. 
#
if ($?ORACLE_PSRV == 0) then
	setenv ORACLE_PSRV	TPCD
	else if ( $ORACLE_PSRV == ) then
		setenv ORACLE_PSRV	TPCD
	endif
endif
if ($?ORACLE_HOSTHOME == 0) then
	setenv ORACLE_HOSTHOME	/usr/scratch/oracle71/orahost
	else if ( $ORACLE_HOSTHOME == ) then
		setenv ORACLE_HOSTHOME	/usr/scratch/oracle71/orahost
	endif
endif
if ($?ORACLE_HOME == 0) then
	setenv ORACLE_HOME	$ORACLE_HOSTHOME/orahome
	else if ( $ORACLE_HOME == ) then
		setenv ORACLE_HOME	$ORACLE_HOSTHOME/orahome
	endif
endif
if ($?TPCD_HOME == 0) then
	setenv TPCD_HOME	/home/R8D/dba/TPCD
	else if ( $TPCD_HOME == ) then
		setenv TPCD_HOME	/home/R8D/dba/TPCD
	endif
endif
if ($?NROOTLOCAL == 0) then
	setenv NROOTLOCAL      /usr/ncube/current/local
	else if ( $NROOTLOCAL == ) then
		setenv NROOTLOCAL      /usr/ncube/current/local
	endif
endif

# Grab data from the configuration files.
#set config_file = $TPCD_HOME/config/$ORACLE_PSRV.params
#if ( ! -r $config_file ) then
#  echo "Before running this script, you need to create "
#  echo "a personalized $config_file"
#  exit
#endif
#source $config_file
#source $TPCD_HOME/config/general.params

# Start generating configuration files.
#echo "Creating init.ora files"
#cd $TPCD_HOME/config
#sed "s+DBDIR+$DBDIR+g" tpcdinit.ora > ${ORACLE_PSRV}tpcdinit.ora
#sed "s+DBDIR+$DBDIR+g" tpcdcreate.ora > ${ORACLE_PSRV}tpcdcreate.ora
#sed "s+TPCB+$ORACLE_PSRV+g" tpcd.sql | \
#sed "s+DBDIR+$DBDIR+g" | sed "s+LOGDIR+$LOGDIR+g" > ${ORACLE_PSRV}tpcd.sql

#echo "Copying init.ora files to $ORACLE_HOME/dbs"
#xnc rm -rf $ORACLE_HOME/dbs/${ORACLE_PSRV}tpcb{init.ora,create.ora}
#xnc cp ${ORACLE_PSRV}tpcb{init.ora,create.ora} $ORACLE_HOME/dbs

# Generate the configuration file based on our environment variables.
#set conf_file = "$TPCB_HOME/config/${ORACLE_PSRV}tpcb.conf"
#echo "Creating psm config file: $conf_file"
# If you add these here, then you can't change the matching env var on the fly
# and just do run.sh.  You would always have to re-run create.sh first.
#echo oracle_psrv = \"$ORACLE_PSRV\" > $conf_file
#echo oracle_hosthome = \"$ORACLE_HOSTHOME\" >> $conf_file
#echo oracle_home = \"$ORACLE_HOME\" >> $conf_file
#echo ncube_local_dir = \"$NROOTLOCAL\" >> $conf_file
#echo "num_inst = $NUM_INST" > $conf_file
#echo "oracle_comm_size = 131072" >> $conf_file
#echo init_ora = \"%h/dbs/${ORACLE_PSRV}tpcbinit.ora\" >> $conf_file
#if ( $?ORACLE_PATH != 0 ) then
#	if ( $ORACLE_PATH != ) then
#		echo oracle_path = \"$ORACLE_PATH\" >> $conf_file
#	endif
#endif

# Make sure $DBDIR exists
#echo Attempting to create $DBDIR
#xnc mkdir $DBDIR

# Create the database.
echo "Creating the tpcd database..."
#$ORACLE_HOSTHOME/bin/pstart -c $TPCD_HOME/config/${ORACLE_PSRV}tpcb.conf $VERBOSE -x inst -n 1
$ORACLE_HOSTHOME/bin/pstart -c $TPCD_HOME/TPCD.conf $VERBOSE -x inst -n 1

set sharepid = "`xnc $NROOTLOCAL/bin/ncube/nspcmd lookup ${ORACLE_PSRV}nhold`"
set invoke = $NROOTLOCAL/bin/ncube/invoke

xnc -p $sharepid -h 0 $invoke $ORACLE_HOME/bin/sqldba <<!
	@/$TPCD_HOME/tpcd_db.sql
#	@/host$TPCB_HOME/config/${ORACLE_PSRV}tpcb.sql

	connect internal;
#	startup pfile=?/dbs/${ORACLE_PSRV}tpcbcreate.ora open tpcbdemo;
	shutdown;
	exit;
!

# Load the database.
#@ nbran = 2000		# number of branches in the database
#@ ntell = 20000		# number of tellers in the database
#@ nacct = 2000000	# number of accounts in the database

#echo "Loading $nbran branches..."
#xnc -p $sharepid -h 0 $invoke $ORACLE_HOME/bin/sqlload tp1/tp1 \
#	/host$TPCB_HOME/load/bran.ctl \
#	/host$TPCB_HOME/load/bran.log direct=true rows=10000 load=$nbran

#echo "Loading $ntell tellers..."
#xnc -p $sharepid -h 0 $invoke $ORACLE_HOME/bin/sqlload tp1/tp1 \
#	/host$TPCB_HOME/load/tell.ctl \
#	/host$TPCB_HOME/load/tell.log direct=true rows=10000 load=$ntell

#echo "Loading $nacct accounts..."
#xnc -p $sharepid -h 0 $invoke $ORACLE_HOME/bin/sqlload tp1/tp1 \
#	/host$TPCB_HOME/load/acct.ctl \
#	/host$TPCB_HOME/load/acct.log direct=false rows=10000 load=$nacct

# Load standard.sql then shutdown the database.
xnc -p $sharepid -h 0 $invoke $ORACLE_HOME/bin/sqldba <<!
	connect internal;
	@$ORACLE_HOME/rdbms/admin/standard.sql
	@$ORACLE_HOME/rdbms/admin/dbmsstdx.sql
	@$ORACLE_HOME/rdbms/admin/dbmsutil.sql
        @/host$TPCB_HOME/config/trigger.sql
	@$ORACLE_HOME/rdbms/admin/catparr.sql
	shutdown;
	exit;
!
#$ORACLE_HOSTHOME/bin/pstop $VERBOSE -c $TPCB_HOME/config/${ORACLE_PSRV}tpcb.conf 
$ORACLE_HOSTHOME/bin/pstop $VERBOSE -c $TPCD_HOME/TPCD.conf 

echo "If nothing went wrong, the TPCD database should now be created and the data is not loaded."
