#!/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/haws/sbin/clhaws_import.sh 1.9 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2004,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)23	1.9 src/43haes/usr/sbin/cluster/haws/sbin/clhaws_import.sh, hacmp.assist, 61haes_r714 11/28/11 14:54:28
#
###############################################################################
#
# This is the main import script used to import either was, dm, tds, or rdb 
# configuration information into HACAMP. The primary intent of this script
# is to provide a wrapper around the actuals scripts that perform the
# import. This wrapper will also provide extensive error checking so
# that the underlying scripts can focus on their specific task rather
# than repeatedly checking for the same error conditions.
#
# This script will call the following low-level scripts:
#
# clhaws_functions - A collection of constants and functions used by all
#                    scripts.
#
# import_was       - Perform the actual import of the Websphere configuration
#                    data
#
# import_dm        - Perform the actual import of the Deployment Manager
#                    data.
#
# import_tds       - Perform the actual import of the TDS configuration
#                    data. Note that this script is a wrapper for calling
#                    into the vendor specific import script.
#
# import_db2       - Perform the actual import of the RDBMS configuration
#                    data. Note that this script is a wrapper for
#                    calling into the vendor specfic import script.
#
#
#
#
MYOPTIND=""


###############################################################################
# Function: usage
###############################################################################
#
# Usage message
###############################################################################
usage() {
     /bin/dspmsg -s 1 haws.cat $MSG_CLHAWS_IMPORT_USAGE "Usage: clhaws_import [-d] [-m] [-t] [-v] -s dm -n node -l service_label\n\
Usage: clhaws_import [-d] [-m] [-t] [-v] -s was -n node -l service_label [-c cell_name] [-o websphere_node]\n\
Usage: clhaws_import [-d] [-m] [-t] [-v] -s db2 -n node -l service_label [-d database_name] -i database_instance_user\n\
Usage: clhaws_import [-d] [-m] [-t] [-v] -s tds -n node -l service_label -w tds_password -p tds_port -i database_instance_user [-o websphere_node]\n\
\n\
Type 'man clhaws_import' for more information.\n\n"
}


###############################################################################
# Function: init
###############################################################################
#
# This code block is common to virtually every script in this package. 
# It's intended to setup basic functionality in common function definitions,
# variable initialization, etc.
###############################################################################
init() {
    # The standard directory for the HAWS software is in
    # /usr/es/sbin/cluster/haws. But this can be changed by setting the
    # environment string HAWS_HOME. 
    if [[ "$HAWS_HOME" = "" ]]; then
        HAWS_HOME=/usr/es/sbin/cluster/haws
    fi

    # Source function library. This is standard for all scripts
    clhaws_functions=$HAWS_HOME/sbin/clhaws_functions
    if [[ ! -f  "$clhaws_functions" ]]; then
        echo "The file '$clhaws_functions' is missing! Unable to continue. Bye"
        exit 1
    fi
    . $clhaws_functions

    # We now call into the generic initialization routine. This will
    # complete the initialization process
    generic_init

    # Once the above clhaws_functions complete, we have all our variables and 
    # functions defined. We can now safely log messages and begin processing.
    logmsg HAWS_TRACE "$MSG_BEGIN" "Begin\n"
}
# end of init()


###############################################################################
# Function: call_subsystem
###############################################################################
#
# The intent of this design is to be able to handle additional subsystems in
# the future. This top-level "import" script is used as a front-end to
# the application-specific import utilities. Given the command line
# 'subsystem' option, call down into the application specific import
# script
###############################################################################
call_subsystem() {
    # Make sure the user specified a subsystem to call
    if [[ "$SUBSYSTEM" = "" ]]; then
	logmsg HAWS_ERROR "$MSG_MISSING_SUBSYS" "You need to specify a subsystem when calling this utility\n"
	exit $HAWS_EXIT_FAIL
    fi
    subsystem_import=$HAWS_HOME/sbin/subsys/$SUBSYSTEM/import
    if [[ ! -f  $subsystem_import ]]; then
	if [[ "$SUBSYSTEM" = "" ]]; then
	    SUBSYSTEM="unspecified"
	fi
        logmsg HAWS_ERROR "$MSG_SUBSYSTEM_INVALID" "Subsystem '%s' was not found!\n" $SUBSYSTEM
        exit $HAWS_EXIT_FAIL
    fi

    logmsg HAWS_INFO "$MSG_CALL_SUBSYSTEM" "Subsystem system called: %s " $subsystem_import
    echo "$*"
    . $subsystem_import $*
}

#
###############################################################################
#
# SCRIPT EXECUTION SECTION
#
###############################################################################
# This section of the script is used to call into the various predefined
# functions composed of the common code, and the script-specific functions.
#
# The intent of this section is to provide a high-level view of how this
# script operates.
###############################################################################


init
logmsg HAWS_LOGONLY "$MSG_IMPORT_START" "Import script starting up on node %s\n" `hostname`
setup_defaults
generic_process_arguments $*
shift `expr $MYOPTIND - 1` 
call_subsystem $*

exit $HAWS_EXIT_SUCCESS
