#!/usr/bin/qsh
#
#  IBM Confidential OCO Source Material
#
#  5724-I63, 5724-H88, 5655-N02, 5733-W70 (C) COPYRIGHT International Business Machines Corp. 2005
#
#  The source code for this program is not published or otherwise divested
#  of its trade secrets, irrespective of what has been deposited with the
#  U.S. Copyright Office.
#
#   CEI/ws/code/cei.configdb/src/dbconfig/sqltemplates/db2iseries/cr_event_db2iseries, WAS.cei.configdb, WAS61.CEI, cf10623.08
#   @Version 1.2 7/27/06
#   
#---------------------------------------------------------------------------
# Description:
# This script is intended to be called from the application or from the
# cr_event_db2 script to create the Event Infrastructure DB2 database 
# on iSeries
#
#---------------------------------------------------------------------------
DB_USERID=$1
DB_PASSWORD=$2

CURRENT_DIR=`dirname $0`
if [ "$CURRENT_DIR" = "." ] ; then
   CURRENT_DIR=`pwd`
fi

#The return code from the script
rc=0

#Collection creation flag
collection_created=0

echo  "db2 -v -t -f $CURRENT_DIR/cr_collection.db2"
db2 -v -t -f $CURRENT_DIR/cr_collection.db2
rc=$?

if [ $rc -eq 0 ] ; then
   collection_created=1
fi

if [ $rc -eq 0 ] ; then
   echo  "db2 -v -t -f $CURRENT_DIR/cr_tbl.db2"
   db2 -v -t -f $CURRENT_DIR/cr_tbl.db2
   rc=$?
fi

if [ $rc -eq 0 ] ; then
   echo  "db2 -v -t -f $CURRENT_DIR/cr_tbl_catalog.db2"
   db2 -v -t -f $CURRENT_DIR/cr_tbl_catalog.db2
   rc=$?
fi

if [ $rc -eq 0 ] ; then
   echo  "db2 -v -t -f $CURRENT_DIR/ins_metadata.db2"
   db2 -v -t -f $CURRENT_DIR/ins_metadata.db2
   rc=$?
fi

if [ $rc -eq 0 ] ; then
   echo  "db2 -v -t -f $CURRENT_DIR/catalogSeed.db2"
   db2 -v -t -f $CURRENT_DIR/catalogSeed.db2
   rc=$?
fi

if [ $rc -eq 0 ] ; then
  cr_stpr
  rc=$?
fi

exit $rc

