 ################################################################################
#
# File:         kirsnscrits 
# Description:  Common ITO Software Maintenance procedures
# Language:     Bourne Shell
# Package:      HP OpenView IT/Operations
#
# (c) Copyright 1993 - 2008 Hewlett-Packard Development Company, L.P.
#
################################################################################

  NSLOOKUP="/usr/sbin/nslookup"
  IFCONFIG="/usr/sbin/ifconfig"
  GREP="/usr/xpg4/bin/grep"
  AWK="/usr/xpg4/bin/awk"



#==============================================================================
#
#  Read the debug configuration file and set global debug environment variables
#  Configuration file is read only when owner is root.
#  After the file is read, following environment variables are checked and
#  exported:
#  Environment variables for command tracing
#    OPC_DEBUG_LOCAL  .. enables local debugging
#    OPC_DEBUG_REMOTE .. enables remote debugging
#    OPC_DEBUG_FILE   .. debug logfile name, set to /dev/null when file
#                        can't be created
#    OPC_DEBUG_APPEND .. controls if debug file will be appended or overwritten
#    OPC_DEBUG_ALL    .. suspends local debugging of message handling
#                        common shell functions (oi_errror..)
#  Environment variables for event tracing
#    OPC_TRACE        .. enables event tracing
#    OPC_TRACE_FILE   .. trace logfile name; equals installation logfile
#
oi_init_debug()
{
    OPC_DEBUGF=${OPC_TMPFILES_DIR}/inst_debug.conf
    if [ -f ${OPC_DEBUGF} ]
    then
        # check is debug configuration file is is owned by root
        T_USER=`id -u -n`
        T_FILE=`find ${OPC_TMPFILES_DIR} -name inst_debug.conf -user ${T_USER}`
        if [ -n "${T_FILE}" ]
        then
            . ${OPC_DEBUGF}
        fi
        unset T_USER T_FILE
    fi

    if [ -n "${OPC_DEBUG_LOCAL}" -o -n "${OPC_DEBUG_REMOTE}" ]
    then
        if [ -z "${OPC_DEBUG_FILE}" ]
        then
            OPC_DEBUG_FILE=/dev/null
        else
            if [ "${OPC_DEBUG_APPEND}" != "YES" ]
            then
                rm -f ${OPC_DEBUG_FILE}
            fi
            touch ${OPC_DEBUG_FILE}
            if [ ! -w ${OPC_DEBUG_FILE} ]
            then
                OPC_DEBUG_FILE=/dev/null
            else
                chmod 600 ${OPC_DEBUG_FILE}
                chown `id -u -n` ${OPC_DEBUG_FILE}
            fi
        fi
        if [ -z "${OPC_DEBUG_CALLOUT}" ]
        then
            OPC_DEBUG_CALLOUT="dummy"
        fi
        if [ -z "${OPC_DEBUG_ALL}" ]
        then
            OPC_DEBUG_ALL="NO"
        fi
        I_USR=root              # has been checked previously
        I_DATE_STR=`TZ=${OPC_TIME_ZONE} date +${I_DATE}`
        I_TIME_STR=`TZ=${OPC_TIME_ZONE} date +${I_TIME}`
        oi_debug opc 012 >> ${OPC_DEBUG_FILE}
        oi_debug opc 013 ${CMD_NAME} ${I_USR} ${I_DATE_STR} ${I_TIME_STR} \
                 >> ${OPC_DEBUG_FILE}
        oi_debug opc 014 >> ${OPC_DEBUG_FILE}
        OPC_DEBUG_LINE=`oi_debug opc 598`
        export OPC_DEBUG_LINE
    fi

    export OPC_DEBUG_FILE OPC_DEBUG_LOCAL OPC_DEBUG_REMOTE
    export OPC_DEBUG_CALLOUT OPC_DEBUG_ALL

    if [ "${OPC_TRACE}" = "YES" ]
    then
        LANG=$OPC_CALL_LANG TRACE_HEADER=`oi_msg opc 588 MODULxxxxxxx \
                                                         SCRIPTxxxxxx`
        export TRACE_HEADER
    fi
    OPC_TRACE_FILE=${OPC_LOGF}
    export OPC_TRACE OPC_TRACE_FILE

    return 0
}


#==============================================================================
#
#  Print debug  message on stdout.
#  No message qualifier is used.
#
oi_debug()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_DEB=$1; shift
    MSG_DEB=$1; shift
    PAR_DEB="$*"
    LANG=$OPC_CALL_LANG echo `oi_msg "$CAT_DEB" "$MSG_DEB" "$PAR_DEB"`
    unset PAR_DEB CAT_DEB MSG_DEB

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}


#==============================================================================
#
#  Print TRACE message on trace logfile
#  dependent on of OPC_TRACE mode.
#
oi_trace()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    if [ "${OPC_TRACE}" = "YES" ]
    then
        CAT_DEB=$1; shift
        MSG_DEB=$1; shift
        PAR_DEB=""
        while [ $# != 0 ]
        do
            PAR_DEB="${PAR_DEB} "`echo $1 | sed -e 's/ /_/g'`
            shift
        done
        LANG=$OPC_CALL_LANG TEXT_L=`oi_msg "$CAT_DEB" "$MSG_DEB" "$PAR_DEB"`
        echo "TRACE:    $TEXT_L" >> $OPC_TRACE_FILE
        unset PAR_DEB CAT_DEB MSG_DEB TEXT_L
    fi

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

}

#==============================================================================
#
#  Before exit from callout shell script, record this on debug logfile
#  and generate event tracing message too.
#
EXIT()
{
    EXIT_VAL=$1
    oi_trace opc 589 ${MODULE_NAME} ${CALLOUT_NAME} ${EXIT_VAL}

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    if [ "${OPC_DEBUG}" = "YES" ]
    then
        echo "${OPC_DEBUG_LINE}" 1>&2
        echo "*** END   LOCAL ${MODULE_NAME} [${SCRIPT_NAME}]" 1>&2
    fi

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    exit ${EXIT_VAL}
}

