#!/bin/sh
# OPC_WHAT_STRING="@(#)HP OpenView Operations 09.01.180 (08/20/09)"

################################################################################
#
# File:         opcvmsverchk
# Description:  Generic unix family VERSION_CHECK script
# Language:     Bourne Shell
# Package:      HP OpenView IT/Operations
#
# (c) Copyright 1993 - 2009 Hewlett-Packard Development Company, L.P. 
#
################################################################################
#

#  DESCRIPTION
#    Generic unix family VERSION_CHECK script: server part.
#    This script remotely executes platform specific ITO rverchk script.
#    Remote script rverchk is transferred to Managed Node and executed there.
#
#  PARAMETERS
#    output_file .. name od result file
#
#  EXIT CODE
#    0  .. success
#    1  .. installation no possible
#    2  .. ITO software already installed, but node belongs to different
#          Management Server. Name of it is placed into output_file
#    3  .. same version of ITO software already installed
#    4  .. different version of ITO software already installed
#

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

# localization
LANG_C=C
LANG_SJIS=ja_JP.SJIS
LANG_EUC=ja_JP.eucJP

#
# nslookup function - nslookup does not use LDAP
#
nslookup()
{
    _name=$1
    _result=""
    if [ -x ${OPCSVR_BIN_DIR}/utils/opcsvnsl ]
    then
        _result=`${OPCSVR_BIN_DIR}/utils/opcsvnsl ${_name} 2>&1`
    else
        if [ -x ${OPCAGT_INST_DIR}/opcnsl ]
        then
            _result=`${OPCAGT_INST_DIR}/opcnsl ${_name} 2>&1`
        else
            if [ -x /tmp/opcsvnsl ]
            then
                _result=`/tmp/opcsvnsl ${_name} 2>&1`
            else
                /usr/bin/nslookup ${_name}
            fi
       fi
   fi
   if [ ! -z "${_result}" ]
   then
        echo ${_result} | grep 'Not found' 1>/dev/null 2>&1
        if [ $? -eq 0 ]
        then
            echo
            echo "*** No address (A) records available for ${_name}"
        else
            _rname=`echo ${_result} | cut -f1 -d:`
            _raddr=`echo ${_result} | cut -f2 -d:`
            echo
            echo "Name:    ${_rname}"
            echo "Address:  ${_raddr}"
            unset _rname
            unset _raddr
       fi
   fi
   unset _name
   unset _result
   return 0
} # END nslookup()

GREP=/bin/grep
TR=/usr/bin/tr

# 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=09.01.180

# 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}}
OV_DEFAULTS_PATH=${OV_VAR_DIR}/tmp
# /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}

#-------------------------------------
# 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}/lib64}
# /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}

# 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}/lib64}
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:-"/bin:/usr/bin:/sbin:/usr/sbin:/etc"}
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 Linux 09.01.180"

# common umask value
umask 022

# location of the oratab file
ORATAB_LOC=/etc/oratab

# shared library suffix
SHLIBSUFFIX=so

#-------------------------------------
# Module name definition
#-------------------------------------

# define module name
    MODULE_NAME=VERSION_CHECK

  ECHOC="echo -e"

# special for well formatted output
#-----------------------------------------------------------------------
# set the COLUMN variable for the window size 
# 
#-----------------------------------------------------------------------
window_size()
 {
   COLUMN=`stty size | cut -d ' ' -f 2`
 }

#-----------------------------------------------------------------------
# Write notes, warnings or errors to stderr 
# The linebreak effects in dependency of the window size between 
# two words. The "COLUMN" variable must set bevor the function is 
# called. To set the "COLUMN" variable use the "window_size" function.
#
# There are 5 kinds of messages possible: NOTE (nt), WARNING (wrn), 
#                                         ERROR (err), QUESTION (qu),
#                                         and without name (log) 
# Attention: Dont write an "?" after an question, because the function
#            makes this to avoid problems with "?".
#
# Example: msg_out nt "This is an example for the msg_out function, \
#		       showing the output of this function."
# Output: NOTE:    This is an example fot the msg_out function, showing
#                  the output of this function.
#-----------------------------------------------------------------------
msg_out()
{
  ${ECHOC} "$2" | awk '
{
  # set the message name
  if (mode == "nt") 
    out_text="NOTE:    "
  else if (mode=="wrn")
    out_text="WARNING: "
  else if (mode=="err")
    out_text="ERROR:   "
  else if (mode=="qu")
    out_text="QUESTION:"
  else if (mode=="log")
    out_text="         "
  else exit 1

  width-=3

  # if the messages fits in one row
  if( (length($0)+length(out_text)) <= width ) {
    # if the message is an question, write no "\n" at the end
    if ( mode=="qu")
      printf "%s %s ? ", out_text, $0  | "cat 1>&2"
    # the message is no question, write an "\n" at the end
    else
       printf "%s %s\n", out_text, $0 | "cat 1>&2"
  }

  # if severals rows are needed
  else {
    i=1
    x=1
    while (i <= NF) {
      if ( (length(out_text)+length($i)) <= width){
        out_text=out_text " " $i
      }  
      else {
        printf "%s\n          ", out_text | "cat 1>&2"
	out_text = $i
	if (x==1)
	  width-=10
        x++
      }
      i++
    }
    # write the last line
    if (out_text != "") {
      # if the message is an question, write no "\n" 
      if ( mode == "qu")
        printf "%s ? ", out_text | "cat 1>&2"
      else 
        printf "%s\n", out_text | "cat 1>&2"
    }
  }
}' mode=$1 width=$COLUMN 
}

