#!/bin/sh

####################################################
#          DO NOT DELETE THIS LINE.
#          THIS IS LIKE AN INCLUDE FILE.
#          USE IT FOR DEVELOPING SCRIPTS.
. /usr/kits/SystemMate/scripts/stm_script_init
#------------------------------------------------------------------
# Set whether this script must be run by root user
# (default true)
#------------------------------------------------------------------
ROOT_MANDATORY=true

####################################################



####################################################
####################################################
#           TO BE MODIFIED BY THE USER
#                   BEGIN
# 
####################################################
####################################################
# GENERAL COMMENTS:
#
#      1) YOU MUST DEFINE A SINGLE EXIT POINT
#
#      2) THE RETURN STATUS MUST BE 0 FOR COMPLETION
#         AND 1 FOR FAILURE (USE THE EXIT_STATUS VARIABLE)
#
#      3) EXECUTE A COMMAND USING launch_command OR
#         REDIRECT COMMAND OUTPUT TO THE FILE /tmp/trace.$$
#
#      4) USE THE COMMON FUNCTIONS TO LOG ERRORS
#         OR MESSAGES:
#
#               log_OK "string"
#            or log_KO "string"   
#                          for setting a status message
#               log_private_comments "string"
#                          for defining a comment in the 
#                          trace returned by a command
#
#------------------------------------------------------------------
# Set the title of the HTML page and the 
# Netscape window
#------------------------------------------------------------------

TITLE="TeMIP MAP Oracle database install (SNAPSHOT)"

#-----------------------------------------------------------------
#  This function provides help (manpage-like)
#-----------------------------------------------------------------
help()
{
    cat << !EOF!
    Setup the TeMIP MAP Oracle database (SNAPSHOT)
    
    
Syntax: 
      
	`basename $0`   temip_config_path director_user oracle_home 
			oracle_sid oracle_admin_user
			database_name database_ip_domain_name 
			sqlnet_service_name_master sqlnet_service_name_snapshot
			database_sid master_hostname snapshot_hostname
  
Where:

	...
	

Return Values:

	0 Successful execution
	1 Failure

Messages:

        OK:`basename $0` success. Map Oracle database (snapshot) configured.

	KO:`basename $0` failure. Map Oracle database (snapshot) failure.
	KO:`basename $0` failure. Missing script /usr/mcc/map/bin/temip_map_database_setup.
	KO:`basename $0` failure. You must be root.
	KO:`basename $0` failure. Invalid number of parameters.

Restriction:
        * You must be super user to run this script

!EOF!
}




    



#--------------------------------------------------------------------
# Parse command line
# getopt must list all the options supported by 
# the script. The syntax is:
#       option x and arguments required
#       option y without argument required
#       mandatory option is "getopt h"
#
#      set -- `getopt hx:y $*`
#
#

set -- `getopt h $*`


#-----------------------------------------------------------------
# Valid options
#-----------------------------------------------------------------
while [ $1 != -- ]
do
    case $1 in
	-h) OPT="HELP";;
    esac
    shift # next flag
done
shift # skip double dash
  
#------------------------------------------------------
# Check if user is root, if root is mandatory
#------------------------------------------------------
if [ "`id -u`" != 0 ]
then
  log_KO "You must be root."
  EXIT_STATUS=1    
else
  #--------------------------------------------------------------
  # Treat the Help option
  #--------------------------------------------------------------    
  if [ "$OPT" = "HELP" ]
  then
    log_OK "Help option."
    EXIT_STATUS=0
  else      
    #-----------------------------------------------------------------
    # Check the number of parameters
    #-----------------------------------------------------------------
    if [ $# != 12 ]
    then
	log_KO "Invalid number of parameters."
	EXIT_STATUS=1
    else
# temip_config_path director_user oracle_home 
# oracle_sid oracle_admin_user
# database_name database_ip_domain_name 
# sqlnet_service_name_master sqlnet_service_name_snapshot
# database_sid master_hostname snapshot_hostname
	TCP=$1
	DU=$2
	OH=$3
	OS=$4
	OAU=$5
	shift 5
	DN=$1
	DID=$2
	SNM=$3
	SNS=$4
	DS=$5
	MH=$6
	SH=$7
	if [ -f /usr/mcc/map/bin/temip_map_database_setup ]
	then
	    #-------------------------------------------------------------------------
	    # Execute commands using output redirection to the log file: /tmp/trace.$$
	    #-------------------------------------------------------------------------
	    /usr/mcc/map/bin/temip_map_database_setup <<EOF  >> /tmp/trace.$$ 2>&1
$TCP
$DU
$OH
$OS
Y
1
2
3
$OAU
$DN
$DID
$SNM
$SNS
$DS
$MH
$SH
Y
e
EOF
	    case $? in
	    0) EXIT_STATUS=0 
		log_OK "Map Oracle database (snapshot) configured"
	    ;;
	    1) EXIT_STATUS=1
		log_KO "Map Oracle database (snapshot) failure."
		cat /tmp/IMPMNT_ORA/temip_map_ora*.log >> /tmp/trace.$$
	    ;;
	    esac
	else
	    EXIT_STATUS=1
	    log_KO "Missing script /usr/mcc/map/bin/temip_map_database_setup."
	fi # check temip_map_database_setup file exists
    fi # endif number of parameters checking
  fi # endif on Help option
fi # endif root id checking
  
  
####################################################
####################################################
#
#                   END
#
####################################################
####################################################



#---------------------------------------------------
# Concatenate the traces
#---------------------------------------------------
final_log

#---------------------------------------------------
# Return the status
#---------------------------------------------------
exit $EXIT_STATUS




#CHECKSUM-CRC32=2844752057