#==============================================================================
#
#  DESCRIPTION
#    Message handling functions display messages to standard output with
#    respect to requested platform message catalog. All messages are uniquelly
#    formatted according to the standard imposed by SD for control scripts.
#    Environment shell variables are set according to specification in
#    oi_environ(1m).
#    Parameters passed to shell scripts are decoded as far as necessary and
#    always quoted to avoid problems with empty parameters during shell
#    function calls.
#    Local shell function variables are distinguished by function name to
#    avoid unsetting problems when functions are from other functions.
#
#  PARAMETERS
#    All messaging shell functions have common parameter interface.
#
#    OPC_OS_NICKNAME or
#    "opc"             When message from platform dependent catalog is required,
#                      nickname of that platform must be specified.
#                      Catalog named <OPC_OS_NICKNAME>inst.cat will be used.
#                      When message from global catalog (opcinst.cat) is
#                      required this parameter must be set to string "opc".
#    message_number .. Message number in corresponding catalog.
#    parameters     .. List of parameters needed by message. may be empty.
#
#  EXIT CODE
#    0 .. always 0
#

BIN_DIR=/usr/bin
OS_DIR=/usr
OPT_DIR=/opt
VAR_DIR=/var/opt
ETC_DIR=/etc/opt

OPC_OPT_DIR=${OPT_DIR}/OV

OPCAGT_NLS_DIR=${OPC_OPT_DIR}/locale
OPCSVR_NLS_DIR=${OPC_OPT_DIR}/locale

# localization
LANG_C=C
LANG_SJIS=ja_JP.PCK
LANG_EUC=japanese

# oratab location
ORATAB_LOC=/var/opt/oracle/oratab






GREP=/usr/xpg4/bin/grep

# for agents we may need a different root directory e.g. in a cluster
# environment else it is the root directory
#
ROOT_DIR=${ROOT_DIR:-""}

# defined in every script - the version of this script
INST_OPCVERS=A.08.30

# prerequisites:
#---------------
#
# the paths
#
#   OPT_DIR     e.g. /opt
#   VAR_DIR     e.g. /var/opt
#   ETC_DIR     e.g. /etc/opt
#
# must be defined before using this module
#
# Naming Scheme
# <prog>_<name>_DIR     1 directory e.g. OV_<name>_DIR, OPC_<name>_DIR
# <name>_PATH           several directories delimited by ":"
#
TMP_DIR=${ROOT_DIR}/tmp/opc_tmp

#-------------------------------------
# generic paths
#-------------------------------------
# /opt/OV
OV_OPT_DIR=${OV_OPT_DIR:-${ROOT_DIR}${OPT_DIR}/OV}
OPC_OPT_DIR=${OPC_OPT_DIR:-${OV_OPT_DIR}}
# /var/opt/OV
OV_VAR_DIR=${OV_VAR_DIR:-${ROOT_DIR}${VAR_DIR}/OV}
OV_VAR_SH_DIR=${OV_VAR_SH_DIR:-${OV_VAR_DIR}/share}
OPC_VAR_DIR=${OPC_VAR_DIR:-${OV_VAR_DIR}}
# /etc/opt/OV
OV_ETC_DIR=${OV_ETC_DIR:-${ROOT_DIR}${ETC_DIR}/OV}
OV_ETC_SH_DIR=${OV_ETC_SH_DIR:-${OV_ETC_DIR}/share}
OPC_ETC_DIR=${OPC_ETC_DIR:-${OV_ETC_DIR}/share}

OV_NEWCFG_DIR=${OV_NEWCFG_DIR:-${OV_OPT_DIR}/newconfig}
OV_OLDCFG_DIR=${OV_OLDCFG_DIR:-${OV_OPT_DIR}/old}

# WWW
OV_WWW_DIR=$OV_OPT_DIR/www

# /opt/OV
OV_OPT10_DIR=${OV_OPT10_DIR:-${ROOT_DIR}${OPT10_DIR}/OV}
# /var/opt/OV
OV_VAR10_DIR=${OV_VAR10_DIR:-${ROOT_DIR}${VAR10_DIR}/OV}
OV_VAR10_SH_DIR=${OV_VAR10_SH_DIR:-${OV_VAR10_DIR}/share}
# /etc/opt/OV
OV_ETC10_DIR=${OV_ETC10_DIR:-${ROOT_DIR}${ETC10_DIR}/OV}
OV_ETC10_SH_DIR=${OV_ETC10_SH_DIR:-${OV_ETC10_DIR}/share}

#-------------------------------------
# SD paths
#-------------------------------------
OPC_SD_DIR=${OPC_SD_DIR:-/usr/sbin}
#-------------------------------------
# Sun Cluster paths
#-------------------------------------
OPC_SC_BIN_DIR=${OPC_SC_BIN_DIR:-/opt/SUNWcluster/bin}
OPC_SC_ETC_DIR=${OPC_SC_ETC_DIR:-/etc/opt/SUNWcluster}
OPC_SC_VAR_DIR=${OPC_SC_VAR_DIR:-/var/opt/SUNWcluster}
#-------------------------------------
# VERITAS Cluster Server paths
#-------------------------------------
OPC_VC_BIN_DIR=${OPC_VC_BIN_DIR:-/opt/VRTSvcs/bin}
OPC_VC_LOG_DIR=${OPC_VC_LOG_DIR:-/var/VRTSvcs/log}
OPC_VC_CFG_DIR=${OPC_VC_CFG_DIR:-/etc/VRTSvcs/conf}
#-------------------------------------
# Sol High Availability SW Solutions
#-------------------------------------
OPC_HA_VC_SW=${OPC_HA_VC_SW:-VeritasClusterServer}
OPC_HA_SC_SW=${OPC_HA_SC_SW:-SunCluster}

