#!/bin/ksh
echo \*\*\*
echo \*\*\* MAKE SURE your ORACLE_HOME, ORACLE_SID, PATH, and so on are
echo \*\*\* set appropriately!  This script must be able to utilize
echo \*\*\* sqlplus and sqlldr in order to load information into your
echo \*\*\* instance!
echo \*\*\*
echo \*\*\* This also assumes that CwMLite has already been installed.
echo \*\*\*
echo \*\*\* Next procedure will drop the user cs_olap and the related metadata


if [ $# -ne 2 ]
then
	echo Please specify the following two parameters when running the uninstall:
	echo " location of your Oracle9i cs_olap datafiles"
	echo " location of the shaw.eif file (source of the data for the analytic workspace)"
	echo ""
	echo For example:
	echo $0 d:\Orahome1\oradata\my9iservice d:\beans
	exit 1
fi

checkEnvVar()
{
        parameter=$1
        txt=`env | grep "^$parameter="`

        if [ "$txt" == "" ]
        then
                echo "env variable $parameter not set"
                exit 1
        fi
}

#Check that the Environment 
#Make sure your ORACLE_SID and ORACLE_HOME are correctly set
checkEnvVar ORACLE_HOME
checkEnvVar ORACLE_SID

PAR1=$1
PAR2=$2

echo \*\*\*
echo Removing previous log files
echo \*\*\*

rm -f CHECK_USER.LOG
rm -f DROP.LOG

echo Connecting as SYS user
$ORACLE_HOME/bin/sqlplus "/ as sysdba" @0_check_user.sql $1 $2


grep "CS_OLAP" CHECK_USER.LOG > /dev/null
if [ $? -eq 0 ]
then
	echo \*\*\*
	echo \*\*\* The user CS_OLAP is currently connected and cannot be dropped
	echo \*\*\* Disconnect all CS_OLAP sessions and try again
	echo \*\*\*
	exit 1
fi

echo Connecting as SYS user
sqlplus "/ as sysdba" @1_drop_all.sql $1 $2

echo
echo "Checking for errors in log file"
grep -i "error" DROP.LOG > /dev/null
if [ $? -eq 0 ]
then
echo \*\*\*
echo \*\*\* Errors in the log file, please review file DROP.LOG
echo \*\*\* and resolve the errors before re-running this script 
echo \*\*\*
fi

echo
echo \*\*\*
echo \*\*\* CS_OLAP schema has been removed.  Have fun!
echo \*\*\*






