#! /usr/bin/ksh

# @version $Id: createTemplateBuilder.ksh,v 1.4 2008/02/11 20:48:33 dweiner Exp $

#---------------------------------------------------------------------
# Initialization  ------------------------------
#---------------------------------------------------------------------
##
function Initialization
{
#export ORACLE_SID=WP_P1
export db_common=/usr/local/n2bb/watchpoint
export OH=/home/oracle
export ora_base=/home/oracle/admin
export db_scripts=/usr/local/n2bb/watchpoint/watchpointstudio
export ora_backup=/usr/local/n2bb/backup
export l_log=${db_common}/createDatabase.log
export oraver=`basename $ORACLE_HOME`

} #END Initialization

#---------------------------------------------------------------------
# MAIN  --------------------------------------------------------------
#---------------------------------------------------------------------

Initialization

typeset database_name

clear
if test -z "$1"
then
	print ""
	print "\t Tandberg Television WatchPoint Template Builder Schema Creation Wizard"
	print "\t=======================================================\n"
	read database_name?"	What is the name of the existing WatchPoint database where you would like to install the Template Builder schema? The default is [WP_P1] "
else
	database_name="$1"
fi

if [[ -z $database_name ]]
then
  database_name=WP_P1
fi

export ORACLE_SID=${database_name}

sqlplus -s /nolog << EOF
   connect / as sysdba
   PROMPT creating the Template Builder Schema in the ${ORACLE_SID} database PLEASE WAIT
   spool /home/oracle/admin/${ORACLE_SID}/create/createTemplateBuilder.log
   PROMPT ...Creating the TemplateBuilderDB package
   @${db_scripts}/TemplateBuilderDB.pks
   PROMPT ...Executing the TemplateBuilderDB package
   exec sys.TemplateBuilderDB.install_templateBuilder;
   PROMPT
   PROMPT Installation complete.  The results are listed below. 
   select * From install_table;
   select setting_value as "Template Builder Version"
   from WPTB.system_settings 
   where setting_type = 'RELEASE';
   PROMPT
   PROMPT An editional log file is located at ${db_scripts}/createTemplateBuilder.log
   spool off
   exit;
EOF

exit 0