#-------------------------------------
# OpenView paths
#-------------------------------------
OV_BIN_DIR=${OV_BIN_DIR:-${OV_OPT_DIR}/bin}
OV_TMP_DIR=${OV_TMP_DIR:-${OV_VAR_DIR}/tmp}
OV_LOG_DIR=${OV_LOG_DIR:-${OV_VAR_DIR}/log}
OV_CFG_DIR=${OV_CFG_DIR:-${OV_ETC_DIR}/share/conf}
OV_ALT_CFG_DIR=${OV_ALT_CFG_DIR:-${OV_ETC_DIR}/share/\#conf}

#-------------------------------------
# ITO Server Paths
#-------------------------------------
# /usr/OV/bin/OpC
OPCSVR_BIN_DIR=${OPCSVR_BIN_DIR:-${OPC_OPT_DIR}/bin/OpC}
# /usr/OV/bin/OpC/install
OPCSVR_INST_DIR=${OPCSVR_INST_DIR:-${OPCSVR_BIN_DIR}/install}
# /opt/OV/lib
OPCSVR_LIB_DIR=${OPCSVR_LIB_DIR:-${OPC_OPT_DIR}/lib}
# /opt/OV/nls
OPCSVR_NLS_DIR=${OPCSVR_NLS_DIR:-${OPCSVR_LIB_DIR}/nls}
# /opt/OV/include
OPCSVR_INC_DIR=${OPCSVR_INC_DIR:-${OPC_OPT_DIR}/include}
# /usr/OV/bin/OpC/utils
OPCSVR_UTIL_DIR=${OPCSVR_UTIL_DIR:-${OPCSVR_BIN_DIR}/utils}
# /usr/OV/bin/OpC/agtinstall
OPCSVR_AGTINST_DIR=${OPCSVR_AGTINST_DIR:-${OPCSVR_BIN_DIR}/agtinstall}
# /etc/opt/OV/share/lrf
OPCSVR_OPC_DIR=${OPCSVR_OPC_DIR:-${OPC_OPT_DIR}/OpC}
OPCSVR_NEWCFG_DIR=${OPCSVR_NEWCFG_DIR:-${OV_NEWCFG_DIR}/OpC}
OPCSVR_OLDCFG_DIR=${OPCSVR_OLDCFG_DIR:-${OV_OLDCFG_DIR}/OpC}
OPCSVR_HELP_DIR=${OPCSVR_HELP_DIR:-${OV_VAR_DIR}/share/help}

# /etc/opt/OV directories
OPCSVR_LRF_DIR=${OPCSVR_LRF_DIR:-${OPC_ETC_DIR}/lrf}
OPCSVR_REG_DIR=${OPCSVR_REG_DIR:-${OPC_ETC_DIR}/registration}

# /var/opt/OV/share/databases
OPCSVR_DB_DIR=${OPCSVR_DB_DIR:-${OPC_VAR_DIR}/share/databases/OpC}
# /var/opt/OV/share/databases/OpC/mgd_node/vendor
OPCSVR_VEND_DIR=${OPCSVR_DB_DIR}/mgd_node/vendor
# /var/opt/OV/share/databases/OpC/mgd_node/customer
OPCSVR_CUST_DIR=${OPCSVR_DB_DIR}/mgd_node/customer

# dynamic paths
OPCSVR_TMP_DIR=${OPCSVR_TMP_DIR:-${OPC_VAR_DIR}/share/tmp/OpC}
OPCSVR_LOG_DIR=${OPCSVR_LOG_DIR:-${OPC_VAR_DIR}/log/OpC}
OPCSVR_CFG_DIR=${OPCSVR_CFG_DIR:-${OPC_ETC_DIR}/conf/OpC}
OPCSVR_APPL_DIR=${OPCSVR_APPL_DIR:-${OPC_VAR_DIR}/share/tmp/OpC_appl}
OPCSVR_MAN_DIR=${OPCSVR_MAN_DIR:-${OPC_OPT_DIR}/man}

OPCSVR_INFO_F=${OPCSVR_INFO_F:-${OPCSVR_INST_DIR}/opcsvinfo}
OPCAGT_INFO_F=${OPCAGT_INFO_F:-${OPCSVR_INST_DIR}/opcinfo}

# Config file needed by distributed GUI client
OPC_GUICLT_MSV_F=${OPC_GUICLT_MSV_F:-${OV_CFG_DIR}/opc_guiclt_msv}
OPC_GUICLT_TMP_MSV_F=${OPC_GUICLT_TMP_MSV_F:-/tmp/opc_guiclt_msv}

# DB config file
OVDB_CONFIG_FILE=${OVDB_CONFIG_FILE:-${OV_CFG_DIR}/ovdbconf}

#-------------------------------------
# ITO Agent Paths
#-------------------------------------
# /usr/OV/bin/OpC/s700
OPCAGT_BIN_DIR=${OPCAGT_BIN_DIR:-${OPC_OPT_DIR}/bin/OpC}
OPCAGT_LIB_DIR=${OPCAGT_LIB_DIR:-${OPC_OPT_DIR}/lib}
OPCAGT_NLS_DIR=${OPCAGT_NLS_DIR:-${OPCAGT_LIB_DIR}/nls}
OPCAGT_INC_DIR=${OPCAGT_INC_DIR:-${OPC_OPT_DIR}/include}
# /usr/OV/bin/OpC/s700/utils
OPCAGT_UTIL_DIR=${OPCAGT_UTIL_DIR:-${OPCAGT_BIN_DIR}/utils}
# /usr/OV/bin/OpC/s700/install
OPCAGT_INST_DIR=${OPCAGT_INST_DIR:-${OPCAGT_BIN_DIR}/install}

# /var/opt/OV/bin/OpC
OPCAGT_ACTMONCMD_DIR=${OPCAGT_ACTMONCMD_DIR:-${OPC_VAR_DIR}/bin/OpC}

# /var/opt/OV/bin/OpC/monitor
OPCAGT_MON_DIR=${OPCAGT_MON_DIR:-${OPC_VAR_DIR}/bin/OpC/monitor}
# /opt/OV/bin/OpC/actions
OPCAGT_ACT_DIR=${OPCAGT_ACT_DIR:-${OPC_VAR_DIR}/bin/OpC/actions}
# /var/opt/OV/bin/OpC/cmds
OPCAGT_CMD_DIR=${OPCAGT_CMD_DIR:-${OPC_VAR_DIR}/bin/OpC/cmds}

# dynamic paths
OPCAGT_LOG_DIR=${OPCAGT_LOG_DIR:-${OPC_VAR_DIR}/log/OpC}
OPCAGT_CFG_DIR=${OPCAGT_CFG_DIR:-${OPC_VAR_DIR}/conf/OpC}
OPCAGT_TMP_DIR=${OPCAGT_TMP_DIR:-${OPC_VAR_DIR}/tmp/OpC}
OPCAGT_VARBIN_DIR=${OPCAGT_TMP_DIR:-${OPC_VAR_DIR}/bin/OpC}
OPCAGT_TMPBIN_DIR=${OPCAGT_TMPBIN_DIR:-${OPCAGT_TMP_DIR}/bin}
OPCAGT_TMPCFG_DIR=${OPCAGT_TMPCFG_DIR:-${OPCAGT_TMP_DIR}/conf}
OPCAGT_NEWCFG_DIR=${OPCAGT_NEWCFG_DIR:-${OV_NEWCFG_DIR}/OpC}
OPCAGT_OLDCFG_DIR=${OPCAGT_OLDCFG_DIR:-${OV_OLDCFG_DIR}/OpC}

# info files
OPCAGT_NDINFO_F=${OPCAGT_NDINFO_F:-${OPCAGT_CFG_DIR}/nodeinfo}
OPCAGT_INFO_F=${OPCAGT_INFO_F:-${OPCAGT_INST_DIR}/opcinfo}
OPCAGT_NETLS_F=${OPCAGT_NETLS_F:-${OPCAGT_CFG_DIR}/opcnetls}
OPCAGT_MGRCONF_F=${OPCAGT_MGRCONF_F:-${OPCAGT_CFG_DIR}/mgrconf}
OPCAGT_UPD_F=${OPCAGT_UPD_F:-${OPCAGT_TMP_DIR}/update}
OPCAGT_CLIENT_F=${OPCAGT_CLIENT_F:-${OPCAGT_INST_DIR}/cfg.clients}
OPCAGT_MGMTSV_F=${OPCAGT_MGMTSV_F:-${TMP_DIR}/mgmt_sv.dat}
#
# commands
#
OPCMON=${OPCAGT_BIN_DIR}/opcmon
OPCMSG=${OPCAGT_BIN_DIR}/opcmsg

VUE_DIR=/etc/vue
VUE_USR_DIR=/usr/vue
VUE_ETC_DIR=/etc/vue
VUE_VAR_DIR=/var/vue
CDE_USR_DIR=/usr/dt
CDE_ETC_DIR=/etc/dt
CDE_VAR_DIR=/var/dt

#-------------------------------------
# paths
#-------------------------------------
SYSTEM_PATH=${SYSTEM_PATH:-"/usr/xpg4/bin:/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc:/usr/ucb"}
OV_PATH=${OV_BIN_DIR}
OPCSVR_PATH=${OPCSVR_BIN_DIR}:${OPCSVR_AGTINST_DIR}:${OPCSVR_INST_DIR}
OPCAGT_PATH=${OPCAGT_BIN_DIR}:${OPCAGT_INST_DIR}:${OPCAGT_MON_DIR}:${OPCAGT_ACT_DIR}:${OPCAGT_CMD_DIR}

# program name
APPLNAME=ITO
LONG_APPLNAME="HP OpenView Operations for Sun Solaris A.08.30"

# common umask value
umask 022

# location of the oratab file

# shared library suffix
SHLIBSUFFIX=so


#==============================================================================
#
#  Initialize error, warning and note counters for OPC_NODE in
#  OPC_RESULT_FILE by including "zero" entry into OPC_RESULT_FILE
#  (needed when no message is displayed for node).
#
oi_init_result()
{
    echo "$OPC_MNGD_NODE $OPC_NODE 0 0 0" >>$OPC_RESULT_FILE
}


#==============================================================================
#
#  Print ERROR message on stderr and on installation and error logfile.
#  Then ask for error confirmation.
#  If node specific error counting is enabled, write error record.
#
oi_error()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_ERR=$1; shift
    MSG_ERR=$1; shift
    LANG=$OPC_CALL_LANG PAR_ERR="$*"

    LANG=$OPC_CALL_LANG ERROR_TXT=`oi_msg "$CAT_ERR" "$MSG_ERR" "$PAR_ERR"`

    LANG=$OPC_CALL_LANG echo "${OPC_ERROR_KWD}$ERROR_TXT"   #1>&2
    LANG=$OPC_CALL_LANG echo "${OPC_ERROR_KWD}$ERROR_TXT"   >> $OPC_LOGF
    LANG=$OPC_CALL_LANG echo "${OPC_ERROR_KWD}$ERROR_TXT"   >> $OPC_ERR_LOGF

    ELC_SILENT=$OPC_SILENT
    OPC_SILENT=0
    echo                                          #1>&2
    oi_s_echo "          " "opc" 004              #1>&2
    TRASH=`line -t $OPC_TIME_OUT`
    if [ $? -ne 0 ]
    then                                # time out has been occurred
        echo                            # generate new line
        oi_warning "opc" 133 $OPC_TIME_OUT
    fi
    OPC_SILENT=$ELC_SILENT

    if [ $OPC_ENABLE_ERRCNT = 1 ]
    then
        echo "$OPC_MNGD_NODE $OPC_NODE 1 0 0" >>$OPC_RESULT_FILE
    fi
    unset CAT_ERR MSG_ERR ERROR_TXT TRASH PAR_ERR ELC_SILENT

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}