#VMS Changes Starts
. "$OPC_AGTINST_DIR"/opcvmsproc
. "$OPC_AGTINST_DIR"/opcvmsprocs
#VMS Changes Ends

#===============================================================================
#
#   MAIN script body
#

# display start module
if [ "${OPC_ADEBUG}" = "OPCAYES" ]
then
    set +x
    DEBUG_CNT=`expr $DEBUG_CNT + 1`
fi
if [ "${OPC_TRACE}" = "YES" ]
then
    CALLOUT_NAME=$0
    CALLOUT_PARAMS="$*"
    #oi_trace opc 588 "${MODULE_NAME}" ${CALLOUT_NAME} "\"${CALLOUT_PARAMS}\""
    echo "TRACE:    ${TRACE_HEADER}" | \
    sed -e "s=MODULxxxxxxx=${MODULE_NAME}=" \
        -e "s=SCRIPTxxxxxx=${CALLOUT_NAME}=" \
    >> ${OPC_TRACE_FILE}
fi
if [ "${OPC_DEBUG}" = "YES" ]
then
    # enable tracing in all functions
    eval `typeset -f | awk '/^function/ { printf "typeset -tf %s\n", $2 }'`
fi
if [ "${OPC_ADEBUG}" = "OPCAYES" ]
then
    if [ ${DEBUG_CNT} -gt 0 ]
    then
	DEBUG_CNT=`expr $DEBUG_CNT - 1`
    fi
    if [ ${DEBUG_CNT} -gt 0 ]
    then
	set -x
    fi
fi

#   set global environment variables
#
TMP_FILE=${OPC_TOPC}/opc-$$.tmp
if [ -f ${TMP_FILE} ]
then 
    #	remove temporary file
    #
    rm -f ${TMP_FILE}
    if [ $? -ne 0 ]
    then
	#	can't write to TMP_FILE
	#
    	oi_error "opc" 526 "${TMP_FILE}"
	EXIT 1
    fi
fi

#   input parameters
#
if [ $# -ne 1 ]
then
    #	usage error
    #
    oi_error "opc" 511 "opcuxverchk"
    EXIT 1
fi
OPC_OUTPUT_FILE=$1

touch ${OPC_OUTPUT_FILE}
if [ $? -ne 0 ]
then
    #	can't write to OPC_OUTPUT_FILE
    #
    oi_error "opc" 526 "${OPC_OUTPUT_FILE}"
    EXIT 1
fi

#   remote execute rverchk script
#

if [ -z "${OPC_RCPEXEC_SCRIPT}" ]
then
    #	remote copy and execute callout script is unknown
    #	exit with an error
    #
    oi_error "opc" 522 "RCPEXEC_SCRIPT" "${OPC_PLATFORM}"
    EXIT 1
fi

#   remote execute rverchk script
#
# beside the ITO version also connection to server is checked
#
if opcux_localhost "${OPC_NODE}"
then
    # for manangemt server such test is not required
    $OPC_RCPEXEC_SCRIPT -r ${TMP_FILE} \
        -d ${OPC_TMP_DIR} \
        $OPC_INST_DIR/$OPC_PLATFORM/$OPC_VERSION/$OPC_PACKAGE_TYPE/install/opcrverchk \
        $OPC_METHOD $OPC_PLATFORM $OPC_MGMT_SV ${OPC_TMP_DIR} LOCAL
else
    # copy opcnsl program to remote node first
    if [ -f $OPC_INST_DIR/$OPC_PLATFORM/$OPC_VERSION/$OPC_PACKAGE_TYPE/install/opcnsl ]
    then
	$OPC_RCOPY_SCRIPT \
	$OPC_INST_DIR/$OPC_PLATFORM/$OPC_VERSION/$OPC_PACKAGE_TYPE/install/opcnsl \
	${OPC_TMP_DIR}/opcnsl
	if [ $? -ne 0 ]
	then
	    oi_error "opc" 107 ${OPC_NODE} opcnsl ${OPC_RCOPY_SCRIPT}
	    EXIT 1
	fi
     fi

#VMS Changes Starts
     OPC_RBTTXE=`$OPC_AGTINST_DIR/opccrpt -x qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm -d "$OPC_PASSWD"`
     # quote it in a second step because sed needs a newline at the end
     OPC_RBTTXE=`echo ${OPC_RBTTXE} | sed 's/ /\\\\ /g' | sed 's/"/\\\\"/g'`

     #FTP_CMD1="cd ${OPC_TMP_DIR}"
     FTP_CMD2="put $OPC_INST_DIR/$OPC_PLATFORM/$OPC_VERSION/$OPC_PACKAGE_TYPE/install/opcvmsverchk.com opcvmsverchk.com"
     FTP_CMD1="ascii"
     opcvmsftp "$FTP_CMD1" "$FTP_CMD2"
     if [ $? -ne 1 ]
     then
        #   file couldn't be transferred to the managed node
        #
        oi_verbose opc 377
        echo
        EXIT 1
     fi

     $OPC_CMD_DIR/opc_rexec $OPC_NODE $OPC_INST_USER ${OPC_RBTTXE} "@SYS\$LOGIN:opcvmsverchk.com $OPC_MGMT_SV" > ${TMP_FILE}
     cat ${TMP_FILE}
     $OPC_CMD_DIR/opc_rexec $OPC_NODE $OPC_INST_USER ${OPC_RBTTXE} "del SYS\$LOGIN:opcvmsverchk.com;*"    

#     $OPC_RCPEXEC_SCRIPT -r ${TMP_FILE} \
#         -d ${OPC_TMP_DIR} \
#         $OPC_INST_DIR/$OPC_PLATFORM/$OPC_VERSION/$OPC_PACKAGE_TYPE/install/opcrverchk \
#         $OPC_METHOD $OPC_PLATFORM $OPC_MGMT_SV ${OPC_TMP_DIR} REMOTE \
#	 ${OPC_MGMT_IP_ADDR}
#VMS Changes Ends
fi
EXIT_VAL=$?

# This is BBC Agent installation.
if [ "${OPC_PACKAGE_TYPE}" = "RPC_BBC" -a "${OPC_METHOD}" = "INSTALL" ]
then
  case ${EXIT_VAL} in
    129)
      # HTTPS based agent detected and
      # it belongs to another managemet server
      oi_error "opc" 851
      ;;
    126)
      # older agent detected
      # advise user to remove agent manually and
      # restart installation
      oi_error "opc" 738
      # abort maintainance
      EXIT 1
      ;;
    123)
      # A.07.XX agent detected
      # ask user to confirm removal of agent
      oi_prompt_and_ask "opc" 240 "${OPC_MNGD_NODE}" "" \
                              730 ""
      if [ "${OPC_ANSWER}" = "${OPC_OIANSWER_DEF}" ]
      then 
        OPC_ANSWER=""
      fi
      case "${OPC_ANSWER}" in
	[${OPC_YES_LIT}]*)
          # removal confirmed
          # proceed as usual
	  EXIT 0
          ;;
        *)
          # if user does not confirm removal,
          # abort maintainance
          oi_error "opc" 745
          EXIT 1
	  ;;
      esac 
      ;;
    0)
      # no agent detected
      # proceed as usual
      ;;
  esac
fi

#   take results form temporary file
if [ -f ${TMP_FILE} ]
then
    #	The name of actual management server is stored in first line,
    #	version of ITO software is stored in second one,
    #	Managed Nodes using this copy of software in the third one,
    #	and IP addresses of Management Server known on Managed Node 
    #   in last one.
    #
    eval `awk  'NR == 1	{ printf "ACT_MGMT_SERV=\"%s\"\n", $0 }
		NR == 2	{ printf "ACT_OPC_VERS=\"%s\"\n", $0 }
		NR == 3	{ printf "ACT_CFG_SYS=\"%s\"\n", $0 }
		NR == 4	{ printf "ACT_RES_IP=\"%s\"\n", $0 }
		NR == 5 { printf "ACT_IS_ITOSE=\"%s\"\n", $0 }' \
	    ${TMP_FILE}`

    #   pass results to calling script
    echo "${ACT_MGMT_SERV}" > ${OPC_OUTPUT_FILE}
    echo "${ACT_OPC_VERS}" >> ${OPC_OUTPUT_FILE}
    echo "${ACT_RES_IP}" >> ${OPC_OUTPUT_FILE}
    echo "${ACT_IS_ITOSE}" >> ${OPC_OUTPUT_FILE}
    #	remove temporary file
    #
    rm -f ${TMP_FILE}