#==============================================================================
#
#  Print ERROR message on stderr and on installation and error logfile,
#  but don't ask for error confirmation; intended for remote script's error
#  messages, generated via oi_rmessage(1m) interface.
#
#  If node specific error counting is enabled, write error record.
#
oi_errmsg()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_ERR=$1; shift
    MSG_ERR=$1; shift
    LANG=$OPC_CALL_LANG PAR_ERR="$*"

    LANG=$OPC_CALL_LANG ERROR_TXT=`oi_msg "$CAT_ERR" "$MSG_ERR" "$PAR_ERR"`

    LANG=$OPC_CALL_LANG echo "${OPC_ERROR_KWD}$ERROR_TXT"   #1>&2
    LANG=$OPC_CALL_LANG echo "${OPC_ERROR_KWD}$ERROR_TXT"   >> $OPC_LOGF
    LANG=$OPC_CALL_LANG echo "${OPC_ERROR_KWD}$ERROR_TXT"   >> $OPC_ERR_LOGF

    if [ $OPC_ENABLE_ERRCNT = 1 ]
    then
        echo "$OPC_MNGD_NODE $OPC_NODE 1 0 0" >>$OPC_RESULT_FILE
    fi
    unset CAT_ERR MSG_ERR ERROR_TXT TRASH PAR_ERR

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}




#==============================================================================
#
#  Print WARNING message on stderr and on logfile
#  independent of OPC_SILENT mode.
#
oi_warning()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_WARN=$1; shift
    MSG_WARN=$1; shift
    LANG=$OPC_CALL_LANG PAR_WARN="$*"

    LC_SILENT=$OPC_SILENT
    OPC_SILENT=0
    oi_s_echo "$OPC_WARNING_KWD" "$CAT_WARN" "$MSG_WARN" "$PAR_WARN"  #1>&2
    OPC_SILENT=$LC_SILENT

    WARNING_TXT=`oi_msg "$CAT_WARN" "$MSG_WARN" "$PAR_WARN"`
    LANG=$OPC_CALL_LANG echo "${OPC_WARNING_KWD}$WARNING_TXT"      >> $OPC_LOGF

    if [ $OPC_ENABLE_ERRCNT = 1 ]
    then
        echo "$OPC_MNGD_NODE $OPC_NODE 0 1 0" >>$OPC_RESULT_FILE
    fi
    unset CAT_WARN MSG_WARN PAR_WARN WARNING_TXT LC_SILENT

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}

#==============================================================================
#



nt NOTE message on stderr and on logfile
#  independent of OPC_SILENT mode.
#
oi_note()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_NOTE=$1; shift
    MSG_NOTE=$1; shift
    LANG=$OPC_CALL_LANG PAR_NOTE="$*"
    NOTE_TXT=`oi_msg "$CAT_NOTE" "$MSG_NOTE" "$PAR_NOTE"`

    NOTE_SILENT=$OPC_SILENT
    OPC_SILENT=0
    oi_s_echo "$OPC_NOTE_KWD" "$CAT_NOTE" "$MSG_NOTE" "$PAR_NOTE"  #1>&2
    OPC_SILENT=$NOTE_SILENT
    LANG=$OPC_CALL_LANG echo "${OPC_NOTE_KWD}$NOTE_TXT"    >> $OPC_LOGF

    if [ $OPC_ENABLE_ERRCNT = 1 ]
    then
        echo "$OPC_MNGD_NODE $OPC_NODE 0 0 1" >>$OPC_RESULT_FILE
    fi
    unset PAR_WARN NOTE_TXT PAR_WARN MSG_WARN NOTE_SILENT

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}

#==============================================================================
#
#  Print progress message on stdout and on logfile
#  depending on OPC_SILENT mode. Blank message qualifier is used.
#  When called without any parameters empty line is produced on log and
#  on screen.
#
oi_verbose()
{

    if [ $# = 0 ]
    then
        echo "          "
        echo "          " >>$OPC_LOGF
        return 0
    fi

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_VER=$1; shift
    MSG_VER=$1; shift
    LANG=$OPC_CALL_LANG PAR_VER="$*"
    oi_s_echo "          " "$CAT_VER" "$MSG_VER" "$PAR_VER"
    LANG=$OPC_CALL_LANG TEXT=`oi_msg "$CAT_VER" "$MSG_VER" "$PAR_VER"`
    LANG=$OPC_CALL_LANG echo "          $TEXT" >> $OPC_LOGF
    unset PAR_VER CAT_VER MSG_VER TEXT

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}



#==============================================================================
#
#  Print progress message on stdout and on logfile without NewLine
#  depending on OPC_SILENT mode. Blank message qualifier is used.
#
oi_verbose_no_nl()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_VER=$1; shift
    MSG_VER=$1; shift
    LANG=$OPC_CALL_LANG PAR_VER="$*"
    oi_s_echo_no_nl "          " "$CAT_VER" "$MSG_VER" "$PAR_VER"
    LANG=$OPC_CALL_LANG TEXT=`oi_msg "$CAT_VER" "$MSG_VER" "$PAR_VER"`
    LANG=$OPC_CALL_LANG echo "          $TEXT \c" >> $OPC_LOGF
    unset PAR_VER CAT_VER MSG_VER TEXT

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}



#==============================================================================
#
#  Print progress message only on logfile.
#
oi_log()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CAT_LOG=$1; shift
    MSG_LOG=$1; shift
    LANG=$OPC_CALL_LANG PAR_LOG="$*"
    LANG=$OPC_CALL_LANG TEXT_L=`oi_msg "$CAT_LOG" "$MSG_LOG" "$PAR_LOG"`
    LANG=$OPC_CALL_LANG echo "          $TEXT_L" >> $OPC_LOGF
    unset PAR_LOG CAT_LOG MSG_LOG TEXT_L

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}


#==============================================================================
#
#  Display contents of file on stderr and write it to logfile.
#
oi_show_file()
{
    FL=$1
    cat  $FL                  #1>&2
    LANG=$OPC_CALL_LANG echo "`cat $FL`"  >>  $OPC_LOGF
    unset FL
    return 0
}

#==============================================================================
#
#  Write contents of file only to logfile, not to stderr
#
oi_log_file()
{
    FL=$1
    LANG=$OPC_CALL_LANG echo "`cat $FL`"  >>  $OPC_LOGF
    unset FL
    return 0
}



#==============================================================================
#
#  Displays message on stdout.
#  First parameter is message severity string.
#  Echoing depends on the OPC_SILENT mode.
#
oi_s_echo()
{
    if [ $OPC_SILENT -eq 0 ]
    then

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    SEVERITY=$1; shift
        CAT_ECHO=$1; shift
        MSG_ECHO=$1; shift
        LANG=$OPC_CALL_LANG PAR_ECHO="$*"
        LANG=$OPC_CALL_LANG TEXT_E=`oi_msg "$CAT_ECHO" "$MSG_ECHO" "$PAR_ECHO"`
        LANG=$OPC_CALL_LANG echo "${SEVERITY}$TEXT_E"
        unset SEVERITY CAT_ECHO MSG_ECHO TEXT_E PAR_ECHO

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    fi
    return 0
}