fi

#   evaluate the result and OPC_METHOD
#
if [ "${OPC_METHOD}" = "INSTALL" ]
then
    case $EXIT_VAL in
    	0)
	    #   everything is ok for further installation
	    #
	    EXIT 0
	    ;;
	127)
	    #	programming error
	    #
	    EXIT 1
	    ;;
    	126)
	    #	installation not possible
	    #
	    EXIT 1
	    ;;
	125)
            #   first it is checked if itose is installed on the node
            #
            #
            if [ "${ACT_IS_ITOSE}" = "ITOSE_INSTALLED" ]
            then
	      if [ "$OPC_PLATFORM" != "hp/s800/hp-ux10" -a \
	           "$OPC_PLATFORM" != "hp/s700/hp-ux10" ]
	      then 
                # itose is installed on the node
                #
                oi_error "opc" 718 "${ACT_OPC_VERS}" "${OPC_MNGD_NODE}" "${OPC_VERSION}"
                EXIT 1
              fi
            fi

	    #	ITO software already installed on Managed Node
	    #	determinate Management Server name and ITO software version
	    #
            #   
	    opcux_localhost ${ACT_MGMT_SERV}
	    if [ $? -eq 1 ] 
	    then 
		if [ "${ACT_MGMT_SERV}" != "unknown" ]
		then
			#   checking for unknown server is added to enable automatic
			#   activation of preinstalled and OPCSE agents
			#   bug fix DDTS NSMbb19192
			#
	    		#   actual Management Server does not equal local host
			#
			EXIT 2
		fi
	    fi

	    #	before ITO version is checked, determinate how many
	    #	Managed Nodes use this copy of software
	    #
            SHT_NODE=`echo ${OPC_MNGD_NODE} | sed -e 's/\..*//g'`
	    if [ `echo ${ACT_CFG_SYS} |sed -e "s/${SHT_NODE}//" |wc -w` -ne 0 ]
	    then
		#   more than just ${OPC_NODE} use this copy of ITO software
		#   ask user to confirm installation
		#
		oi_warning "opc" 222 ${OPC_MNGD_NODE}
		oi_prompt_and_ask "opc" 240 "${OPC_MNGD_NODE}" "" \
					223 ${OPC_MNGD_NODE}
		if [ "${OPC_ANSWER}" = "${OPC_OIANSWER_DEF}" ]
		then
		    OPC_ANSWER=""
		fi
		case "${OPC_ANSWER}" in
		    [${OPC_YES_LIT}]*)
		    #	continue with operations
		    #
		    ;;
		    *)
			oi_error "opc" 647
			EXIT 1
		    ;;
		esac
		
	    fi
            unset SHT_NODE
	    if [ "${ACT_OPC_VERS}" = "${REAL_OPC_VERSION}" ] 
	    then
		#   same version of ITO software installed on node
		#
		EXIT 3
	    fi
	    EXIT 4
	    ;;
	124)
	    #	ITO software for another architecture installed on
	    #	mixed arch. cluster server system
	    #
	    
	    opcux_localhost ${ACT_MGMT_SERV}
	    if [ $? -eq 1 ] 
	    then 
		#   actual Management Server does not equal local host
		#
		EXIT 2
	    fi
	    unset ACT_MGMT_SERV
	    
	    EXIT 0
	    ;;
    esac
else
    case $EXIT_VAL in
    	0)
	    #   everything is ok for further installation
	    #
	    EXIT 1
	    ;;
	127)
	    #	programming error
	    #
	    EXIT 1
	    ;;
    	126)
	    #	installation not possible
	    #
	    EXIT 1
	    ;;
	125)
	    #	ITO software already installed on Managed Node
	    #	determinate Management Server name and ITO software version
	    #
	    opcux_localhost ${ACT_MGMT_SERV}
	    if [ $? -eq 1 ] 
	    then 
		#   actual Management Server does not equal local host
		#
		EXIT 2
	    fi
	    if [ "${ACT_OPC_VERS}" = "${REAL_OPC_VERSION}" ] 
	    then
		#   same version of ITO software installed on node
		#
		EXIT 3
	    fi
	    EXIT 4
	    ;;
	124)
	    #	ITO software for another architecture installed on
	    #	mixed arch. cluster server system
	    #
	    EXIT 1
	    ;;
    esac
fi

EXIT 1

################################################################################
# end of opcvmsverchk
################################################################################