#==============================================================================
#
#  Displays message on stdout without new line.
#  First parameter is message severity string.
#  Echoing depends on the OPC_SILENT mode.
#  This function is necessary for prompting etc.
#  Note that PARMS must be extracted to allow empty parameters.
#
oi_s_echo_no_nl()
{
    if [ $OPC_SILENT -eq 0 ]
    then

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

        SEVERITY=$1; shift
        CAT_ECHON=$1; shift
        MSG_ECHON=$1; shift
        PAR_ECHON="$*"
        LANG=$OPC_CALL_LANG TEXT_EN=`oi_msg "$CAT_ECHON" "$MSG_ECHON" "$PAR_ECHON"`
        LANG=$OPC_CALL_LANG echo "${SEVERITY}$TEXT_EN \c"
        unset SEVERITY CAT_ECHON MSG_ECHON TEXT_EN PAR_ECHON

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    fi
    return 0
}


#==============================================================================
#
#  Get corresponding message from message catalog and display it on stdout.
#  Message catalog is selected according to the value of the first parameter.
#  If first parameter is -s, then message wrapparound formatting is suppressed.
#
oi_msg()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    NICE_FLAG=n
    if [ "$1" = "-s" ]
    then
        shift
        NICE_FLAG=""
    fi
    CATALOG=LC_MESSAGES/${1}inst.mo; shift

    if [ "x$LC_MESSAGES" != "x" ]
    then
        if [ -f ${OPCSVR_NLS_DIR}/${LC_MESSAGES}/${CATALOG} ]
        then
         CATALOG=${OPCSVR_NLS_DIR}/${LC_MESSAGES}/${CATALOG}
        else
         CATALOG=${OPCSVR_NLS_DIR}/C/${CATALOG}
        fi
    else
        if [ -f ${OPCSVR_NLS_DIR}/${OPC_CALL_LANG}/${CATALOG} ]
        then
          CATALOG=${OPCSVR_NLS_DIR}/${OPC_CALL_LANG}/${CATALOG}
        else
          CATALOG=${OPCSVR_NLS_DIR}/C/${CATALOG}
        fi
    fi

    MSG_MSG=$1; shift
    PAR_MSG="$*"
    LANG=$OPC_CALL_LANG $OPC_CMD_DIR/opc_getmsg "-"${NICE_FLAG}c "$CATALOG" 10 "$MSG_MSG" $PAR_MSG
    if [ $? -ne 0 ]
    then
        echo "          unexpected problem accessing the message catalogue"
        echo "          message set: 10; message number: $MSG_MSG"

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

        return 1
    fi
    unset CATALOG MSG_MSG PAR_MSG

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}


#==============================================================================
#
#  Get corresponding message from message catalog and display it on stdout
#  without new line. Message catalog is selected according to the value
#  of the first parameter.
#
oi_msg_no_nl()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    CATALOG=LC_MESSAGES/${1}inst.mo; shift

    if [ "x$LC_MESSAGES" != "x" ]
    then
        if [ -f ${OPCSVR_NLS_DIR}/${LC_MESSAGES}/${CATALOG} ]
        then
         CATALOG=${OPCSVR_NLS_DIR}/${LC_MESSAGES}/${CATALOG}
        else
         CATALOG=${OPCSVR_NLS_DIR}/C/${CATALOG}
        fi
    else
        if [ -f ${OPCSVR_NLS_DIR}/${OPC_CALL_LANG}/${CATALOG} ]
        then
          CATALOG=${OPCSVR_NLS_DIR}/${OPC_CALL_LANG}/${CATALOG}
        else
          CATALOG=${OPCSVR_NLS_DIR}/C/${CATALOG}
        fi
    fi

    MSG_MSG=$1; shift
    PAR_MSG="$*"
    MSG=`LANG=$OPC_CALL_LANG $OPC_CMD_DIR/opc_getmsg \
              -nc "$CATALOG" 10 "$MSG_MSG" $PAR_MSG`
    if [ $? -ne 0 ]
    then
        echo "          unexpected problem accessing the message catalogue"
        echo "          message set: 10; message number: $MSG_MSG"

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

        return 1
    fi
    LANG=${OPC_CALL_LANG} echo "${MSG}\c"
    unset CATALOG MSG_MSG MSG PAR_MSG

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}



#==============================================================================
#
#  DESCRIPTION
#    Prompt and ask for answer.
#    If timeout on input has occurred, display warning and inform
#    operator that execution has continued.
#    Return entered string or string "defauuult" if timeout occurred.
#    When empty sting is entered, it is converted to "defauuult".
#
#  PARAMETERS
#    OPC_OS_NICKNAME or "opc"  .. catalog selection
#    warn_msgn             .. message number of warning in case of time out
#    wpar1                 .. first parameter to warning message: use "" for em.
#    wpar2                 .. second parameter for warning message
#    prompt_msgn           .. message number of prompt line
#    prompt_parameters     .. the rest of line are prompt message parameters
#
oi_prompt_and_ask()
{

#   BEGIN of function: disable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        set +x
        DEBUG_CNT=`expr $DEBUG_CNT + 1`
    fi

    PR_CATALOG=$1; shift
    PRW_MSG=$1; shift
    PRW_PAR1="$1"; shift
    PRW_PAR2="$1"; shift
    PROMPT_MSG=$1; shift
    PR_PARMSG="$*"

    PLC_SILENT=$OPC_SILENT
    OPC_SILENT=0
    oi_msg_no_nl $PR_CATALOG $PROMPT_MSG $PR_PARMSG
    OPC_ANSWER=`line -t $OPC_TIME_OUT`
    if [ $? -ne 0 ]
    then
        # time out has been occurred
        echo  # generate new line
        oi_warning "opc" 133 $OPC_TIME_OUT
        oi_warning $PR_CATALOG $PRW_MSG $PRW_PAR1 $PRW_PAR2
        OPC_ANSWER=$OPC_OIANSWER_DEF
    else
        if [ "$OPC_ANSWER" = "" ]
        then
            OPC_ANSWER=$OPC_OIANSWER_DEF
        fi
    fi
    OPC_SILENT=$PLC_SILENT
    unset PLC_SILENT

#   END   of function: enable debugging if OPC_DEBUG_ALL not set
    if [ "${OPC_ADEBUG}" = "OPCAYES" ]
    then
        if [ ${DEBUG_CNT} -gt 0 ]
        then
            DEBUG_CNT=`expr $DEBUG_CNT - 1`
        fi
        if [ ${DEBUG_CNT} -le 1 ]
        then
            set -x
        fi
    fi

    return 0
}



#==============================================================================
#
#  DESCRIPTION
#    Save/Restore OPC_NODE and its corresponding environment variables to
#    OPC_NODE's cluster server ones.
#    Use this function to simplify environment switching between OPC_NODE and
#    OPC_NODE's cluster server.
#
#  PARAMETERS
#    mode .. mode of operation: SAVE to save ,RESTORE to restore OPC_NODE's
#            variables.
#
#  ENVIRONMENT
#    OPC_NODE, OPC_IP_ADDRESS, OPC_PASSWD_REQ, OPC_PASSWD
#             .. OPC_NODE variables
#    OPC_CL_NODE, OPC_CL_IP_ADDRESS, OPC_CL_PASSWD_REQ, OPC_CL_PASSWD
#             .. OPC_NODE's cluster server variables
#    OPC_CL_M .. variable to prevent successive RESTORE operations
#
#  EXIT CODE
#      0 .. task successfully done
#      1 .. usage error
#

opcuxenvsave()
{
    if [ $# -ne 1 ]
    then
        #   usage error
        #
        return 1
    fi

    MODE=$1

    case ${MODE} in
        SAVE)
            #   save OPC_NODE variables
            #   switch values of OPC_NODE and OPC_NODE's cluster server
            #   save error counters
            OPC_CL_M=1
        ;;
        RESTORE)
            #   restore OPC_NODE variables
            #   switch values of OPC_NODE and OPC_NODE's cluster server
            #   write current error counters and reestablish old ones
            if [ "${OPC_CL_M}" = "1" ]
            then
                #   restore operation is possible
                #
                OPC_CL_M=0
            else
                #   restore operation is not possible
                #
                unset MODE
                return 1
            fi
        ;;
        *)
            #   usage error
            #
            unset MODE
            return 1
        ;;
    esac

    TSV_NODE=${OPC_NODE}
    TSV_IP_ADDRESS=${OPC_IP_ADDRESS}
    TSV_PASSWD_REQ=${OPC_PASSWD_REQ}
    TSV_PASSWD="${OPC_PASSWD}"
    #TSV_ACT_ONLY=${ACTIVATE_ONLY}

    OPC_NODE=${OPC_CL_NODE}
    OPC_IP_ADDRESS=${OPC_CL_IP_ADDRESS}
    OPC_PASSWD_REQ=${OPC_CL_PASSWD_REQ}
    OPC_PASSWD="${OPC_CL_PASSWD}"
    #ACTIVATE_ONLY=${OPC_ACT_ONLY}

    OPC_CL_NODE=${TSV_NODE}
    OPC_CL_IP_ADDRESS=${TSV_IP_ADDRESS}
    OPC_CL_PASSWD_REQ=${TSV_PASSWD_REQ}
    OPC_CL_PASSWD="${TSV_PASSWD}"
    #CL_ACT_ONLY=${TSV_ACT_ONLY}

    export OPC_NODE OPC_IP_ADDRESS OPC_PASSWD_REQ OPC_PASSWD
    export OPC_CS_NODE OPC_CL_IP_ADDRESS OPC_CS_PASSWD_REQ OPC_CS_PASSWD
    unset MODE TSV_NODE TSV_IP_ADDRESS TSV_PASSWD_REQ TSV_PASSWD  TSV_ACT_ONLY
    #export ACTIVATE_ONLY CL_ACT_ONLY

    return 0

}

#===============================================================================
#
#  Produce password_file(5) line for actual $OPC_NODE.
#  Used by opcping and opcmpeping scripts.
#
produce_password()
{
    if [ "${OPC_STATUS}" = "NOTREADY" -o "${OPC_STATUS}" = "INSTALLED" ]
    then
        #   skip this OPC_NODE
        #
        # skipping warning issued in opc_inst.sh
        echo "${OPC_NODE} ${OPC_STATUS}" > $OPC_OUTPUT_FILE
    else
        #   produce real password_file(5) line for this node
        #

        if [ -z "${OPC_PASSWD}" ]
        then
            #   zero length password reset to default value
            #
            OPC_PASSWD=OPC_UNKNOWN_PASSWORD
        fi

        PASSWORD_LINE="${OPC_NODE}"
        PASSWORD_LINE="${PASSWORD_LINE} ${OPC_STATUS}"
        PASSWORD_LINE="${PASSWORD_LINE} ${OPC_PASSWD_REQ}"
        PASSWORD_LINE="${PASSWORD_LINE} ${OPC_PASSWD}"
        PASSWORD_LINE="${PASSWORD_LINE} ${KERBEROS_BYPASS}"
        PASSWORD_LINE="${PASSWORD_LINE} ${ACTIVATE_ONLY}"
        if [ ! -z "${WNT_ACCOUNT_PASSWD}" ]
        then
          PASSWORD_LINE="${PASSWORD_LINE} `${OPCSVR_INST_DIR}/opcpwcrpt \"${WNT_ACCOUNT_PASSWD}\"`"
        fi

        echo "${PASSWORD_LINE}" > $OPC_OUTPUT_FILE
        unset PASSWORD_LINE
    fi
}



#==============================================================================
#
#  DESCRIPTION
#   check, if OS version of Managed Node is supported by ITO software
#   OPC_VERSION version.
#
#  ENVIRONMENT
#    OPC_VERSION .. is possible to be changed, if actual OPC_VERSION version
#                   ITO software doesn't support OS version of Managed Node
#
#  EXIT_CODE
#    0 .. OK
#    1 .. ERROR
#
chk_os_support()
{

    REQ_FILE=${OPC_INST_DIR}/${OPC_PLATFORM}/require.dat
    ACT_OS_VER=$1                   # OS version of Managed Node
    
    #   check require.dat file for getting all supported versions
    #
    CHK_OS_VER=""
    for SUP_OS_VER in `awk "/^${OPC_VERSION}/ {for (x=3; x<=NF; x++) print\\$(x)}" \
                      ${REQ_FILE}`
    do
        if [ "`echo ${ACT_OS_VER} | awk /${SUP_OS_VER}/`" != "" ]
        then
            CHK_OS_VER=${ACT_OS_VER}
            break
        fi
    done

    if [ -n "${CHK_OS_VER}" ]
    then
        #   OS version of Managed Node is supported by OPC_VERSION
        #   version ITO software
        #
        unset ACT_OS_VER CHK_OS_VER
        return 0
    fi

    ##  if OS version of Managed Node isn't supported by this OPC_VERSION ,
    #   find lates one. This operation relay on fact, that callout scripts
    #   for new OPC_VERSION ITO software are equivalent to callout scripts of
    #   current version ITO software.
    #
    if [ "${OPC_SUBPRODUCT}" = "${OPC_PRODUCT}" ]
    then
        CUR_SUBPRODUCT="OVO"
    else
        CUR_SUBPRODUCT="${OPC_SUBPRODUCT}"
    fi

    oi_warning "opc" 036 ${OPC_VERSION} ${OPC_PLATFORM} \
                         ${ACT_OS_VER} ${OPC_NODE} ${CUR_SUBPRODUCT}

    # find the lates installed ITO Agent software, which support ACT_OS_VER
    #
    CHK_OPC_VER=`awk '{if ($1 != "#") \
                        {for (x=3; x<=NF; x++) \
                          {if (index(vers,$(x)) != 0) \
                            {print $1}
                          } \
                        } \
                      }' \
                  vers=${ACT_OS_VER} ${REQ_FILE} |
                  sort | awk 'BEGIN {L=""} {L=$1} END{print L}'`

    if [ -z "${CHK_OPC_VER}" ]
    then
        #   no ITO version found supporting the OS release
        #
        oi_error "opc" 155 ${OPC_PLATFORM} ${ACT_OS_VER} ${CUR_SUBPRODUCT}
        unset ACT_OS_VER CHK_OS_VER CHK_OPC_VER
        return 1
    else
        #   ask if ITO software  maintenance using this version should be
        #   continued
        oi_warning "opc" 156 ${CHK_OPC_VER} ${OPC_VERSION} \
                             ${OPC_PLATFORM} ${ACT_OS_VER} ${CUR_SUBPRODUCT}
        oi_prompt_and_ask "opc" 143 "${OPC_NODE}" "" \
                                157 ${OPC_NODE} ${CHK_OPC_VER} ${CUR_SUBPRODUCT}
        if [ "${OPC_ANSWER}" = "${OPC_OIANSWER_DEF}" ]
        then
            OPC_ANSWER=${OPC_YES_LIT}
        fi
        case "${OPC_ANSWER}" in
            [${OPC_YES_LIT}]*)
            #   continue with new OPC_VERSION
            #   
                OPC_VERSION=${CHK_OPC_VER}; export OPC_VERSION
                EXIT_VAL=0
            ;;
            *)
                EXIT_VAL=1
            ;;
        esac
    fi

    unset ACT_OS_VER CHK_OS_VER CHK_OPC_VER
    if [ ${EXIT_VAL} -eq 0 ]
    then
        unset EXIT_VAL
        return 0
    else
        unset EXIT_VAL
        return 1
    fi

}

#==============================================================================
#
#  DESCRIPTION
#    Set environment variables for N-th node
#
#  ENVIRONMENT
#    OPC_VERSION    Current version
#
#  EXIT CODE
#    0 .. Ok
#    1 .. Out of scope
#

oi_node_entry()
{
    ND_CNT=$1
    if [ $ND_CNT -gt $NODES -o $ND_CNT -le 0 ]
    then
        return 1
    fi

    eval `awk 'BEGIN { i = 1 }
    {
        if ( (NF > 0) && ($1 != "#" )) {
            if ( i == COUNT ) {
                printf "OPC_NODE=%s\n",            $1
                printf "OPC_MNGD_NODE=%s\n",       $1
                printf "OPC_IP_ADDRESS=%s\n",      $2
                printf "OPC_PLATFORM=%s\n",        $3
                printf "OPC_VERSION=%s\n",         $6
                printf "OPC_NODE_LOGD=%s\n",       $7
                printf "OPC_FORCE_UPD=%s\n",       $8
                printf "OPC_DEPOT_NODE=%s\n",      $9
                printf "OPC_ACCESS_METHOD=%s\n",   $10
                printf "OPC_PACKAGE_NAME=%s\n",    $11
                printf "OPC_DEPOT_NAME=%s\n",      $12
                printf "OPC_COMPR_PKG_TRANS=%s\n", $13
                printf "OPC_COMPR_PKG=%s\n",       $14
                printf "OPC_INST_METHOD=%s\n",     $15
                printf "OPC_INST_USER=%s\n",       $16
            }
            i++
        }
    }' COUNT=$ND_CNT <$INFO_FILE`

    if [ $OPC_VERSION = "LATEST" ]
    then
        OPC_VERSION=`awk '{ if( $1 == PLATFORM ) print $2 }' \
        PLATFORM=$OPC_PLATFORM <$VERSIONS_CACHE_FILE`
    fi

    PASSWORD_LINE=`awk '{
        if ( $1 == NODE_KEY ) print $0
    }' NODE_KEY=$OPC_NODE <$PASSWORD_FILE`
    if [ `echo "$PASSWORD_LINE" | wc -w` -lt 2 ]
    then
        echo "$OPC_NODE NOTREADY" >> $PASSWORD_LINE
    fi
    eval `echo "$PASSWORD_LINE" | awk '{
        printf "OPC_STATUS=%s\n", $2
    }'`

    return 0
}





