#!/bin/bash 
#set -nv
#
# Post Installation Cluster Script for:
#   webes_install_update script for 4.4.0
#
# FUNCTION: post installation configuration script
#
# DESCRIPTION: Installation script for Web-Based Enterprise Service loads 
#              the various components as installable files under the directory 
#              /opt/hp/svctools/kits, presents the user with the list 
#              of optional products then if they choose to install one or more 
#              of these products it installs the mandatory and the optional kits.
#
# USAGE:  executed by user for post install configuration
#
# Copyright 1999 Compaq Computer Corporation.  COMPAQ, the Compaq logo and the
# Digital logo are registered in the U.S. Patent and Trademark Office.  Pro-
# prietary service tool software. Valid license from Compaq or authorized
# sublicensor required for possession, use or copying. Consistent with FAR
# 12.211 and 12.212, Commercial Computer Software, Computer Software Documenta-
# tion, and Technical Data for Commercial Items are licensed to the U.S. Government
# under vendor's standard commercial license.
#
# Compaq service tool software, including associated documentation, is the property
# of and contains confidential technology of Compaq Computer Corporation.  Service
# customer is hereby licensed to use the software only for activities directly relating
# to the delivery of, and only during the term of, the applicable services delivered
# by Compaq or its authorized service provider.  Customer may not modify or reverse
# engineer, remove or transfer the software or make the software or any resultant
# diagnosis or system management data available to other parties without Compaq's or
# its authorized service provider's consent.  Upon termination of the services customer
# will, at Compaq's or its service provider's option, destroy or return the software and
# associated documentation in its possession.
#
# Compaq Web-Based Enterprise Service Suite X4.3.2 for RHL 7.3, 8.0
#
###############################################################################
#
# This program configures WEBES, and installs and configures CA, CCAT.
#
# Configuration on a cluster will almost always be node specific, i.e., even 
# when executed the first time there MAY be registry files recovered from a
# previous deinstallation.
#
# All configuration changes are made in a temporary copy of the registry, then
# the user is asked to name the cluster nodes that the changes should be applied
# to. The default is all nodes.
#
# The new registry data is propagated to the selected node(s) by first copying
# the registry files to the local node, calling sed_registry_file to make the
# updates, then copying the registry back to the owning node.
#
###############################################################################
# Variables

#SUBSETNAME=`basename $0`
#SUBSETNAME=`expr "$SUBSETNAME" : `^\(.*\)\.spec``


# Variables
PREFIX=X;export PREFIX
#VERSION=500; export VERSION
#WEBESVER=${VERSION};export WEBESVER
WEBESVER=500;export WEBESVER
WEBESDOTVER=5.0.0;export WEBESDOTVER
WEBESBUILDLEVEL=;export WEBESBUILDLEVEL
WCCVER=500;export WCCVER
WCCDOTVER=5.0.0;export WCCDOTVER
KNOWN_WEBESVER="${PREFIX}${WEBESDOTVER}";export KNOWN_WEBESVER
CADOTVER=5.0.0;export CADOTVE
CAVER=500;export CAVER
CCATDOTVER=5.3.0;export CCATDOTVER
CCATVER=530;export CCATVER
WCCPROXYDOTVER=2.0.0;export WCCPROXYDOTVER
WEBESRPM=5.0-0;export WEBESRPM
WEBESSEARPM=5.0-0; export WEBESSEARPM
WEBESCCATRPM=5.3-0; export WEBESCCATRPM
WCCPROXYRPM=2.0-0;export WCCPROXYRPM

newline='
'
export newline

OSBUILD=`/bin/uname -v 2> /dev/null`; export OSBUILD
 
#SUBSETNAME=`basename $0`
#SUBSETNAME=`expr "$SUBSETNAME" : '^\(.*\)\.spec'`

# Set this to null for the ca_, ccat_ and wcc_install_xxx.sh scripts.
INSTDIR=""; export INSTDIR

SVCTOOLS_HOME=/usr/opt/hp/svctools; export SVCTOOLS_HOME
REGISTRY_HOME=$SVCTOOLS_HOME/specific/desta/config; export REGISTRY_HOME

DESTA_CLI=$INSTDIR/usr/sbin/desta; export DESTA_CLI
CA_CLI=$INSTDIR/usr/sbin/wsea; export CA_CLI
CCAT_CLI=$INSTDIR/usr/sbin/wccat; export CCAT_CLI

# To add more supported versions of DSNLink, edit the following lists
# and update the subroutine, setup_ACHS_notification().

MIN_SUPPORTED_DSNVER=235; export MIN_SUPPORTED_DSNVER
MAX_SUPPORTED_DSNVER=300; export MAX_SUPPORTED_DSNVER

SUPPORTED_DSNDOTVER="2.3E 3.0 3.0NE"; export SUPPORTED_DSNDOTVER

KIT_PATH=""

# The following variables hold the item number of the user's main menu selection.
# To add/remove a main menu item:
#      1) edit this list
#      2) edit display_main_menu
#      3) edit read_main_menu_input
#      4) edit main_menu_UI_loop

MM_INSTALL_CA=""
MM_INSTALL_CCAT=""
MM_REMOVE_CA=""
MM_REMOVE_CCAT=""
MM_REMOVE_WEBES=""
MM_CFG_STARTUP=""
MM_CUST_INFO=""
MM_SERVOB=""
MM_SYS_INFO=""
MM_START_WEBES=""
MM_STOP_WEBES=""
MM_HELP=""
MM_QUIT=""

# Make all new files have no permissions for group and world.
umask 077

###############################################################################
#
# START OF SUBROUTINES
#
###############################################################################
# The functions in this section deal with installing the optional
# components, i.e., CA, CCAT, Unicensus.

install_CA ()
{
    /bin/echo ""
    /bin/echo "Installing System Event Analyzer ${PREFIX}${CADOTVER}"

    get_kit_path "MUST_HAVE"
     
     
     echo "installing kit ....."

    stop_WEBES_if_running "ALL_NODES"

  # Fix for PTR 91-22-1920
  #  get_registry_item webes.Installed; WEBINST="$GR_ITEM"
  #  if [ "$WEBINST" = "t" ]; then
  #     sed_registry_file webes.Installed "f"
  #  fi
  # Fix for PTR 91-22-1920

if [ -f ${SVCTOOLS_HOME}/specific/desta/data/webesInstalled.txt ]; then

     /bin/rm -f ${SVCTOOLS_HOME}/specific/desta/data/webesInstalled.txt


 fi




    /bin/rpm -ih --force $KIT_PATH/WEBESSEA-${WEBESSEARPM}.i386.rpm
    if [ $? != 0 ]; then
       exit 1
    fi
    return 0
}


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

install_CCAT ()
{
# Oct13, 2003     
    /bin/echo ""
    /bin/echo "Installing Computer Crash Analysis Tool ${PREFIX}${CCATDOTVER}"

    get_kit_path "MUST_HAVE"

    stop_WEBES_if_running "ALL_NODES"

  # Fix for PTR 91-22-1920
  #  get_registry_item webes.Installed; WEBINST="$GR_ITEM"
  #  if [ "$WEBINST" = "t" ]; then
  #     sed_registry_file webes.Installed "f"
  #  fi
  # Fix for PTR 91-22-1920

if [ -f ${SVCTOOLS_HOME}/specific/desta/data/webesInstalled.txt ]; then

     /sbin/rm -f ${SVCTOOLS_HOME}/specific/desta/data/webesInstalled.txt


 fi



    /bin/rpm -ih ${KIT_PATH}/WEBESCCAT-${WEBESCCATRPM}.i386.rpm
    if [ $? != 0 ]; then
	exit 1
    fi
    return 0
}

###############################################################################
# The following functions perform the WEBES configuration.

configure_webes ()
{
  review_customer_info

  review_system_info

  create_user_profile

  prepare_for_webes_execution

  review_service_obligation

  ping_test

  set_CfgState_configured
}

configure_newbies ()
{
   configure_webes

   if [ -n "$CA_INSTALLED" ]; then
      /bin/echo ""
      /bin/echo "Updating System Event Analyzer notification"
      setup_notification
      register_ACHS_items
      create_notifyca_txt
   fi
   if [ -n "$CCAT_INSTALLED" ]; then
      /bin/echo ""
      /bin/echo "Updating Computer Crash Analysis Tool notification"
      setup_notification
      create_notifyccat_txt
   fi

   configure_startOnBoot
}

# The following function sets up for WEBES to be run from the command
# line.

prepare_for_webes_execution ()
{
  pwe_OldDir=`/bin/pwd`
  cd /usr/sbin
  SBINFILES="desta"

#  echo "BEGIN EXECUTING prepare_for_webes_execution"
   get_installed_product CA_INSTALLED ""
#  echo "AFTER EXECUTING get_installed_product for CA" 
   get_installed_product CCAT_INSTALLED ""
#  echo "AFTER EXECUTING get_installed_product for CCAT" 
   /bin/echo ""
   if [ -z "$CA_INSTALLED" -a -z "$CCAT_INSTALLED" ]; then
	###### Do Nothing ##########
         /bin/echo " "
   else
     if [ -e ${SVCTOOLS_HOME}/common/bin/temp_desta_message ]; then
        /bin/rm ${SVCTOOLS_HOME}/common/bin/temp_desta_message
     fi
     for i in $SBINFILES; do
        /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/$i ./$i
     done
   fi
  cd $pwe_OldDir
}

set_CfgState_configured ()
{
  # Update the registry, first for the local node then for the rest of the cluster,
  # with CfgState = "CONFIGURED"

  case "$CONSTRAINT" in
     "INIT")
        sed_cluster_registries webes.CfgState "CONFIGURED"
	;;
     "NEW_MEMBER")
        for MBR in $NEW_MEMBER_MBRS; do
           sed_remote_registry_file $MBR webes.CfgState "CONFIGURED"
        done
	;;
  esac
}

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

configure_CA ()
{
    /bin/echo ""
    /bin/echo "Configuring System Event Analyzer"
    /bin/echo ""

    if [ "${WILDFIRE_HOST}" ]; then
	/bin/rm -rf ${SVCTOOLS_HOME}/ca/store
    fi

    if [ -e ${SVCTOOLS_HOME}/common/bin/temp_desta_message ]; then
	/bin/rm -f ${INSTDIR}/usr/sbin/desta
	/bin/rm -f ${SVCTOOLS_HOME}/common/bin/temp_desta_message
	/bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta ${INSTDIR}/usr/sbin
    fi

# PTR 91-22-1500
    /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/wsea ${INSTDIR}/usr/sbin

    setup_notification
   
    register_ACHS_items
  
    create_notifyca_txt

    [ -z "$ANSWER_FILE" ] && delay_ca_scavenging

    # Remember that we've installed a new component
    NEW_COMPONENT="true"
    CA_CONFIGURED="true"

    /bin/echo ""
}

delay_ca_scavenging()
{
read_input "Do you wish to delay the initial scan?" "yes/no" "no" ""
[ "$input" = "no" ] && return
input=`/bin/echo $input |cut -c 1 | /usr/bin/tr [a-z] [A-Z]`
[ "$input" != "Y" ] && return
while true
do
  echo "Please enter the date and time for CA scan to start"
  echo "in the format [dd-MMM-yyyy HH:mm]"
  echo "where dd=numeric day of the month,"
  echo "MMM=English 3-character month abbreviation, yyyy=4-digit year"
  read scav_date time
  while true
  do
       if [ "$scav_date" = "" -o "$time" = "" ]; then
          echo "The fields cannot be empty"
          echo "Please enter the date and time in [dd-MMM-yyyy HH:mm] format"
          read scav_date time
       else
	  break
       fi
  done
  if [ ! -z $scav_date -a ! -z $time ]; then
    day=`/bin/echo $scav_date |cut -f 1 -d -`
    if [ $day -gt 0 -a $day -lt 32 ]
    then
       day_flag="VALID"
    else
       day_flag="INVALID"
    fi
    month=`/bin/echo $scav_date |cut -f 2 -d - | /usr/bin/tr [a-z] [A-Z]`
    MONTH_LIST="JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC"
    for MON in $MONTH_LIST; do
      if [ $month = $MON ]; then
        if [ $month = FEB -o $month = APR -o $month = JUN -o $month = SEP -o $month = NOV ]; then
          if [ $day -eq 31 ]; then
            day_flag="INVALID"
          fi
        fi
        if [ $month = FEB ]; then
           if [ $day -gt 28 ]; then
                day_flag="INVALID"
           fi
        fi
        month_flag="VALID"
        break
      else
        month_flag="INVALID"
      fi
    done
    year=`/bin/echo $scav_date |cut -f 3 -d - `
    if [ $year -gt 2000 -a $year -lt 2099 ]; then
       year_flag="VALID"
    else
       year_flag="INVALID"
    fi
    hour=`/bin/echo $time |cut -f 2 -d " " | cut -f 1 -d :`
    min=`/bin/echo $time |cut -f 2 -d " " | cut -f 2 -d :`
    if [ $hour -lt 24 -a $min -lt 60 ];then
        time_flag="VALID"
    else
        time_flag="INVALID"
    fi

    if [ $day_flag = "VALID" -a $month_flag = "VALID" -a $year_flag = "VALID" -a $time_flag = "VALID" ]; then
       SCAV_TIME="$day-$month-$year $time"
       NODE_LIST=$MBR_NODENAMES
       for NODE in $NODE_LIST
       do
	 /bin/echo ""
	 /bin/echo "...updating the registry on $NODE"
         if [ "$NODE" = "$FULL_HOSTNAME" ]; then
	    sed_registry_file scavStart "${SCAV_TIME}"
	 else
	    MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	    if [ -z "$MBR" ]; then
	        /bin/echo "unable to translate $NODE to cluster member ID"
		continue
	    else
		/bin/cp -p /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG ./rui_temp
		if [ "$?" != "0" ]; then
		   /bin/echo "failed to retrieve registry fom $NODE"
		fi
		sed_temp_registry ./rui_temp  scavStart "${SCAV_TIME}"
		/bin/cp -p ./rui_temp /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG
		if [ "$?" != "0" ]; then
		   /bin/echo "failed to restore registry to $NODE"
		fi
	    fi
	  fi
       done
       /bin/rm -f ./rui_temp
       break
    else
       echo " Please enter valid date and time in correct format"
       continue
    fi
 fi
done

}

register_ACHS_items ()
{
    # Create the correct registry entries for DSN notification. Put these
    # in a non-CDSL file so all nodes can get to it. It will be used if a new
    # member is added to the cluster.
    #
    # NOTE: ACHS_CONTACT is used in create_notifyca_txt ().
   
   if [ -z "$ANSWER_FILE" ]; then
      get_registry_item CA.ACHSContact; ACHS_CONTACT="$GR_ITEM"
      /bin/echo ""
      /bin/echo "To whom should system event notifications be addressed?"
      /bin/echo ""
      read_input "Contact Name " "" "$ACHS_CONTACT" "NAMEINPUT"
      ACHS_CONTACT="$input"
   else
      get_answer_item ACHSContact; ACHS_CONTACT="$GA_ITEM"
   fi
    
    TEMP=${SVCTOOLS_HOME}/common/ca/config/ACHSInfo
    /bin/rm -f $TEMP
    touch $TEMP
    sed_temp_registry $TEMP CA.ACHSContact "$ACHS_CONTACT"
    sed_temp_registry $TEMP CA.ACHSProfile "${SVCTOOLS_HOME}/specific/desta/config/profile.txt"
    sed_temp_registry $TEMP CA.ACHSRoute "SICL"
    /bin/echo ""
}

create_notifyca_txt ()
{
   # This function is only called during initialization. After the file has been
   # created the user can edit it manually. If CONSTAINT = INIT, go through all
   # nodes. If CONSTRAINT = NEW_MEMBER, work only with the new member nodes.

   if [ "$CONSTRAINT" = "INIT" ]; then
      NODE_LIST=$MBR_NODENAMES
   elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
      NODE_LIST=$NEW_MEMBER_NODES
   else
      return
   fi

   for N in $NODE_LIST; do
      if [ "$N" = "$FULL_HOSTNAME" ]; then
         # the local node, or not clustered
         NOTIFY_FILE=${SVCTOOLS_HOME}/specific/desta/config/NotifyCA.txt
	 GET_CMD=get_registry_item; MBR=""
	 NODE=$FULL_HOSTNAME
      else
         MBR=`/bin/egrep "${N}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
         if [ -z "$MBR" ]; then
	    /bin/echo "create_notifyca_txt: unable to translate $N to cluster member ID"
	    continue
         else
	    NOTIFY_FILE=/usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/NotifyCA.txt
	    GET_CMD=get_remote_registry_item
	    NODE=$N
	 fi
      fi

    if [ -z "$ANSWER_FILE" ]; then
        $GET_CMD CA.ACHSContact $MBR; SMTP_CONTACT="$GR_ITEM"
        $GET_CMD common.SMTPServer $MBR; SMTP_SERVER="$GR_ITEM"
    else
       get_answer_item ACHSContact $N; SMTP_CONTACT="$GA_ITEM"      
       get_answer_item SMTPServer $N; SMTP_SERVER="$GA_ITEM"     
    fi
    
      /bin/echo "...creating notification template on $N"

      [ -f $NOTIFY_FILE ] && /bin/rm -f $NOTIFY_FILE

      /bin/echo "# NotifyCA.txt" >$NOTIFY_FILE
      /bin/echo "#" >>$NOTIFY_FILE
      /bin/echo "SERVER=${SMTP_SERVER}" >>$NOTIFY_FILE
      /bin/echo "FROM=sea@${N}" >>$NOTIFY_FILE
      /bin/echo "TO=${ACHS_CONTACT}" >>$NOTIFY_FILE
      /bin/echo "SUBJECT=System Event Analyzer Event Notification" >>$NOTIFY_FILE
   done
   /bin/echo " "
}

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

configure_CCAT ()
{

   /bin/echo ""
   /bin/echo "Configuring Computer Crash Analysis Tool"
   /bin/echo ""
   
   if [ -e ${SVCTOOLS_HOME}/common/bin/temp_desta_message ]; then
	/bin/rm -f ${INSTDIR}/usr/sbin/desta
        /bin/rm -f ${SVCTOOLS_HOME}/common/bin/temp_desta_message
        /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta ${INSTDIR}/usr/sbin
   fi

   /bin/ln -fs ${SVCTOOLS_HOME}/common/bin/wccat ${INSTDIR}/usr/sbin
   cd /etc/rc.d/rc3.d
   /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/wccat_startup ./S99wccat

   setup_notification
   create_notifyccat_txt

   cd $SVCTOOLS_HOME

   # Remember that we've installed a new component
   NEW_COMPONENT="true"

   /bin/echo ""
}

create_notifyccat_txt ()
{
   # This function is only called during initialization. After the file has been
   # created the user can edit it manually. If CONSTAINT = INIT, go through all
   # nodes. If CONSTRAINT = NEW_MEMBER, work only with the new member nodes.

   if [ "$CONSTRAINT" = "INIT" ]; then
      NODE_LIST=$MBR_NODENAMES
   elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
      NODE_LIST=$NEW_MEMBER_NODES
   else
      return
   fi

  if [ -z "$ANSWER_FILE" ]; then  
       get_registry_item ccat.ACHSContact; ACHS_CONTACT="$GR_ITEM"
      /bin/echo "To whom should crash analysis notifications be addressed?"
      /bin/echo ""
      read_input "Contact Name " "" "$ACHS_CONTACT" "NAMEINPUT"
      ACHS_CONTACT="$input"
     /bin/echo ""
  else
     get_answer_item ACHSContact; ACHS_CONTACT="$GA_ITEM"
 fi

   for N in $NODE_LIST; do
      if [ "$N" = "$FULL_HOSTNAME" ]; then
         # the local node, or not clustered
         #NOTIFY_FILE=${SVCTOOLS_HOME}/config/CCATNotify.txt
	 NOTIFY_FILE=${SVCTOOLS_HOME}/specific/desta/config/CCATNotify.txt
	 GET_CMD=get_registry_item; MBR=""
	 NODE=$FULL_HOSTNAME
      else
         MBR=`/bin/egrep "${N}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
         if [ -z "$MBR" ]; then
	    /bin/echo "create_notifyccat_txt: unable to translate $N to cluster member ID"
	    continue
         else
	    NOTIFY_FILE=/usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/CCATNotify.txt
	    GET_CMD=get_remote_registry_item
	    NODE=$N
	 fi
      fi

  if [ -z "$ANSWER_FILE" ]; then  
        $GET_CMD common.SMTPContact $MBR; SMTP_CONTACT="$GR_ITEM"
        $GET_CMD common.SMTPServer $MBR; SMTP_SERVER="$GR_ITEM"
  else
       get_answer_item ACHSContact $N; SMTP_CONTACT="$GA_ITEM"
       get_answer_item SMTPServer $N; SMTP_SERVER="$GA_ITEM"
  fi
      /bin/echo "...creating notification template on $N"

      [ -f $NOTIFY_FILE ] && /bin/rm -f $NOTIFY_FILE

      /bin/echo "# CCATNotify.txt" >$NOTIFY_FILE
      /bin/echo "#" >>$NOTIFY_FILE
      /bin/echo "SERVER=${SMTP_SERVER}" >>$NOTIFY_FILE
      /bin/echo "FROM=ccat@${N}" >>$NOTIFY_FILE
      /bin/echo "TO=${ACHS_CONTACT}" >>$NOTIFY_FILE
      /bin/echo "SUBJECT=Computer Crash Analysis Tool Notification" >>$NOTIFY_FILE
   done
   /bin/echo " "
}

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

remove_CA ()
{
    /bin/echo "...removing System Event Analyzer"
#    /bin/rpm -e WEBESSEA-${CADOTVER}-0
    /bin/rpm -e WEBESSEA-${WEBESSEARPM}
    /bin/echo "...done"
}

remove_CCAT ()
{
    /bin/echo "...removing Computer Crash Analysis Tool"
    /bin/rpm -e  WEBESCCAT-${WEBESCCATRPM}
    /bin/echo "...done"
}

remove_all_WEBES ()
{
    /bin/echo ""
    /bin/echo "Preparing to remove these WEBES components:"
    /bin/echo ""
    [ -n "${CA_INSTALLED}" ] && /bin/echo "  System Event Analyzer ${PREFIX}${CADOTVER}"
    [ -n "${CCAT_INSTALLED}" ] && /bin/echo "  Computer Crash Analysis Tool ${PREFIX}${CCATDOTVER}"
    [ -n "${WCC_INSTALLED}" ] && /bin/echo "  WEBES Common Components ${PREFIX}${WCCDOTVER}"
    /bin/echo ""

    stop_WEBES_if_running "ALL_NODES"

    [ -n "${CA_INSTALLED}" ] && remove_CA
    [ -n "${CCAT_INSTALLED}" ] && remove_CCAT

#    /bin/rpm -e WEBESBASE-${WCCDOTVER}-0
    /bin/rpm -e WEBESBASE-${WEBESRPM}

    /bin/echo ""
    /bin/echo "WEBES removal is now complete."
    /bin/echo ""
    /bin/rpm -e WEBESPROXY-${WCCPROXYRPM} 2>/dev/null   
    exit 0
}

###############################################################################
# The following three subroutines deal with setting up notification.
#
# This subroutine prompts the user to select a notification method, i.e., SICL,
# QSAP, or NONE. It checks for supported versions of DSNLink before offering
# SICL as one of the options.
#
#
# Note - Answer file's existence overrides any saved configurations that occur due to a previous uninstall.
#  
#     Truth table for notification
#     ----------------------------
#
#  Answer   ISEE      DSNLink   
#   File  Installed  Installed    Response
# -----------------------------------------------------------------------------
#    0        0          0        Prompt for QSAP
#    0        0          1        Prompt for SICL, QSAP
#    0        1          0        Use ISEE
#    0        1          1        Use ISEE, prompt for SICL
#    1        0          0        Use QSAP if in answer file
#    1        0          1        Use SICL and/or QSAP, if in answer file
#    1        1          0        Use ISEE if in answer file
#    1        1          1        Use ISEE and/or SICL, if in answer file
#
# If there is no answer file, the user may be prompted to choose. But if
# ISEE is available by default it must be used. 

setup_notification ()
{
    # Allow setup for WCC, CA or CCAT initial config sessions and
    # when a new cluster member is added, but not otherwise.

    if [ "$CONSTRAINT" = "INIT" ]; then
        NODE_LIST=$MBR_NODENAMES
    elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
        /bin/echo ""
	/bin/echo "   NOTE: no notification type will be enabled for the new cluster"
	/bin/echo "   member(s). To select a Service Provider Notification method you"
	/bin/echo "   must execute \"ca sicl on\" or \"desta qsap on\" on each added"
	/bin/echo "   cluster member."
	/bin/echo ""
	return
    else
        return
    fi

    # Notification setup is only done ONCE. Both CA and CCAT will attempt it.
    # If notification type is already something other than NONE, don't ask to
    # change it.

    get_registry_item notification.Queried; [ "$GR_ITEM" = "YES" ] && return
   # get_registry_item notification.Type; [ "$GR_ITEM" != "SMTP" ] && return

    sed_registry_file notification.Queried "YES"

    # Loop to prompt the user and range check the input.
    NOTIFY_REG_VALUE=`/bin/grep "notification.Type" ${SVCTOOLS_HOME}/specific/desta/config/DESTA.REG | /bin/cut -f 2 -d=`
    NOTIFY_TYPES="" 
    NOTIFY="" 
    ISEE_Available=""
    SICL_Available=""
    QSAP_Available=""
    QSAP_GATEWAY=""
    QSAP_PORT=""
    
    verify_ISEE_installed
   # get_supported_DSNLink


    if [ -n "$ANSWER_FILE" ] ; then
      get_answer_item NotificationType; 
      NOTIFY="`for NOTIFYTYPE in $GA_ITEM; do /bin/echo $NOTIFYTYPE | /bin/grep ISEE; done`"
      [ -n "$NOTIFY" -a -n "$INSTALLED" ] && ISEE_Available="true"
      
      NOTIFY="`for NOTIFYTYPE in $GA_ITEM; do /bin/echo $NOTIFYTYPE | /bin/grep SICL; done`"
      [ -n "$NOTIFY" -a -n "$DSN_INSTALLED" ] && SICL_Available="true"

      NOTIFY="`for NOTIFYTYPE in $GA_ITEM; do /bin/echo $NOTIFYTYPE | /bin/grep QSAP; done`"
       [ -n "$NOTIFY" -a -z "$INSTALLED" ] && QSAP_Available="true"
   else
     [ -n "$INSTALLED" ] && ISEE_Available="true"
#     [ -n "$DSN_INSTALLED" ] && SICL_Available="true"
#     [ -z "$INSTALLED" ] && QSAP_Available="true"
   fi

    if [ -n "$ANSWER_FILE" ] ; then   # start of Notification list
       [ -n "$ISEE_Available" ] && NOTIFY_TYPES="ISEE"
       if [ -n "$SICL_Available" ]; then
          if [ -z "$NOTIFY_TYPES" ]; then
	     NOTIFY_TYPES="ACHS"
	  else
	     NOTIFY_TYPES="$NOTIFY_TYPES ACHS"
	  fi
       fi
       if [ -n "$QSAP_Available" ]; then
          if [ -z "$NOTIFY_TYPES" ]; then
	     NOTIFY_TYPES="QSAP"
	  else
	     NOTIFY_TYPES="$NOTIFY_TYPES QSAP"
	  fi
	  get_answer_item QSAPPort; QSAP_PORT="$GA_ITEM"
	  get_answer_item QSAPGateway; QSAP_GATEWAY="$GA_ITEM"
       fi
#    else
#	 Not using an answer file. If ISEE is available it must be used.
#	 if [ -n "$ISEE_Available" ]; then
#	  NOTIFY_TYPES="ISEE"
#	  /bin/echo ""
#	  /bin/echo "Instant Support Enterprise Edition (ISEE) is installed and will be used"
#	 /bin/echo ""
#	fi
     fi
#	 If DSNLink is also installed prompt the user. Warn about duplicate callouts.
 #         if [ -n "$SICL_Available" ]; then
 #	     /bin/echo ""
 #	     /bin/echo "  Both ISEE and DSNLink are available. ISEE will be enabled"
 #	     /bin/echo "  and is normally sufficient, but SICL/DSNLink may also be"
 #	     /bin/echo "  enabled. If both are used, duplicate problem reports will"
 #	     /bin/echo "  be sent to the customer support centers."
 #	     /bin/echo ""
 #            read_input "Do you want SICL/DSNLink to also be enabled?" "yes/no" "no" ""
 #            CHOICE=`/bin/echo $input | tr [A-Z]  [a-z]`
 #            if [ "$CHOICE" = "y" -o "$CHOICE" = "yes" ]; then	         
 #	        if [ -z "$NOTIFY_TYPES" ]; then
 #		   NOTIFY_TYPES="ACHS"
 #	        else
 #		   NOTIFY_TYPES="$NOTIFY_TYPES ACHS"
 #	        fi
 #	     fi
 #	  fi
 #      else
 #	  # display the usual menu
 #	  while true
 #	  do
 #	    SN_ITEM=1
 #	    SN_DSN=""; SN_CSG=""; SN_NONE=""
 #            /bin/echo ""
 #
 #           # Fix for PTR 91-22-1878 
 #            /bin/echo "Please Note:"
 #            /bin/echo ""
 #
 #            if [ -n "$SICL_Available" ]; then
 #		/bin/echo "DSNlink will not be supported after January 2005. It is being replaced with ISEE."
 #               /bin/echo "To install ISEE, please contact your local field representative or visit the ISEE page at:"
 #               /bin/echo "http://www.hp.com/hps/hardware/hw_enterprise.html"
 #               /bin/echo "Click on the link \"Download ISEE\"." 

 #                /bin/echo ""
 #	    fi
 
 #            /bin/echo ""
 #           /bin/echo "PRS (CSG/QSAP) will not be supported after February 2005. It is being replaced with ISEE."
 #           /bin/echo "OSEM will continue to be supported, but it does not send notifications to HP customer support."
 #           /bin/echo "To install ISEE, please contact your local field representative or visit the ISEE page at:"
 #           /bin/echo "http://www.hp.com/hps/hardware/hw_enterprise.html"
 #           /bin/echo "Click on the link \"Download ISEE\"."

 #            /bin/echo ""
            # Fix for PTR 91-22-1878

 #            /bin/echo "Please select a Service Provider Notification method:"
 #           /bin/echo ""
 #           if [ -n "$DSN_INSTALLED" ]; then
 #              /bin/echo " $SN_ITEM) System-Initiated Call Logging (SICL) using DSNlink"
 #              SN_DSN=$SN_ITEM; SN_ITEM=`expr $SN_ITEM + 1`
 #           fi
 #           /bin/echo " $SN_ITEM) Customer Service Gateway (CSG, formerly QSAP) or Open Service Event Manager (OSEM)"
 #           SN_CSG=$SN_ITEM; SN_ITEM=`expr $SN_ITEM + 1`
 #           /bin/echo " $SN_ITEM) None"
 #            SN_NONE=$SN_ITEM
 #            /bin/echo ""
 #           read_input "Choose from the above:" "" "" "NotifyTypes"
 #           CHOICE="$input"
 #           /bin/echo ""
 #           if [ "$CHOICE" = "" ]; then
 #               sed_registry_file notification.Type "${NOTIFY_REG_VALUE}"
 #	        return
 #	    elif [ "$CHOICE" = "$SN_DSN" ]; then
 #		NOTIFY_TYPES="ACHS"
 #		break
 #	    elif [ "$CHOICE" = "$SN_BOTH" ]; then
 #		NOTIFY_TYPES="QSAP ACHS"
 #		break
 #	    elif [ "$CHOICE" = "$SN_CSG" ]; then
 #		NOTIFY_TYPES="QSAP"
 #		break
 #	    elif [ "$CHOICE" = "$SN_NONE" ]; then
 #               sed_registry_file notification.Type "${NOTIFY_REG_VALUE}"
 #		return
 #	    else
 #		/bin/echo "$CHOICE is not a valid selection"
 #	    fi
 #	  done
 
          # If we're doing QSAP setup, get the QSAP port number and gateway address.
 #	  TEMP="`for N in $NOTIFY_TYPES; do /bin/echo $N | /bin/grep QSAP; done`"
 #	  if [ -n "$TEMP" ]; then
 #	     get_QSAP_user_input QSAP_STATUS
 #	     if [ "$QSAP_STATUS" -eq "1" ]; then
 #		# Remove QSAP from the NOTIFY_TYPES list, or return if it was the only selected type.
 #	        [ "$NOTIFY_TYPES" = "QSAP" ] && return
 #		[ "$NOTIFY_TYPES" = "QSAP ACHS" ] && NOTIFY_TYPES="ACHS"
 #	     fi
 #	  fi
 #      fi
 #   fi
 
   NODE=$FULL_HOSTNAME
   if [ "$NODE" = "$FULL_HOSTNAME" ]; then
      sed_registry_file notification.Type "${NOTIFY_REG_VALUE} ${NOTIFY_TYPES}"
      if [ "${NOTIFY_TYPES}" = "QSAP" -o "${NOTIFY_TYPES}" = "QSAP ACHS" ]; then
         sed_registry_file desta.QSAP "$QSAP_GATEWAY"
         sed_registry_file desta.QSAPport "$QSAP_PORT"
      fi
   fi
   
} 

# Include the sed_registry_file () incase it is not being exported from wcc_install_xxx.sh

verify_ISEE_installed ()
{
   INSTALLED=""
   PKG=`rpm -aq | grep ^ISEEPlatform*`

   if [ "$PKG" != "" ]; then
       INSTALLED="true"
#    /bin/echo "If ISEE is Installed then setting the value to true"	

   fi
}


get_QSAP_user_input ()
{
    # Ask the same questions as the "desta qsap on" command.

    rm -f $SVCTOOLS_HOME/common/desta/config/QSAP*
   
    # Fix for PTR 91-22-1878
    /bin/echo "Enter the name of the Customer Service Gateway (CSG, formerly QSAP) or Open Service Event Manager (OSEM) node."
    read_input "CSG or OSEM node: " "" "" "CSG_setup"
    # Fix for PTR 91-22-1878

    if [ -z "$input" ]; then
        /bin/echo ""
        /bin/echo "Notification setup aborted - you can enable CSG notification"
        /bin/echo "later by executing the \"desta qsap on\" command."
        /bin/echo ""
        eval $1=1
        return
    fi
    QSAP_GATEWAY=$input

    # The default port number is in the Java source - see HTTPTransport.qsapPortKey.
    /bin/echo ""
    # Fix for PTR 91-22-1878
    /bin/echo "Enter the port number the CSG or OSEM is listening on."
    read_input "CSG or OSEM port: " "" "2069" "CSG_setup"
    # Fix for PTR 91-22-1878
    
    QSAP_PORT=$input
    /bin/echo ""
    eval $1=0
}
 

get_supported_DSNLink ()
{
    # Find out if a supported version of DSNLink is installed. If an old
    # version is found return the dot notation version. If WorldWire is
    # installed, don't complain but clear the version number.

    DSN_INSTALLED=""
    get_installed_product DSN_INSTALLED ""
    if [ -n "$DSN_INSTALLED" ]
    then
        if [ "$DSN_INSTALLED" -lt "$MIN_SUPPORTED_DSNVER" ]
        then
            DSN_INSTALLED=""
            get_installed_product DSN_INSTALLED getdots
            /bin/cat << EOF
An unsupported version of DSNLink (v${DSN_INSTALLED}) is installed
on this host. If SICL notification via DSNLink is desired,
upgrade to one of the following versions:

EOF
            for TEMP in $SUPPORTED_DSNDOTVER; do
                /bin/echo "   DSN v${TEMP}"
            done
            /bin/cat << EOF

For more information on DSNLink and downloadable kits, go to:

   http://www.support.compaq.com/dsnlink/

EOF
	DSN_INSTALLED=""
        elif [  "$DSN_INSTALLED" -gt "$MAX_SUPPORTED_DSNVER" ]
        then
            # These versions are WorldWire.
            DSN_INSTALLED=""
        fi
   fi
}

###############################################################################
# These two functions configure whether the Director should start when the
# system boots up. The remove function is called when optional components are
# deinstalled - it can't start if only the core components are installed.

remove_startOnBoot ()
{
  get_all_installed_products
  if [ -z "$CA_INSTALLED" -a -z "$CCAT_INSTALLED" ]; then
     /bin/echo ""
     /bin/echo "No optional components are installed - WEBES will not start on boot."
     /bin/echo ""

      /bin/rm -f /etc/rc.d/rc6.d/K01desta
      /bin/rm -f /etc/rc.d/rc5.d/S89desta
      /bin/rm -f /etc/rc.d/rc4.d/S89desta
      /bin/rm -f /etc/rc.d/rc3.d/S89desta
      /bin/rm -f /etc/rc.d/rc2.d/S89desta
      /bin/rm -f /etc/rc.d/rc1.d/K01desta
      /bin/rm -f /etc/rc.d/rc0.d/K01desta
     
      sed_cluster_registries webes.startOnBoot "false"

     STOPPED_NODES=""
     create_temp_desta_file
  fi
}

# This function is called when optional components are installed, and when the user 
# chooses "Start at Boot Time" from the main menu. The latter case has null CONSTRAINT
# and the user doesn't HAVE to change things if it's already been configured once.

configure_startOnBoot ()
{
  /bin/echo ""
  get_all_installed_products

  # Can't start if the optional components aren't installed.
  if [ -z "$CA_INSTALLED" -a -z "$CCAT_INSTALLED" ]; then
     # Can't start on the local node
     if [ -f /etc/rc.d/rc5.d/S89desta -o -f /etc/rc.d/rc4.d/S89desta -o -f /etc/rc.d/rc3.d/S89desta -o -f /etc/rc.d/rc2.d/S89desta -o -f /etc/rc.d/rc1.d/K01desta -o -f /etc/rc.d/rc0.d/K01desta ]; then
         /bin/echo "WEBES is currently configured to start at boot time"
	/bin/echo "but the optional components are not present. WEBES will"
	/bin/echo "be reconfigured so it does not start automatically."
	
              /bin/rm -f /etc/rc.d/rc6.d/K01desta
              /bin/rm -f /etc/rc.d/rc5.d/S89desta
              /bin/rm -f /etc/rc.d/rc4.d/S89desta
              /bin/rm -f /etc/rc.d/rc3.d/S89desta
              /bin/rm -f /etc/rc.d/rc2.d/S89desta
              /bin/rm -f /etc/rc.d/rc1.d/K01desta
              /bin/rm -f /etc/rc.d/rc0.d/K01desta
   
	sed_cluster_registries webes.startOnBoot "false"
     else
	/bin/echo "No optional components are installed. WEBES cannot"
	/bin/echo "be configured to start when the system boots."
     fi
     return
  fi

  # It's easier to do the standalone node as a special case.
  BOOT_Enabled=""
  if [ -z "$IS_CLUSTER_MEMBER" ]; then
     get_registry_item webes.startOnBoot; START="$GR_ITEM"
     if [ -z "$START" -o "$START" = "false" ]; then
	if [ -n "$ANSWER_FILE" ]; then
            get_answer_item StartOnBootFlag; BOOT_Enabled="$GA_ITEM"
             if [ -z "$BOOT_Enabled" -o "$BOOT_Enabled" = "false" ]; then
               input="no"
             else
               input="yes"
             fi   
        else
        /bin/echo "WEBES is not currently configured to start at boot time."
	read_input "Should WEBES start at boot time on $FULL_HOSTNAME?" "yes/no" "yes" "StartOnBoot"
	fi
        if [ "$input" = "no" ]; then
           #######################PTR 91-22-1571
           /bin/rm -f /etc/rc.d/rc6.d/K01desta  
           /bin/rm -f /etc/rc.d/rc5.d/S89desta  
           /bin/rm -f /etc/rc.d/rc4.d/S89desta  
           /bin/rm -f /etc/rc.d/rc3.d/S89desta
           /bin/rm -f /etc/rc.d/rc2.d/S89desta 
           /bin/rm -f /etc/rc.d/rc1.d/K01desta  
           /bin/rm -f /etc/rc.d/rc0.d/K01desta  
           #######################PTR 91-22-1571
	   sed_registry_file webes.startOnBoot "false"
        else
           #######################PTR 91-22-1571
           cd /etc/rc.d/rc6.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./K01desta 
           cd /etc/rc.d/rc5.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta 
           cd /etc/rc.d/rc4.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta 
           cd /etc/rc.d/rc3.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta
           cd /etc/rc.d/rc2.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta 
           cd /etc/rc.d/rc1.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./K01desta 
           cd /etc/rc.d/rc0.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./K01desta 
           #######################PTR 91-22-1571
           cd ${SVCTOOLS_HOME}
           sed_registry_file webes.startOnBoot "true"
         fi
     else
        # don't force user to configure if we're in INIT and just checking to see
        # if we could run.
        if [ "$CONSTRAINT" != "INIT" ]; then
	   /bin/echo "WEBES is currently configured to start at boot time."
	   read_input "Should WEBES start at boot time on $FULL_HOSTNAME?" "yes/no" "yes" "StartOnBoot"
	   if [ "$input" = "no" ]; then
	      sed_registry_file webes.startOnBoot "false"
	      if [ -z "$IS_CLUSTER_MEMBER" ]; then
	         /bin/rm -f /etc/rc.d/rc5.d/S89desta
                       /bin/rm -f /etc/rc.d/rc4.d/S89desta
	         /bin/rm -f /etc/rc.d/rc3.d/S89desta
	         /bin/rm -f /etc/rc.d/rc2.d/S89desta
	         /bin/rm -f /etc/rc.d/rc0.d/K01desta
	         /bin/rm -f /etc/rc.d/rc1.d/K01desta
	         /bin/rm -f /etc/rc.d/rc6.d/K01desta
	      fi
	   fi
	fi
     fi
     /bin/echo ""
     return
  fi

  # Now do the rest of the cluster. Find out where we can run. If we can't
  # run anywhere just fall though to the selection code.

  where_can_WEBES_run

  if [ -n "$COULD_RUN_MBRS" ]; then
     # We could run someplace - if INIT don't make the user reconfigure.
     if [ "$CONSTRAINT" = "INIT" ]; then
	return
     else
	/bin/echo "WEBES is configured to start at boot time on the"
	/bin/echo "following cluster nodes:"
	display_nodes $COULD_RUN_NODES
	/bin/echo ""
	read_input "Do you wish to change this list?" "yes/no" "no" "StartOnBoot"
	[ "$input" = "no" ] && return
     fi
  fi

  # Arrive here to configure a cluster.

  while true
  do
     /bin/echo ""
     /bin/echo "Please enter the nodes on which WEBES should start:"
     get_user_node_selection $MBR_NODENAMES
     if [ -z "$NODE_LIST" ]; then
	break
     elif [ "$NODE_LIST" = "?" ]; then
	help_webes "StartOnBoot"
     else
	if [ ! -e /etc/rc.d/rc3.d/S89desta ]; then
	   cd /etc/rc.d/rc5.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta
	   cd /etc/rc.d/rc4.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta
	   cd /etc/rc.d/rc3.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta
	   cd /etc/rc.d/rc2.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./S89desta
	   cd /etc/rc.d/rc0.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./K01desta
                 cd /etc/rc.d/rc1.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./K01desta
                 cd /etc/rc.d/rc6.d; /bin/ln -sf ${SVCTOOLS_HOME}/common/bin/desta_startup ./K01desta
	   cd $SVCTOOLS_HOME
	fi

	# Configure the selected nodes to start.
	/bin/echo ""
	for NODE in $NODE_LIST; do
	    if [ "$NODE" = "$FULL_HOSTNAME" ]; then
	       /bin/echo "...updating registry on $NODE"
	       stop_WEBES_if_running $NODE
	       sed_registry_file webes.startOnBoot "true"
	    else
	       MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	       if [ -z "$MBR" ]; then
	          /bin/echo "configure_startOnBoot: unable to translate $NODE to cluster member ID"
	          continue
	       else
	          /bin/echo "...updating registry on $NODE"
		  stop_WEBES_if_running $NODE
	          sed_remote_registry_file $MBR webes.startOnBoot "true"
	       fi
	    fi
	done

	# Find the nodes that weren't selected, and configure
	# them not to start.
	for NODE in $MBR_NODENAMES; do
	   TEMP=`/bin/echo $NODE_LIST | /bin/grep $NODE`
	   [ -n "$TEMP" ] && continue
	   if [ "$NODE" = "$FULL_HOSTNAME" ]; then
	      /bin/echo "...updating registry on $NODE"
	      stop_WEBES_if_running $NODE
	      sed_registry_file webes.startOnBoot "false"
	   else
	      stop_WEBES_if_running $NODE
	      MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	      if [ -z "$MBR" ]; then
	         /bin/echo "configure_startOnBoot: unable to translate $NODE to cluster member ID"
	         continue
	      else
	         /bin/echo "...updating registry on $NODE"
	         stop_WEBES_if_running $NODE
	         sed_remote_registry_file $MBR webes.startOnBoot "false"
	      fi
	   fi
	done
	break
     fi
  done
}

# Build two lists, $COULD_RUN_MBRS and $COULD_RUN_NODES containing a list
# of the cluster members/nodes on which WEBES is configured to start at
# boot time.

where_can_WEBES_run ()
{
    COULD_RUN_MBRS=""; COULD_RUN_NODES=""

    get_registry_item webes.startOnBoot; TEMP="$GR_ITEM"
    if [ "$TEMP" = "true" ]; then
       COULD_RUN_MBRS=$MY_MEMBER_ID
       COULD_RUN_NODES=$FULL_HOSTNAME
    fi
    if [ -n "$IS_CLUSTER_MEMBER" ]; then
	for MBR in $OTHER_MBRS_LIST; do
	    get_remote_registry_item webes.startOnBoot $MBR; TEMP="$GR_ITEM"
	    if [ "$TEMP" = "true" ]; then
	       if [ -z "$COULD_RUN_MBRS" ]; then
	          COULD_RUN_MBRS=$MBR
	       else
	          COULD_RUN_MBRS="$MBR $COULD_RUN_MBRS"
	       fi
	       TEMP=`/bin/grep "${MBR}=" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 2 -d=`
	       if [ -n "$TEMP" ]; then
	          if [ -z "$COULD_RUN_NODES" ]; then
		     COULD_RUN_NODES=$TEMP
		  else
	             COULD_RUN_NODES="$TEMP $COULD_RUN_NODES"
		  fi
	       else
	          /bin/echo "where_can_WEBES_run: unable to translate $MBR to node name"
		  continue
	       fi
	    fi
	done
    fi
}

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

review_customer_info ()
{
  # CONSTRAINT = INIT: read local node information. Make the user enter
  #    the info if not present, and apply the results to all nodes. 
  # CONSTRAINT = NEW_MEMBER: read info from first new member. Make the user enter
  #    the info if not present, and apply the results to all new nodes. 
  # CONSTRAINT = null: prompt user for node(s) to work with, display the information
  #    from the first node for verification or prompt if not present. Results will
  #    be applied to all selected nodes.

  /bin/echo ""
  if [ -z "$IS_CLUSTER_MEMBER" ]; then
     /bin/echo "Reviewing Customer Information:"
     NODE_LIST=$MBR_NODENAMES
     GET_CMD=get_registry_item
     MBR=""
     get_user_info_from_registry
  elif [ "$CONSTRAINT" = "INIT" -o -z "$IS_CLUSTER_MEMBER" ]; then
     # Get the info from the local node.
     /bin/echo "Reviewing Customer Information. Information will be"
     /bin/echo "applied to all nodes of the cluster."
     NODE_LIST=$MBR_NODENAMES
     GET_CMD=get_registry_item
     MBR=""
     get_user_info_from_registry
  elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
     # Get the info from the first of the new members.
     /bin/echo "Reviewing Customer Information. Information will be"
     /bin/echo "applied to all newly added cluster nodes."
     NODE_LIST=$NEW_MEMBER_NODES
     for MBR in $NEW_MEMBER_MBRS; do
        GET_CMD=get_remote_registry_item
	get_user_info_from_registry
	break
     done
  else
     /bin/echo "Reviewing Customer Information. Information will be"
     /bin/echo "applied to all selected cluster nodes."
     /bin/echo ""
     while true
     do
        /bin/echo "Please choose the nodes to be effected:"
        get_user_node_selection $MBR_NODENAMES
        if [ -z "$NODE_LIST" ]; then
	   return
        elif [ "$NODE_LIST" = "?" ]; then
	   help_webes "CLUSTERAPPLY"
        else
	   # Get the info from the first of the selected nodes
	   for NODE in $NODE_LIST; do
	      MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	      if [ -z "$MBR" ]; then
	         /bin/echo ""
	         /bin/echo "review_customer_info: unable to translate $NODE to cluster member ID"
	         /bin/echo ""
	         continue
	      else
	         if [ "$MBR" = "$MY_MEMBER_ID" ]; then
		    GET_CMD=get_registry_item
		    MBR=""
		 else
	            GET_CMD=get_remote_registry_item
		 fi
	         get_user_info_from_registry
	         break
	      fi
	   done
	   break
        fi
     done
  fi

  NEED_TO_SAVE_UI=""

  # Only prompt if the user information is missing & if answer does not exist. Mar4,2004
  if [ -n "$ANSWER_FILE" ]; then
     get_user_values
     NEED_TO_SAVE_UI="true" 
  elif [ -z "$USER_NAME" -o -z "$USER_COMPANY" -o -z "$USER_PHONE" -o -z "$USER_EMAIL" ]; then
     get_user_info
  fi
  display_user_info
  [ -z "$ANSWER_FILE" ] && verify_user_info

  if [ -n "$NEED_TO_SAVE_UI" -a -z "$CONSTRAINT" ]; then
     /bin/echo ""
     /bin/echo "If you change the customer information you may"
     /bin/echo "also want to update the ISEE profile. Review:"
     /bin/echo ""
     /bin/echo "      $SVCTOOLS_HOME/specific/desta/config/profile.txt"
     /bin/echo ""
  fi
  if [ -n "$CONSTRAINT" -o -n "$NEED_TO_SAVE_UI" ]; then
     register_user_info
  fi
}

get_user_info_from_registry ()
{
   $GET_CMD common.UserName $MBR; USER_NAME="$GR_ITEM"
   $GET_CMD common.UserCompany $MBR; USER_COMPANY="$GR_ITEM"
   $GET_CMD common.FirstCompanyAddress $MBR; COMPANY_ADDRESS_1="$GR_ITEM"
   $GET_CMD common.SecondCompanyAddress $MBR; COMPANY_ADDRESS_2="$GR_ITEM"
   $GET_CMD common.ThirdCompanyAddress $MBR; COMPANY_ADDRESS_3="$GR_ITEM"
   $GET_CMD common.UserPhone $MBR; USER_PHONE="$GR_ITEM"
   $GET_CMD common.UserEmail $MBR; USER_EMAIL="$GR_ITEM"
}

get_user_values ()
{
   get_answer_item UserName; USER_NAME="$GA_ITEM"
   get_answer_item UserCompany; USER_COMPANY="$GA_ITEM"
   get_answer_item CompanyAddressLine1; COMPANY_ADDRESS_1="$GA_ITEM"
   get_answer_item CompanyAddressLine2; COMPANY_ADDRESS_2="$GA_ITEM"
   get_answer_item CompanyAddressLine3; COMPANY_ADDRESS_3="$GA_ITEM"
   get_answer_item UserPhone; USER_PHONE="$GA_ITEM"
   get_answer_item UserEmail; USER_EMAIL="$GA_ITEM"
}

get_user_info ()
{
   /bin/echo ""
   /bin/echo "Please enter the requested Customer Information:"
   /bin/echo ""

   read_input "Contact Name " "" "$USER_NAME" "NAMEINPUT"
   if [ "$USER_NAME" != "$input" ]; then
	USER_NAME="$input"
	NEED_TO_SAVE_UI="true"
   fi

   read_input "Company Name" "" "$USER_COMPANY" "COMPANYINPUT"
   if [ "$USER_COMPANY" != "$input" ]; then
	USER_COMPANY="$input"
	NEED_TO_SAVE_UI="true"
   fi

   read_input "Company Address" "" "$COMPANY_ADDRESS_1" "COMPANYADDRESSINPUT"
   if [ "$COMPANY_ADDRESS_1" != "$input" ]; then
	COMPANY_ADDRESS_1="$input"
	NEED_TO_SAVE_UI="true"
   fi

   read_input "Company Address (Continued)" "" "$COMPANY_ADDRESS_2" "COMPANYADDRESSINPUT"
   if [ "$COMPANY_ADDRESS_2" != "$input" ]; then
	COMPANY_ADDRESS_2="$input"
	NEED_TO_SAVE_UI="true"
   fi

   read_input "Company Address (Continued)" "" "$COMPANY_ADDRESS_3" "COMPANYADDRESSINPUT"
   if [ "$COMPANY_ADDRESS_3" != "$input" ]; then
	COMPANY_ADDRESS_3="$input"
	NEED_TO_SAVE_UI="true"
   fi

   read_input "Contact Telephone (dash-separated: 123-456-7890)" "" "$USER_PHONE" "PHONEINPUT"
   if [ "$USER_PHONE" != "$input" ]; then
	USER_PHONE="$input"
	NEED_TO_SAVE_UI="true"
   fi

   read_input "Contact Email " "" "$USER_EMAIL" "EMAILINPUT"
   if [ "$USER_EMAIL" != "$input" ]; then
	USER_EMAIL="$input"
	NEED_TO_SAVE_UI="true"
   fi


   /bin/echo ""
   /bin/echo "You have entered the following information:"
}

display_user_info ()
{
   /bin/echo ""
   /bin/echo "Contact Name:             ${USER_NAME}"
   /bin/echo "Contact Company:          ${USER_COMPANY}"
   /bin/echo "Contact Company Address:  ${COMPANY_ADDRESS_1}"
   if [ -n "${COMPANY_ADDRESS_2}" ]; then
     /bin/echo "                          ${COMPANY_ADDRESS_2}"
   fi
   if [ -n "${COMPANY_ADDRESS_3}" ]; then
     /bin/echo "                          ${COMPANY_ADDRESS_3}"
   fi
   /bin/echo "Contact Phone:            ${USER_PHONE}"
   /bin/echo "Contact Email:            ${USER_EMAIL}"
   /bin/echo ""
}

verify_user_info ()
{
   while true; do
      read_input "Is the above information correct?" "yes/no" "yes" "review_cust_info"
      case "$input" in
               "yes") /bin/echo ""
		      break
               ;;
               "no") get_user_info
                     display_user_info
		     continue
               ;;
               *) continue
               ;;
      esac
   done
}

register_user_info ()
{
   # Update the registry on all nodes in NODE_LIST

   for NODE in $NODE_LIST
   do
      /bin/echo ""
      /bin/echo "...updating the registry on $NODE"
      stop_WEBES_if_running $NODE
      if [ "$NODE" = "$FULL_HOSTNAME" ]; then
         sed_registry_file common.UserName "${USER_NAME}"
         sed_registry_file common.UserCompany "${USER_COMPANY}"
         sed_registry_file common.FirstCompanyAddress "${COMPANY_ADDRESS_1}"
         sed_registry_file common.SecondCompanyAddress "${COMPANY_ADDRESS_2}"
         sed_registry_file common.ThirdCompanyAddress "${COMPANY_ADDRESS_3}"
         sed_registry_file common.UserPhone "${USER_PHONE}"
         sed_registry_file common.UserEmail "${USER_EMAIL}"
      else
         MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
         if [ -z "$MBR" ]; then
	    /bin/echo "register_user_info: unable to translate $NODE to cluster member ID"
	    continue
         else
	    /bin/cp -p /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG ./rui_temp
	    if [ "$?" != "0" ]; then
	       /bin/echo "register_user_info: failed to retrieve registry from $NODE"
	    fi
	    sed_temp_registry ./rui_temp common.UserName "${USER_NAME}"
	    sed_temp_registry ./rui_temp common.UserCompany "${USER_COMPANY}"
	    sed_temp_registry ./rui_temp common.FirstCompanyAddress "${COMPANY_ADDRESS_1}"
	    sed_temp_registry ./rui_temp common.SecondCompanyAddress "${COMPANY_ADDRESS_2}"
	    sed_temp_registry ./rui_temp common.ThirdCompanyAddress "${COMPANY_ADDRESS_3}"
	    sed_temp_registry ./rui_temp common.UserPhone "${USER_PHONE}"
	    sed_temp_registry ./rui_temp common.UserEmail "${USER_EMAIL}"
	    /bin/cp -p ./rui_temp /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG
	    if [ "$?" != "0" ]; then
	       /bin/echo "register_user_info: failed to restore registry to $NODE"
	    fi
         fi
      fi
      /bin/echo "...done"
   done
   /bin/rm -f ./rui_temp

   # Create a file that can be used by newly added nodes to retrieve the latest info.

   [ -f $SVCTOOLS_HOME/common/desta/config/CommonFiles/UserInformation ] && /bin/rm -f $SVCTOOLS_HOME/common/desta/config/CommonFiles/UserInformation
   touch $SVCTOOLS_HOME/common/desta/config/CommonFiles/UserInformation
   TEMP=$SVCTOOLS_HOME/common/desta/config/CommonFiles/UserInformation
   sed_temp_registry $TEMP common.UserName "${USER_NAME}"
   sed_temp_registry $TEMP common.UserCompany "${USER_COMPANY}"
   sed_temp_registry $TEMP common.FirstCompanyAddress "${COMPANY_ADDRESS_1}"
   sed_temp_registry $TEMP common.SecondCompanyAddress "${COMPANY_ADDRESS_2}"
   sed_temp_registry $TEMP common.ThirdCompanyAddress "${COMPANY_ADDRESS_3}"
   sed_temp_registry $TEMP common.UserPhone "${USER_PHONE}"
   sed_temp_registry $TEMP common.UserEmail "${USER_EMAIL}"

   /bin/echo ""
}

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

review_system_info ()
{
  # CONSTRAINT = INIT: user not allowed to choose nodes. Cycle through all
  #    nodes to read and display info, results applied to same node.
  # CONSTRAINT = NEW_MEMBER: user not allowed to choose nodes. Cycle through
  #    all new members to read and display info, results applied to same node.
  # CONSTRAINT = null: prompt user for node(s) to work with. Cycle through all
  #    nodes to read and display info, results applied to same node.

  if [ "$CONSTRAINT" = "INIT" ]; then
    /bin/echo "Initially necessary to review system info on all nodes."
    NODE_LIST=$MBR_NODENAMES
  elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
    /bin/echo "It is necessary to review system info on all new nodes."
    NODE_LIST=$NEW_MEMBER_NODES
  else
    if [ -z "$IS_CLUSTER_MEMBER" ]; then
       NODE_LIST=$MBR_NODENAMES
    else
       while true
       do
          /bin/echo ""
	  /bin/echo "Please choose the nodes to be reviewed:"
          get_user_node_selection $MBR_NODENAMES
          if [ -z "$NODE_LIST" ]; then
	     return
          elif [ "$NODE_LIST" = "?" ]; then
	     help_webes "ReviewSysInfo"
          else
	     break
          fi
       done
    fi
  fi

  for NODE in $NODE_LIST
  do
    /bin/echo ""
    /bin/echo "Reviewing system information for $NODE:"
    NEED_TO_SAVE_SYSINFO=""; SMTP_CONTACT=""; SMTP_SERVER=""
    SYSTEM_TYPE=""; SYSTEM_MODEL=""; SERIAL_NUMBER=""
    if [ "$NODE" = "$FULL_HOSTNAME" ]; then
       GET_ITEM_CMD="get_registry_item"
       MBR=""
    else
       MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
       if [ -z "$MBR" ]; then
          /bin/echo "review_system_info: unable to translate $NODE to cluster member ID"
          continue
       else
	  GET_ITEM_CMD="get_remote_registry_item"
       fi
    fi
    $GET_ITEM_CMD CA.ACHSContact $MBR; ACHS_CONTACT="$GR_ITEM"
    $GET_ITEM_CMD common.SMTPContact $MBR; SMTP_CONTACT="$GR_ITEM"
    $GET_ITEM_CMD common.SMTPServer $MBR; SMTP_SERVER="$GR_ITEM"
    $GET_ITEM_CMD common.SystemType $MBR; SYSTEM_TYPE="$GR_ITEM"
    $GET_ITEM_CMD common.SystemModel $MBR; SYSTEM_MODEL="$GR_ITEM"
    $GET_ITEM_CMD common.SystemSerialNumber $MBR; SERIAL_NUMBER="$GR_ITEM"

   if [ -n "$ANSWER_FILE" ]; then 
      NEED_TO_SAVE_SYSINFO="true"
      get_answer_item ACHSContact $NODE; ACHS_CONTACT="$GA_ITEM"   
      get_answer_item SMTPContact $NODE; SMTP_CONTACT="$GA_ITEM"
      get_answer_item SMTPServer $NODE; SMTP_SERVER="$GA_ITEM"
      get_answer_item SystemType $NODE
         [ -n "$GA_ITEM" ] && SYSTEM_TYPE="$GA_ITEM"
      get_answer_item SystemModel $NODE
         [ -n "$GA_ITEM" ] && SYSTEM_MODEL="$GA_ITEM"
      get_answer_item SystemSerialNumber $NODE
         [ -n "$GA_ITEM" ] && SERIAL_NUMBER="$GA_ITEM"
   else
       if [ -z "$SERIAL_NUMBER" -o -z "$SYSTEM_MODEL" -o -z "$SYSTEM_TYPE" -o -z "$SMTP_SERVER" ]; then
           get_node_specific_info
       fi
   fi    
    display_node_specific_info
    [ -z "$ANSWER_FILE" ] && verify_node_specific_info

    if [ -n "$NEED_TO_SAVE_SYSINFO" -a -z "$CONSTRAINT" ]; then
       /bin/echo ""
       /bin/echo "If you change the system information you may"
       /bin/echo "also want to update the ISEE profile. Review:"
       /bin/echo ""
       /bin/echo "      $SVCTOOLS_HOME/specific/desta/config/profile.txt"
       /bin/echo ""
    fi
    if [ -n "$NEED_TO_SAVE_SYSINFO" ]; then
       register_node_specific_info
    fi
  done
}

get_node_specific_info()
{
   NEED_TO_SAVE_SYSINFO="true"
   /bin/echo ""
   /bin/echo "Please enter the following system information:"
   /bin/echo ""
   read_input "System Type" "" "$SYSTEM_TYPE" "SystemType"
   SYSTEM_TYPE="$input"
   read_input "System Model" "" "$SYSTEM_MODEL" "SystemModel"
   SYSTEM_MODEL="$input"
   read_input "SMTP Contact " "" "$SMTP_CONTACT" "SMTPContact"
   SMTP_CONTACT="$input"
   read_input "SMTP Server " "" "$SMTP_SERVER" "SMTPServer"
   SMTP_SERVER="$input"
   read_input "System Serial Number " "" "$SERIAL_NUMBER" "SystemSerialNumber"
   SERIAL_NUMBER="$input"
#   read_input "ACHS Contact " "" "$ACHS_CONTACT" "ACHSContact"
#   ACHS_CONTACT="$input"
   /bin/echo ""
   /bin/echo "You have entered the following:"
}

display_node_specific_info()
{
   /bin/echo ""
   /bin/echo "SMTP Contact:             ${SMTP_CONTACT}"
   /bin/echo "SMTP Server:              ${SMTP_SERVER}"
#   /bin/echo "ACHS Contact:             ${ACHS_CONTACT}"
   /bin/echo "System Type:              ${SYSTEM_TYPE}"
   /bin/echo "System Model:             ${SYSTEM_MODEL}"
   /bin/echo "System Serial Number:     ${SERIAL_NUMBER}"
}

verify_node_specific_info()
{
   while true; do
      /bin/echo ""
      read_input "Is the above information correct?" "yes/no" "yes" "INFOCORRECT"
      case "$input" in
               "yes") /bin/echo ""
                      break
               ;;
               "no") get_node_specific_info
                     display_node_specific_info
                     continue
               ;;
               *) continue
               ;;
      esac
   done
}

register_node_specific_info()
{
   # Update the registry on $NODE, which may be a remote or local.
   # If CA is installed, update the "CA." items, too.

   /bin/echo "...updating the registry on $NODE"
   stop_WEBES_if_running $NODE
   if [ "$NODE" = "$FULL_HOSTNAME" ]; then
      sed_registry_file common.SMTPContact "${SMTP_CONTACT}"
      sed_registry_file common.SMTPServer "${SMTP_SERVER}"
      sed_registry_file CA.ACHSContact "${ACHS_CONTACT}"
      sed_registry_file ccat.ACHSContact "${ACHS_CONTACT}"
      sed_registry_file common.SystemType "${SYSTEM_TYPE}"
      sed_registry_file common.SystemModel "${SYSTEM_MODEL}"
      sed_registry_file common.SystemSerialNumber "${SERIAL_NUMBER}"
      if [ -n "$CA_INSTALLED" ]; then
         sed_registry_file CA.ACHSContact "${ACHS_CONTACT}"
	 sed_registry_file CA.Serial.Number "${SERIAL_NUMBER}"
      fi
   else
      /bin/cp -p /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG ./rsi_temp
      if [ "$?" != "0" ]; then
         /bin/echo "register_system_info: failed to retrieve registry from $NODE"
         return
      fi
      sed_temp_registry ./rsi_temp common.SMTPContact "${SMTP_CONTACT}"
      sed_temp_registry ./rsi_temp common.SMTPServer "${SMTP_SERVER}"
      sed_temp_registry ./rsi_temp CA.ACHSContact "${ACHS_CONTACT}"
      sed_temp_registry ./rsi_temp ccat.ACHSContact "${ACHS_CONTACT}"
      sed_temp_registry ./rsi_temp common.SystemType "${SYSTEM_TYPE}"
      sed_temp_registry ./rsi_temp common.SystemModel "${SYSTEM_MODEL}"
      sed_temp_registry ./rsi_temp common.SystemSerialNumber "${SERIAL_NUMBER}"
      if [ -n "$CA_INSTALLED" ]; then
         sed_temp_registry ./rsi_temp CA.ACHSContact "${ACHS_CONTACT}"
	 sed_temp_registry ./rsi_temp CA.Serial.Number "${SERIAL_NUMBER}"
      fi
      /bin/cp -p ./rsi_temp /usr/cluster/members/$MBR/usr//opt/hp/svctools/specific/desta/config/DESTA.REG
      if [ "$?" != "0" ]; then
         /bin/echo "register_system_info: failed to restore registry to $NODE"
         return
      fi
      /bin/rm -f ./rsi_temp
   fi
   /bin/echo "...done."
}

###############################################################################
# This function is only called during initialization. After the profile has been
# created the user can edit it manually. If CONSTRAINT = INIT, go through all
# nodes. If CONSTRAINT = NEW_MEMBER, work only with the new member nodes.

create_user_profile ()
{
   if [ "$CONSTRAINT" = "INIT" -o -z "$IS_CLUSTER_MEMBER" ]; then
      NODE_LIST=$MBR_NODENAMES
   elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
      NODE_LIST=$NEW_MEMBER_NODES
   else
      return
   fi

   PROFILE_CREATE=false
   /bin/cat <<EOF

The Instant Support Enterprise Edition (ISEE) profile
contains a mix of Customer and System information.
The profile may be customized using a text editor.
The path and filename is:

   $SVCTOOLS_HOME/specific/desta/config/profile.txt

Existing ISEE profiles may be recovered for use,
or they can be recreated using the Customer and
System information now on hand.

EOF

 if [ -n "$ANSWER_FILE" ]; then
    REVIEW_PROFILE=""
 else
   while true
   do
      REVIEW_PROFILE=""
      read_input "Create new profiles?" "yes/no" "yes" "PROFILE_EXISTS"

      if [ "$input" = "" ]; then
         break;
      elif [ ! -z $input ]; then
          input=`echo $input | tr [A-Z]  [a-z]`
          if [ $input = "yes" -o $input = "y" ]; then
             break;
          elif [ $input = "no" -o $input = "n" ]; then
              REVIEW_PROFILE="true"
             break;
          else
             echo "Please type yes or no"
             continue
          fi
      fi
   done
   /bin/echo ""
 fi

   for N in $NODE_LIST; do
      if [ "$N" = "$FULL_HOSTNAME" ]; then
         # the local node, or not clustered
         PROFILE_PATH=${SVCTOOLS_HOME}/specific/desta/config
         GET_PROFILE_CMD=get_registry_item
         MBR=""; NODE=$FULL_HOSTNAME
         do_the_profile_thing
#         echo "After do_the_profile_thing ...."
      else
         MBR=`/bin/egrep "${N}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
         if [ -z "$MBR" ]; then
	    /bin/echo "create_user_profile: unable to translate $N to cluster member ID"
	    continue
         else
	    PROFILE_PATH=/usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config
	    GET_PROFILE_CMD=get_remote_registry_item
	    NODE=$N
	    do_the_profile_thing
            echo "After do_the_profile_thing ...."
	 fi
      fi
   done
}

do_the_profile_thing ()
{
   if [ ! -f ${PROFILE_PATH}/profile.txt ]; then
      /bin/echo "...creating ISEE profile on $NODE"
   elif [ -n "$REVIEW_PROFILE" ]; then
      if [ -f ${PROFILE_PATH}/profile.txt ]; then
         /bin/echo "This ISEE profile already exists on $NODE:"
         /bin/echo "====================================================="
         /bin/cat ${PROFILE_PATH}/profile.txt
         /bin/echo ""
         /bin/echo "====================================================="
           if [ -z "$ANSWER_FILE" ]; then
               return
           else
             /bin/echo "This profile can be replaced using the Customer"
             /bin/echo "and System information now on hand."
             /bin/echo ""
              read_input "Replace existing SICL profile?" "yes/no" "yes" "PROFILE_EXISTS"
                 if [ "$input" = "yes" ]; then
                   /bin/echo ""
                   /bin/echo "...replacing SICL profile on $NODE"
	           /bin/rm -f ${PROFILE_PATH}/profile.txt
                 else
                    /bin/echo ""
	            return
                 fi
           fi 
        fi
   else
      /bin/echo "...creating SICL profile on $NODE"
      /bin/rm -f ${PROFILE_PATH}/profile.txt
   fi
   get_sicl_profile_info
   write_sicl_profile
   /bin/echo "...done"
   /bin/echo ""
           # echo "exiting do_the_profile_thing ...."
}

get_sicl_profile_info ()
{
    USER_COMPANY=""; COMPANY_ADDRESS_1=""; COMPANY_ADDRESS_2=""; COMPANY_ADDRESS_3=""
    USER_NAME=""; USER_EMAIL=""; USER_PHONE=""; SYSTEM_TYPE=""; SYSTEM_MODEL=""; SERIAL_NUMBER=""

    $GET_PROFILE_CMD common.UserCompany $MBR; USER_COMPANY="$GR_ITEM"
    $GET_PROFILE_CMD common.FirstCompanyAddress $MBR; COMPANY_ADDRESS_1="$GR_ITEM"
    $GET_PROFILE_CMD common.SecondCompanyAddress $MBR; COMPANY_ADDRESS_2="$GR_ITEM"
    $GET_PROFILE_CMD common.ThirdCompanyAddress $MBR; COMPANY_ADDRESS_3="$GR_ITEM"
    $GET_PROFILE_CMD common.UserName $MBR; USER_NAME="$GR_ITEM"
    $GET_PROFILE_CMD common.UserEmail $MBR; USER_EMAIL="$GR_ITEM"
    $GET_PROFILE_CMD common.UserPhone $MBR; USER_PHONE="$GR_ITEM"
    $GET_PROFILE_CMD common.SystemType $MBR; SYSTEM_TYPE="$GR_ITEM"
    $GET_PROFILE_CMD common.SystemModel $MBR; SYSTEM_MODEL="$GR_ITEM"
    $GET_PROFILE_CMD common.SystemSerialNumber $MBR; SERIAL_NUMBER="$GR_ITEM"

    # Get the IP address... lazy admins may leave it out of /etc/hosts

    HOST_IP="`/bin/grep $NODE /etc/hosts | /bin/awk '{print $1}'`"
    if [ -z "$HOST_IP" ]; then
       HOST_IP=`/bin/ping -c 1 $NODE | /bin/grep "bytes from" | /bin/cut -f 4 -d\  | /bin/cut -f 1 -d :`
       if [ -z "$HOST_IP" ]; then
          HOST_IP="UNKNOWN"
       fi
    fi
}

write_sicl_profile ()
{
    /bin/echo "Customer: ${USER_COMPANY}" > ${PROFILE_PATH}/profile.txt
    /bin/echo "Address: ${COMPANY_ADDRESS_1}" >> ${PROFILE_PATH}/profile.txt
    if [ -n "${COMPANY_ADDRESS_2}" ]; then
       /bin/echo "         ${COMPANY_ADDRESS_2}" >> ${PROFILE_PATH}/profile.txt
    fi
    if [ -n "${COMPANY_ADDRESS_3}" ]; then
       /bin/echo "         ${COMPANY_ADDRESS_3}" >> ${PROFILE_PATH}/profile.txt
    fi
    /bin/echo "Primary contact: ${USER_NAME}"  >> ${PROFILE_PATH}/profile.txt
    /bin/echo "E-mail: ${USER_EMAIL}" >> ${PROFILE_PATH}/profile.txt
    /bin/echo "Secondary contact: "  >> ${PROFILE_PATH}/profile.txt
    /bin/echo "Phone number: ${USER_PHONE}" >> ${PROFILE_PATH}/profile.txt
    /bin/echo "Special instructions: " >> ${PROFILE_PATH}/profile.txt
    /bin/echo "" >> ${PROFILE_PATH}/profile.txt
    /bin/echo "CONFIGURATION INFORMATION: " >> ${PROFILE_PATH}/profile.txt
    /bin/echo "" >> ${PROFILE_PATH}/profile.txt
    /bin/echo "   System Type: ${SYSTEM_TYPE}     Model: ${SYSTEM_MODEL}" >> ${PROFILE_PATH}/profile.txt
    /bin/echo "   System S/N: ${SERIAL_NUMBER}    System name: ${NODE}" >> ${PROFILE_PATH}/profile.txt
    /bin/echo "   System IP address: ${HOST_IP}     Fixed: (X)  DHCP served: ( ) " >> ${PROFILE_PATH}/profile.txt
    /bin/echo "" >> ${PROFILE_PATH}/profile.txt 
}

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

review_service_obligation ()
{
   # CONSTRAINT = INIT: run servob install on the local node only, then copy
   #    the Obligation object to the other nodes... including member0.
   # CONSTRAINT = NEW_MEMBER: copy the member0 Obligation object to all new nodes.
   # CONSTRAINT = null: prompt user for node(s) to work with. Cycle through all
   #    nodes to read and display info, results applied to same node.

   /bin/echo ""
   if [ "$CONSTRAINT" = "INIT" ]; then
      initialize_obligation
      return
   elif [ "$CONSTRAINT" = "NEW_MEMBER" ]; then
      new_member_obligation
      return
   else
      if [ -z "$IS_CLUSTER_MEMBER" ]; then
         NODE_LIST=$MBR_NODENAMES
      else
	 while true
	 do
	    /bin/echo "Please choose the nodes to be reviewed:"
	    get_user_node_selection $MBR_NODENAMES
	    if [ -z "$NODE_LIST" ]; then
	       return
	    elif [ "$NODE_LIST" = "?" ]; then
	       help_webes "SERVOB"
	    else
	       break
	    fi
	 done
      fi
   fi

   for NODE in $NODE_LIST; do
      SERNUM=""
      if [ "$NODE" = "$FULL_HOSTNAME" ]; then
         /bin/echo ""
	 get_registry_item common.SystemSerialNumber; SERNUM="$GR_ITEM"
	 [ -z "$SERNUM" ] && SERNUM="unknown"
	 /bin/echo "Obligation data for $FULL_HOSTNAME, serial# $SERNUM"
	 if [ -f $SVCTOOLS_HOME/specific/desta/data/Obligation ]; then
	    /bin/echo ""
	    ${SVCTOOLS_HOME}/common/bin/desta servob show
	    /bin/echo ""
	    read_input "Is the above information correct?" "yes/no" "yes" "SERVOB"
	    [ "$input" = "yes" ] && continue
	 fi 
	 ${SVCTOOLS_HOME}/common/bin/desta servob install
      else
	 MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	 if [ -z "$MBR" ]; then
	    /bin/echo "review_service_obligation: unable to translate $NODE to cluster member ID"
	    continue
	 else
	    /bin/echo ""
	    get_remote_registry_item common.SystemSerialNumber $MBR; SERNUM="$GR_ITEM"
	    [ -z "$SERNUM" ] && SERNUM="unknown"
	    /bin/echo "Obligation data for $NODE, serial# $SERNUM"
	    if [ -f /usr/cluster/members/$MBR/usr/opt/hp/svctools/desta/data/Obligation ]; then
		/bin/echo ""
		execute_on_NODE ${SVCTOOLS_HOME}/common/bin/desta servob show
		[ "$?" != "0" ] && continue
		/bin/echo ""
		read_input "Is the above information correct?" "yes/no" "yes" "SERVOB"
		[ "$input" = "yes" ] && continue
	    fi
	    execute_on_NODE ${SVCTOOLS_HOME}/common/bin/desta servob install
	 fi
      fi
   done
   /bin/echo ""
}

initialize_obligation ()
{
   # Do the Obligation thing on the local node, then copy the created Obligation 
   # object to all other cluster nodes, including member0.

   /bin/echo ""
   get_registry_item common.SystemSerialNumber; SERNUM="$GR_ITEM"
   [ -z "$SERNUM" ] && SERNUM="unknown"
   /bin/echo "Obligation data for $FULL_HOSTNAME, serial# $SERNUM"

   OBLIGNUM=""
   if [ -n "$ANSWER_FILE" ]; then
      get_answer_item SystemSerialNumber; [ $? -eq 0 ] && SERNUM="$GA_ITEM"
      get_answer_item ObligationNumber; [ $? -eq 0 ] && OBLIGNUM="$GA_ITEM"
     if [ -n "$OBLIGNUM" ]; then  
           ${SVCTOOLS_HOME}/common/bin/desta servob install $SERNUM $OBLIGNUM
     else
          ${SVCTOOLS_HOME}/common/bin/desta servob install $SERNUM
     fi
  else
          ${SVCTOOLS_HOME}/common/bin/desta servob install
  fi
  
 # Copy the created Obligation object to all other cluster nodes, including member0.
 # Mar 4,2004 do we need this code at all? 
 #  if [ -n "$IS_CLUSTER_MEMBER" ]; then
 #     /bin/echo ""
 #     /bin/echo "...copying Obligation to other cluster nodes"
 #     for M in $OTHER_MBRS_LIST; do
 #	 /bin/cp -p $SVCTOOLS_HOME/specific/desta/data/Obligation /usr/cluster/members/$M/usr/opt/hp/svctools/specific/desta/data
 #     done
 #     /bin/cp -p $SVCTOOLS_HOME/specific/desta/data/Obligation /usr/cluster/members/member0/usr/opt/hp/svctools/specific/desta/data
 #     /bin/echo "...done"
 #  fi
 # End of -- Mar 4,2004 do we need this code at all? 
}

new_member_obligation ()
{
   # Copy the member0 Obligation object to the new members. If that directory doesn't exist,
   # which it won't on a v5.0 cluster, just find it somewhere else.

   NMO_MBR=member0
   ROOT_PATH="/usr/cluster/members"
   NODE_PATH="opt/hp/svctools/specific/desta/data"

   /bin/echo ""
   for M in $NEW_MEMBER_MBRS; do
      /bin/echo "...copying Obligation object to $M"
      /bin/cp -p $ROOT_PATH/$NMO_MBR/$NODE_PATH/Obligation $ROOT_PATH/$M/$NODE_PATH
   done
   /bin/echo ""
}

###############################################################################
# These functions allow the user to start and stop WEBES on the cluster.

user_start_WEBES ()
{
   get_installed_product CA_INSTALLED ""
   get_installed_product CCAT_INSTALLED ""
   /bin/echo ""
   if [ -z "$CA_INSTALLED" -a -z "$CCAT_INSTALLED" ]; then
      /bin/echo "WEBES cannot be started - no optional components are installed"
      /bin/echo""
      return
   fi

   # It's easier to do the standalone node as a special case.

   if [ -z "$IS_CLUSTER_MEMBER" ]; then
      get_registry_item webes.startOnBoot; TEMP="$GR_ITEM"
   #   if [ "$TEMP" = "true" ]; then
         check_WEBES_running
         if [ -z "$RUNNING_NODES" ]; then
	    /bin/echo "Starting WEBES on $FULL_HOSTNAME"
	    desta_process_start EXIT_CODE
	    if [ "$EXIT_CODE" != "0" ]; then
	       /bin/echo "WEBES did not start on $FULL_HOSTNAME"
	       return
	    fi
	    WEBES_SHUTDOWN="false"
	 else
	    /bin/echo "WEBES is currently running on $FULL_HOSTNAME"
	    /bin/echo ""
	 fi
    #  else
    #     /bin/echo "WEBES is not configured to start on $FULL_HOSTNAME"
    #	 /bin/echo "Select the \"Start at Boot Time\" menu item to"
    #	 /bin/echo "configure this."
    #     /bin/echo ""
    #  fi
      # If $STOPPED_NODES shows we shutdown earlier, clear it.
      [ -n "$STOPPED_NODES" ] && STOPPED_NODES=""
      return
   fi

   # And now the cluster...

   where_can_WEBES_run

   if [ -n "$COULD_RUN_NODES" ]; then
      check_WEBES_running "ALL_NODES"
      if [ -n "$RUNNING_NODES" ]; then
	 # WEBES is running somewhere on this cluster. Build a list of nodes
         # that could still be started and replace COULD_RUN_NODES with it.
         CAN_START=""
	 for NODE in $COULD_RUN_NODES; do
	    TEMP=`/bin/echo $RUNNING_NODES | /bin/grep $NODE`
	    if [ -z "$TEMP" ]; then
	       if [ -z "$CAN_START" ]; then
	          CAN_START=$NODE
	       else
	          CAN_START="$NODE $CAN_START"
	       fi
	    fi
	 done
	 if [ -n "$CAN_START" ]; then
	    COULD_RUN_NODES=$CAN_START
	 else
	    /bin/echo ""
	    /bin/echo "WEBES is currently running on all nodes on"
	    /bin/echo "which it is configured to start at boot time."
	    /bin/echo ""
	    return
	 fi
      fi
      /bin/echo ""
      /bin/echo "WEBES can be started on these nodes:"
      display_nodes $COULD_RUN_NODES
      /bin/echo ""
      /bin/echo "On which nodes would you like to start WEBES?"
      while true
      do
         get_user_node_selection $COULD_RUN_NODES
	 if [ -z "$NODE_LIST" ]; then
	    break
	 elif [ "$NODE_LIST" = "?" ]; then
	    help_webes "StartOnBoot"
	 else
	    for NODE in $NODE_LIST
	    do
	       /bin/echo ""
	       /bin/echo "...starting on $NODE"
	       if [ "$NODE" = "$FULL_HOSTNAME" ]; then
		  desta_process_start EXIT_CODE
	       else
	          MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	          if [ -z "$MBR" ]; then
		     /bin/echo "user_start_WEBES: unable to translate $NODE to cluster member ID"
	          else
	             desta_remote_start EXIT_CODE
	          fi
	       fi
	       # If this node was stopped earlier, remove it from the list.
	       if [ -n "$STOPPED_NODES" ]; then
	          TEMP=`/bin/echo $STOPPED_NODES | /bin/grep $NODE`
		  if [ -n "$TEMP" ]; then
		     TEMP=""
		     for S in $STOPPED_NODES; do
		        if [ "$S" != "$NODE" ]; then
			   if [ -z "$TEMP" ]; then
			      TEMP=$S
			   else
			      TEMP="$S $TEMP"
			   fi
			fi
		     done
		     STOPPED_NODES=""
		     for S in $TEMP; do
		        if [ -z "$STOPPED_NODES" ]; then
			   STOPPED_NODES=$S
			else
		           STOPPED_NODES="$S $STOPPED_NODES"
			fi
		     done
		  fi
	       fi
	    done
	    break
	 fi
      done
   else
      /bin/echo ""
      /bin/echo "WEBES is not configured to start at boot time."
      /bin/echo "Select the Start at Boot Time menu item to"
      /bin/echo "configure this."
      /bin/echo ""
   fi
}

user_stop_WEBES ()
{
   /bin/echo ""
   check_WEBES_running "ALL_NODES"
   if [ -n "$RUNNING_NODES" ]; then
      if [ -z "$IS_CLUSTER_MEMBER" ]; then
         /bin/echo "Stopping WEBES on $FULL_HOSTNAME"
         desta_process_stop EXIT_CODE
      else
	 /bin/echo "WEBES is running on these nodes:"
	 display_nodes $RUNNING_NODES
	 /bin/echo ""
	 /bin/echo "On which nodes would you like to stop WEBES?"
         while true
         do
            get_user_node_selection $RUNNING_NODES
	    if [ -z "$NODE_LIST" ]; then
	       break
	    elif [ "$NODE_LIST" = "?" ]; then
	       /bin/echo ""
	       /bin/echo "The WEBES application on the selected node will be stopped"
	       /bin/echo ""
	    else
	       for NODE in $NODE_LIST
	       do
	          /bin/echo ""
		  /bin/echo "...stopping on $NODE"
	          if [ "$NODE" = "$FULL_HOSTNAME" ]; then
		     desta_process_stop EXIT_CODE
		     if [ "$EXIT_CODE" = "0" ]; then
		        WEBES_SHUTDOWN="true"
		     fi
		  else
	             MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
	             if [ -z "$MBR" ]; then
		        /bin/echo "user_stop_WEBES: unable to translate $NODE to cluster member ID"
	             else
	                desta_remote_stop EXIT_CODE
	                if [ "$EXIT_CODE" = "0" ]; then
	                   WEBES_SHUTDOWN="true"
		        fi
	             fi
		  fi
	       done
	       break
	    fi
         done	 
      fi
   else
      if [ -z "$IS_CLUSTER_MEMBER" ]; then
         /bin/echo "WEBES is not currently running on $FULL_HOSTNAME"
      else
         /bin/echo "WEBES is not currently running on the cluster."
      fi
   fi
}

# Stops WEBES on specified node if it is running. Adds to the $STOPPED_NODES list.
#
# $1 = "ALL_NODES" or a specific node name.

stop_WEBES_if_running ()
{
   # Handle standalone node as a special case.
   if [ -z "$IS_CLUSTER_MEMBER" ]; then
      WCC_RUNNING_NODES=""; WCC_RUNNING_MBRS=""
      check_for_local_WEBES
      if [ -n "$WCC_RUNNING_NODES" ]; then
         /bin/echo ""
         /bin/echo "This operation requires WEBES shutdown."
         /bin/echo "...stopping on $FULL_HOSTNAME"
         desta_process_stop EXIT_CODE
	 STOPPED_NODES="$FULL_HOSTNAME"
      fi
      return
   fi

   # Build a list of cluster nodes to stop on.

   SW_NODES=""
   case "$1" in
    ALL_NODES)
       check_WEBES_running "ALL_NODES"
       if [ -n "$RUNNING_NODES" ]; then
          for N in $RUNNING_NODES; do
	     if [ -z "$SW_NODES" ]; then
	        SW_NODES=$N
	     else
	        SW_NODES="$N $SW_NODES"
	     fi
	  done
       fi
       ;;
    $FULL_HOSTNAME)
       WCC_RUNNING_NODES=""; WCC_RUNNING_MBRS=""
       check_for_local_WEBES
       if [ -n "$WCC_RUNNING_NODES" ]; then
          SW_NODES="$FULL_HOSTNAME"
       fi
       ;;
    *)
       TEMP=`/bin/egrep "${1}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
       if [ -n "$TEMP" ]; then
          WCC_RUNNING_NODES=""; WCC_RUNNING_MBRS=""
          check_for_member_WEBES $TEMP
	  if [ -n "$WCC_RUNNING_MBRS" ]; then
	     SW_NODES="$1"
	  fi
       else
          /bin/echo "stop_WEBES_if_running: unable to translate $1 to cluster member ID"
       fi
       ;;
   esac

   [ -z "$SW_NODES" ] && return

   # Run through the list of nodes and stop the Director. If the node isn't
   # already on $STOPPED_NODES, add it to the list.

   /bin/echo ""
   /bin/echo "This operation requires WEBES shutdown."

   for N in $SW_NODES; do
       /bin/echo "...stopping on $N"
       if [ "$N" = "$FULL_HOSTNAME" ]; then
	  desta_process_stop EXIT_CODE
       else
	  WCC_RUNNING_NODES=""; WCC_RUNNING_MBRS=""
          check_for_node_WEBES $N
	  if [ -n "$WCC_RUNNING_NODES" ]; then
	     MBR=$WCC_RUNNING_MBRS; NODE=$WCC_RUNNING_NODES
	     desta_remote_stop EXIT_CODE
	  fi
       fi
       if [ -z "`/bin/echo $STOPPED_NODES | /bin/grep $N`" ]; then
          if [ -z "$STOPPED_NODES" ]; then
	     STOPPED_NODES=$N
	  else
	     STOPPED_NODES="$STOPPED_NODES $N"
	  fi
       fi
   done
}

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

read_input()
{
   [ -z "$2" ] && _prompt="$1 [ ? ]: "
   [ -n "$2" ] && _prompt="$1 [ $2 ] [ ? ]: "
   [ -n "$3" -a -z "$2" ] && _prompt="$1 [ ? ](default= $3): "
   [ -n "$3" -a -n "$2" ] && _prompt="$1 [ $2 ] [ ? ](default= $3): "
   case $_prompt in
      ??????????????????????????????????????????????????????????????????*)
         [ -z "$2" ] && _prompt="$1$newline [ ? ]: "
         [ -n "$2" ] && _prompt="$1$newline [ $2 ] [ ? ]: "
         [ -n "$3" -a -z "$2" ] && _prompt="$1$newline [ ? ](default= $3): "
         [ -n "$3" -a -n "$2" ] && _prompt="$1$newline [ $2 ] [ ? ](default= $3): "
      ;;
   esac
   while true
   do
      /bin/echo -n "$_prompt" 
      read input
      case $input in
         "")
            input=$3; return 0
            ;;
         'null')
            input=""; return 0
            ;;
         '?'|h|help)
            help_webes "$4"; continue
            ;;
         y|Y|yes)
            input="yes"; return 0
            ;;
         n|N|no)
            input="no"; return 0
            ;;
         x)
            exit 1
            ;;
         *)
            return 0
            ;;
      esac
   done
}

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

help_webes()
{
 
  case "$1" in
   thisUtility) /bin/cat<<EOF

   This script is to be executed after WEBES has been 
   installed on your system. The first time it is executed
   it automatically performs the mandatory WEBES configuration
   process. After that has been performed, this script can be
   used to install and configure the other WEBES components,
   review and modify the Customer and System information and
   the Service Obligation data.

   If any installation or configuration processes are chosen
   the WEBES Director will first be stopped (on all nodes of
   a cluster). If this is done, you will be given a chance to
   start the Director again (on all nodes of a cluster).

EOF
   ;;
   kitPath) /bin/cat<<EOF

   If you enter the location of the kit directory it will be
   retained for use in any later WEBES component installation.
   Entering the path is optional during the initial configuration
   session, but it will be REQUIRED if an optional component is
   being installed and the path is not on hand.

   Note that the kit is available on the Compaq System Tools 
   CD that ships with the Compaq TRU64 UNIX software product library.

EOF
   ;;
   mainMenu)  /bin/cat<<EOF

   This menu allows you to:

    - Install an optional component, such as Computer
       Crash Analysis Tool or System Event Analyzer.
    - Remove an optional component, such as CCAT or
       SEA.
    - Remove all of the WEBES components permanantly
       (Including the mandatory subset) in one attempt.
    - Reinstall an optional component, such as CCAT
       or SEA once they are removed. 
    - Configure the nodes on which WEBES will start
       when the system boots. At least one optional
       component must be installed for this.
    - Review:
       - customer information (name, address, e-mail)
       - system information (serial number, model, type)
       - service obligation numbers and dates.
    - Start or stop WEBES on any/all nodes.

EOF
   ;;
   InitialConfig) /bin/cat<<EOF

   ACHS Contact is used by WEBES products.  This is the e-mail
   address (format: you@yourcompany.com) of the person that the
   Automatic Call Handling System will contact after logging a
   call, in the event that a system error is detected.

   The SMTP contact is the e-mail address (e.g. you@yourcompany.com)
   of the individual that will be notified directly by e-mail in the
   event that a system error is detected.  Normally this is the root
   at the local host.
   
   The SMTP server is the host you designate as the SMTP mail server.
   Normally this is the local host.

   The Service Obligation consists of the start date and
   number of the service contract you hold on each Compaq
   computer you own. Enter the computer's purchase date
   and service contract number (usually the same as the
   computer's serial number). WEBES will remind you when
   the Service Obligation is about to expire.

EOF
   ;;
   StartOnBoot) /bin/cat<<EOF

   The WEBES Director can be configured to start when the
   system boots. It will run in Automatic Analysis mode,
   as a detached process, receiving reports of any events
   that may occur as the system runs. The events will be
   analyzed and, if errors are detected, notification will
   be sent to the system administrator and the ACHS contact.

EOF
   ;;

   chooseClusterNode) /bin/cat<<EOF

   Choose menu item 1 to effect only the local node, or menu item 
   2 to effect all candidate cluster nodes. Choose item 3 to enter
   a list of cluster nodenames - you'll then be able to enter "?"
   to get a list of the candidate nodes, if desired.

EOF
   ;;

   ACHSContact) /bin/cat<<EOF

   ACHS Contact is used by WEBES products.  This is the e-mail
   address (format: you@yourcompany.com) of the person that the
   Automatic Call Handling System will contact after logging a
   call, in the event that a system error is detected.

EOF
  ;;

  ReviewSysInfo) /bin/cat<<EOF

  The system type, model and serial number are included in
  e-mail notifications sent to the system administrator and
  the Automated Call Handling System in the event an error
  is detected on your system.

EOF
  if [ -n "$IS_CLUSTER_MEMBER" ]; then
     /bin/cat<<EOF
  The system information will be retrieved from each cluster
  member and displayed. You will be able to edit the information
  and have it effect only the specified cluster member.

EOF
  fi
  ;;

  SystemSerialNumber) /bin/cat<<EOF

  The system serial number is included in e-mail notifications
  sent to the system administrator and the Automated Call Handling
  System in the event an error is detected on your system.
     
EOF
  ;;

  SystemType) /bin/cat<<EOF

  The system type is included in e-mail notifications sent
  to the system administrator and the Automated Call Handling
  System in the event an error is detected on your system.
     
EOF
  ;;

  SystemModel) /bin/cat<<EOF

  The system model is included in e-mail notifications sent
  to the system administrator and the Automated Call Handling
  System in the event an error is detected on your system.
     
EOF
   ;;

   CLUSTERAPPLY) /bin/cat<<EOF

   When WEBES is installed on a cluster, most of the files
   used by the products are shared between the nodes of the
   cluster. You may tailor the configuration data on any
   of the cluster nodes by entering the name of the node.

EOF
   ;; 

   review_cust_info) /bin/cat<<EOF

   The customer information is used in e-mail notifications
   sent to the system administrator in the event an error 
   is detected on your system. It includes the company name
   and address, and the name, phone number and e-mail address
   of a point of contact at your company.

EOF
   ;;
   COMPANYADDRESSINPUT) /bin/cat<<EOF

   The company's address for the profile.txt file entry. 
   Please note that you will be presented with three fields 
   in which you can enter any value. The fields, of course,
   were intended to allow a line for the street address and 
   two more lines for any other pertinent address information.
     
EOF
   ;;
   COMPANYINPUT) /bin/cat<<EOF

   The local company's name

EOF
   ;;
   EMAILINPUT) /bin/cat<<EOF

   The email address of the person to contact when a system 
   error is detected.

EOF
   ;;
   INFOCORRECT) /bin/cat<<EOF

   Answer yes if the information is correct.

EOF
   ;;
   NAMEINPUT) /bin/cat<<EOF

   The name of the person to contact when a system error 
   is detected.

EOF
   ;;
   PHONEINPUT) /bin/cat<<EOF

   The local phone number of the person to contact when a 
   system error is detected. Enter this as a dash-separated
   number, e.g., 123-456-7890. DO NOT use parentheses, (123),
   or this script will generate an error!

EOF
   ;;
   PINGNOTOK) /bin/cat << EOF
   
   The Transmission Control Protocol/InternetProtocol (TCP/IP) 
   is required for System Event Analyzer to function. You may abort 
   this installation by answering no and allowing the program
   to exit. If you answer yes and intend to install System Event
   Analyzer, then ensure the TCP/IP protocol is installed
   on this host.

EOF
   ;;
   PROFILE_EXISTS) /bin/cat<<EOF

   System Event Analyzer, one of the Web-Based Enterprise Service 
   Suite products, uses a customer profile text file to 
   store information, such as point-of-contact names and 
   phone numbers, used in System Initiated Call Logging. 

   This file can be created during WEBES installation, or 
   can be created by System Event Analyzer when it is executed. 
   If WEBES is deinstalled the file can be saved for use 
   in a later re-installation.

EOF
   ;;
   SMTPContact) /bin/cat<<EOF

   Used by WEBES products.  Ths is the e-mail address 
   (e.g. you@yourcompany.com) of the individual that will 
   be notified directly by e-mail in the event that a 
   system error is detected.  Normally this is the root at 
   the local host.

EOF
   ;;
   SMTPServer) /bin/cat<<EOF

   Used by the Computer Crash Analysis Tool.  This is the host 
   you designate as the SMTP mail server.  Normally this is 
   the local host.

EOF
   ;;
   KRS_DELETE) /bin/cat<<EOF

   The Computer Crash Analysis Tool comes with knowledge rule
   files (KRS) for all Tru64UNIX operation systems. If you 
   select to keep only the knowledge rule files for this 
   machine's operating system version then the other knowledge
   rules files will be removed.

EOF
   ;;
   SERVOB) /bin/cat<<EOF

   The Service Obligation consists of the start date and
   number of the service contract you hold on each Compaq
   computer you own. Enter the computer's purchase date
   and service contract number (usually the same as the
   computer's serial number). WEBES will remind you when
   the Service Obligation is about to expire.

EOF
   ;;

   NotifyTypes) /bin/cat<<EOF

   Both notification methods allow WEBES to automatically log
   calls with your service provider.

   System-Initiated Call Logging (SICL) requires a supported
   version of DSNLink installed on the same system as WEBES.

   Customer Service Gateway (CSG) notification, formerly known
   as QSAP, requires a CSG node somewhere in your enterprise.

   You can select NONE now, but enabling SICL or CSG notification
   later will require you to execute the "ca sicl on" or "desta
   qsap on" commands later (on every node of a cluster).
 
EOF
   ;;
   CSG_setup) /bin/cat<<EOF

   Enabling CSG notification requires a CSG node somewhere in 
   your enterprise. 

   If you don't know the nodename you can simply hit <Return> to
   leave the notification method unselected. But enabling SICL or
   CSG notification later will require you to execute the "ca sicl on"
   or "desta qsap on" command (on every node of a cluster).

   The port number for CSG v4.5 and v5.0 is 2069, and for CSG v3.1 
   and v3.1B it is 8941.

EOF
   ;;
   esac
}


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

ping_test ()
{
   PING_OK="no"
   /bin/ping -c1 localhost >/dev/null
   if [ "$?" = "0" ]; then
     PING_OK="yes"
   fi
   if [ -n "${PING_OK}" ]; then
     /bin/ping -c1 ${FULL_HOSTNAME} >/dev/null
     if [ "$?" = "0" ]; then
	PING_OK="yes"
     else
        PING_OK="no"
     fi
   fi
   if [ "${PING_OK}" != "yes" ]; then 
     /bin/cat<<EOPING

The Transmission Control Protocol/Internet Protocol (TCP/IP) 
may not be installed or correctly configured on ${HOSTNAME}.
The WEBES products will not function correctly without the 
Internet Protocol program installed and properly configured.

EOPING
   fi
}

######################################################################
# Make sure WEBES is installed, and is of the correct version. This 
# code generates null strings for $INSTALLEDVER and $INSTALLEDDOTVER
# if the installation is current. If the installation is invalid, the
# script exits.

verify_WEBES_installed ()
{
   INSTALLED=""
   INSTALLEDVER=""
   INSTALLEDDOTVER=""


   PKG=`rpm -aq|grep ^WEBESBASE`
 if [ "$PKG" != "" ]; then
    INSTALLED="true"
    INSTALLEDVER="`echo $PKG 2> /dev/null | /bin/cut -f2,3 -d "-" | cut -c1,3,5 | /bin/sed -n 's/\([0-9]\)\([0-9]\)\([0-9]\)/\1.\2.\3/p'`"
    INSTALLEDDOTVER="`echo $PKG 2> /dev/null | /bin/cut -f2,3 -d "-" | cut -c1,3,5 | /bin/sed -n 's/\([0-9]\)\([0-9]\)\([0-9]\)/\1.\2-\3/p'`"
#    INSTALLEDVER="`echo $INSTALLEDVER*100 | bc -l |/bin/cut -f1 -d "."`"
#    INSTALLEDDOTVER="`echo $PKG 2> /dev/null | /bin/cut -f2 -d "-"`"
    if [ -n "${INSTALLED}" ]; then
    if [ "${INSTALLEDVER}" == "${WEBESDOTVER}" ]; then
      #installation is current 
      return
   fi

      if [ "${INSTALLEDVER}" < "${WEBESDOTVER}" ]; then
                 /bin/cat <<EOF
 
An older version of the Web-Based Enterprise Service Suite (${INSTALLEDDOTVER})
is currently installed. That version must be deinstalled and replaced
with version ${WEBESDOTVER} before this procedure can be executed.

EOF
	exit 1
      fi
    fi
      if [ -n "${INSTALLEDVER}" ]; then
	/bin/cat <<EOF

A newer version of the Web-Based Enterprise Service Suite (${INSTALLEDDOTVER})
is currently installed. This procedure shipped with version ${WEBESDOTVER}
and is not compatible.

EOF
	exit 1
      fi
  else
      /bin/cat <<EOF

The Web-Based Enterprise Service Suite ${PREFIX}${WEBESDOTVER} must
be installed before this procedure can be executed.

EOF
      exit 1
  fi

# Check for one of the common directories, just to be sure.

  if [ ! -d $SVCTOOLS_HOME ]; then
    /bin/cat <<EOF

    The Web-Based Enterprise Service Suite ${PREFIX}${WEBESDOTVER} must
    be installed before this procedure can be executed.

EOF
    exit 1
  fi
}

######################################################################
# Displays a dialog from which the user creates a list of cluster nodes. Use it
# for determining which node(s) to configure, etc. Exports $NODE_LIST which will
# be null, a (possibly single-item) list of cluster member nodenames including
# the current node but not the member0 node, or "?" if the 'Help' item was selected.
#
# $1 = candidate nodes. Set to $MBR_NODENAMES or a subset list.

get_user_node_selection ()
{
   while true
   do
      GITEM=1
      NODE_LIST=""
      G_CURRENT=""; G_ALL=""; G_SELECTED=""; G_HELP=""; G_RETURN=""

      /bin/echo ""
      valid=`/bin/echo $* | /bin/grep $FULL_HOSTNAME`
      if [ -n "$valid" ]; then
         /bin/echo " $GITEM) Current node only ($FULL_HOSTNAME)."
	 G_CURRENT=$GITEM; GITEM=`expr $GITEM + 1`
      fi
      /bin/echo " $GITEM) All $# candidate nodes."; G_ALL=$GITEM; GITEM=`expr $GITEM + 1`
      /bin/echo " $GITEM) Selected nodes."; G_SELECTED=$GITEM; GITEM=`expr $GITEM + 1`
      /bin/echo " $GITEM) Help."; G_HELP=$GITEM; GITEM=`expr $GITEM + 1`
      /bin/echo " $GITEM) Return."; G_RETURN=$GITEM; GITEM=`expr $GITEM + 1`
      /bin/echo ""
      read_input "Choose from the above:" "" "" "chooseClusterNode"
      CHOICE="$input"

      if [ "$CHOICE" = "$G_CURRENT" ]; then
           NODE_LIST=$FULL_HOSTNAME
	   return
      elif [ "$CHOICE" = "$G_ALL" ]; then
           NODE_LIST=$*
	   return
      elif [ "$CHOICE" = "$G_HELP" ]; then
           NODE_LIST="?"
	   return
      elif [ "$CHOICE" = "$G_RETURN" ]; then
           NODE_LIST=""
	   return
      elif [ "$CHOICE" = "$G_SELECTED" ]; then
           /bin/echo ""
	   /bin/echo "Enter a list of nodenames [? to see list of names]: \c"
	   read CHOICE
	   if [ "$CHOICE" = "?" ]; then
	      /bin/echo ""
	      /bin/echo "The candidate cluster members are:"
	      display_nodes $*
	   else
	      # Rebuild the list, since user may enter duplicates or abbreviated names.
	      NODE_LIST=""
	      for UNODE in $CHOICE
	      do
		 already=`/bin/echo $NODE_LIST | /bin/grep $UNODE`
		 [ -n "$already" ] && continue                # don't allow duplicates

		 valid=`/bin/echo $* | /bin/grep $UNODE`    # catch invalid entries, can't
		 if [ -z "$valid" ]; then                     # recover gracefully, so just bail
		    /bin/echo ""
		    /bin/echo "$UNODE is not a valid choice"
		    NODE_LIST=""
		    return
		 fi

		 for N in $*; do                           # loop through the known nodes
		    TEMP=`/bin/echo $N | /bin/grep $UNODE`           # does short name appear in any long name?
		    if [ -n "$TEMP" ]; then
		       if [ -z "$NODE_LIST" ]; then
		          NODE_LIST=$N
		       else
		          NODE_LIST="$N $NODE_LIST"
		       fi
		       break
		    fi
		 done
	      done
	      if [ -z "$NODE_LIST" ]; then
	         /bin/echo ""
		 /bin/echo "No nodes were selected"
		 continue
	      fi
	      /bin/echo ""
	      /bin/echo "The following nodes were selected:"
	      display_nodes $NODE_LIST
	      /bin/echo ""
	      read_input "Is this list correct?" "yes/no" "yes" "INFOCORRECT"
	      if [ "$input" = "yes" ]; then
		 return
	      fi
	   fi
      else
         /bin/echo ""
	 /bin/echo "$CHOICE is not a valid selection"
      fi
   done
}

# displays 3 nodenames per line. $1 is the list of nodenames to display.

display_nodes ()
{
  /bin/echo ""
  on_line=0
  line_list=""
  for n in $*; do
    if [ $on_line -lt 3 ]; then
       if [ -z "$line_list" ]; then
	  line_list=$n
       else
	  line_list="$line_list   $n"
       fi
       on_line=`expr $on_line + 1`
    else
       /bin/echo "   $line_list"
       line_list=$n
       on_line=1
    fi
  done
  [ -n "$line_list" ] && /bin/echo "   $line_list"   
}

get_kit_path ()
{
    get_registry_item kit.path; KIT_PATH="$GR_ITEM"

    export KIT_PATH

    # [ "$KIT_PATH" != "NOT_KNOWN" ] && return

     if [ "$KIT_PATH" != "NOT_KNOWN" -a "$KIT_PATH" != "" ]; then
        found=`ls $KIT_PATH/*${WEBESRPM}*.rpm`
	if [ -z "$found" ]; then
	    echo ""
	    echo "rpm file not found in ${KIT_PATH}"
        else
           return
        fi
    fi

    # KIT_PATH is null or NOT_KNOWN
    while true
    do
	echo ""
	echo "Please enter the directory path where the kit (.rpm file ) is present"
	echo "e.g., /home/usr/kits/*.rpm."
	echo ""
	if [ "$1" = "MUST_HAVE" ]; then
	    read_input "Path: " "" "" "kitPath"
	else
	    read_input "Path (OPTIONAL): " "" "" "kitPath"
	fi
	if [ -z "$input" ]
	then
	    [ "$1" != "MUST_HAVE" ] && return
            echo "kit path is null" 
	    echo ""
	    continue
	fi
	KIT_PATH="$input"
#	found=`ls $KIT_PATH/*${WEBESVER}*.rpm`
	found=`ls $KIT_PATH/*${WEBESRPM}*.rpm`
	if [ -z "$found" ]; then
	    echo ""
	    echo "rpm file not found in ${KIT_PATH}"
	    continue
	fi
	break
    done

    NODE_LIST=$MBR_NODENAMES

    echo "Node list:" $NOD_LIST
    for NODE in $NODE_LIST
    do
        /bin/echo ""
        /bin/echo "...updating the registry on $NODE"
        if [ "$NODE" = "$FULL_HOSTNAME" ]; then
              sed_registry_file kit.path "$KIT_PATH"
        else
	      MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
              if [ -z "$MBR" ]; then
                /bin/echo "unable to translate $NODE to cluster member ID"
                continue
              else
		/bin/cp -p /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG ./rui_temp
                if [ "$?" != "0" ]; then
                   /bin/echo "failed to retrieve registry fom $NODE"
                fi
                sed_temp_registry ./rui_temp  kit.path "$KIT_PATH"
	        /bin/cp -p ./rui_temp /usr/cluster/members/$MBR/usr/opt/hp/svctools/specific/desta/config/DESTA.REG
                if [ "$?" != "0" ]; then
                   /bin/echo "failed to restore registry to $NODE"
                fi
              fi
         fi
    done
    /bin/rm -f ./rui_temp
}

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

get_new_members ()
{
   NUM_NEW_MEMBERS=0
   NEW_MEMBER_MBRS=""
   NEW_MEMBER_NODES=""

   for LINE in `/bin/grep "=" $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState`
   do
      MBR=`/bin/echo $LINE | /usr/bin/cut -f 1 -d=`
      [ "$MBR" = "system.state" ] && continue
      [ "$MBR" = "member0" ] && continue
      [ "$MBR" = "ca.configure" ] && continue
      [ "$MBR" = "ccat.configure" ] && continue
      NUM_NEW_MEMBERS=`expr $NUM_NEW_MEMBERS + 1`

      if [ -z "$NEW_MEMBER_MBRS" ]; then
         NEW_MEMBER_MBRS=$MBR
      else
         NEW_MEMBER_MBRS="$MBR $NEW_MEMBER_MBRS"
      fi
      NODE=`/bin/grep "${MBR}=" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 2 -d=`
      if [ -z "$NODE" ]; then
	 /bin/echo ""
	 /bin/echo "initial_service_obligation: unable to translate memberID to nodename"
	 /bin/echo ""
	 continue
      else
         if [ -z "$NEW_MEMBER_NODES" ]; then
	    NEW_MEMBER_NODES=$NODE
	 else
	    NEW_MEMBER_NODES="$NODE $NEW_MEMBER_NODES"
	 fi
      fi
   done

   # Clear the new members from the SystemState file.

   for MBR in $NEW_MEMBER_MBRS; do
      sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState $MBR
   done
}

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

display_welcome_banner ()
{
  /bin/cat <<EOF

Welcome to the Web-Based Enterprise Service Suite ${PREFIX}${WEBESDOTVER}
Installation Update Utility.

During this procedure, the prompts to some questions are mapped as follows :

  Text of question? [ Some_Options ] [ ? ] (default= ans):

       (Enter or Return) accepts the default answer
       (?) shows mini help file and continues

If you are not fully familiar with the configuration procedure for WEBES
and its components, please refer to the Installation Guide before you proceed.

EOF

}

######################################################################
# This function displays a dynamic menu, i.e., the options displayed 
# are effected by the current configuration. So, the item numbers the
# user can choose from will vary. Each presented item must also have
# a variable, MM_* defined at the top of this script, that is set to 
# $MENU_ITEM so that they can be compared in the main_menu_UI_loop 
# function.

display_main_menu ()
{
    /bin/echo ""
    /bin/echo "Please choose from the following:"
    /bin/echo ""

    # Initialize the selection variables.

    MENU_ITEM=1
    MM_INSTALL_CA=""; MM_INSTALL_CCAT=""
    MM_REMOVE_CA="";  MM_REMOVE_CCAT=""; 
    MM_REMOVE_WEBES="";
    MM_CFG_STARTUP=""; MM_CUST_INFO=""; MM_SERVOB=""
    MM_SYS_INFO=""; MM_HELP=""; MM_QUIT=""; MM_START_WEBES=""
    MM_STOP_WEBES=""

    get_installed_product CA_INSTALLED ""
    get_installed_product CCAT_INSTALLED ""

    if [ -z "${CA_INSTALLED}" -o -z "${CCAT_INSTALLED}" ]; then
       if [ -z "${CA_INSTALLED}" ]; then
	  /bin/echo " ${MENU_ITEM}) Install System Event Analyzer ${PREFIX}${CADOTVER}"
	  MM_INSTALL_CA=$MENU_ITEM
          MENU_ITEM=`expr $MENU_ITEM + 1`
       fi
       if [ -z "${CCAT_INSTALLED}" ]; then
          /bin/echo " ${MENU_ITEM}) Install Computer Crash Analysis Tool ${PREFIX}${CCATDOTVER}"
	  MM_INSTALL_CCAT=$MENU_ITEM
         MENU_ITEM=`expr $MENU_ITEM + 1`
       fi
    fi

    if [ -n "${CA_INSTALLED}" -o -n "${CCAT_INSTALLED}" ]; then
       if [ -n "${CA_INSTALLED}" ]; then
	  /bin/echo " ${MENU_ITEM}) Remove System Event Analyzer ${PREFIX}${CADOTVER}"
	  MM_REMOVE_CA=$MENU_ITEM
          MENU_ITEM=`expr $MENU_ITEM + 1`
       fi
       if [ -n "${CCAT_INSTALLED}" ]; then
          /bin/echo " ${MENU_ITEM}) Remove Computer Crash Analysis Tool ${PREFIX}${CCATDOTVER}"
	  MM_REMOVE_CCAT=$MENU_ITEM
          MENU_ITEM=`expr $MENU_ITEM + 1`
       fi
    fi

    /bin/echo " ${MENU_ITEM}) Remove all of Web-Based Enterprise Service Suite"
    MM_REMOVE_WEBES=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Start at Boot Time"
    MM_CFG_STARTUP=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Customer Information"
    MM_CUST_INFO=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) System Information"
    MM_SYS_INFO=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Service Obligation"
    MM_SERVOB=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Start WEBES Director"
    MM_START_WEBES=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Stop WEBES Director"
    MM_STOP_WEBES=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Help"
    MM_HELP=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`

    /bin/echo " ${MENU_ITEM}) Quit"
    MM_QUIT=$MENU_ITEM
    MENU_ITEM=`expr $MENU_ITEM + 1`
}

######################################################################
# This function reads the user's menu selection number, and matches
# it to what was presented in the menu. If a valid selection was
# made, the value of $NEXT is set.

read_main_menu_input ()
{
 if [ -z "$UNINSTALL_SILENT" ]; then
    read_input "Choice: " "" "" "mainMenu"
    if [ -z "$input" ]; then
       /bin/echo ""
       /bin/echo "No selection was made."
       NEXT="DISPLAY_MENU"
    elif [ $input -lt 1 -o $input -ge $MENU_ITEM ]; then
       /bin/echo ""
       /bin/echo "$input is not a valid selection."
       NEXT="DISPLAY_MENU"
    elif [ "$input" = "$MM_INSTALL_CA" ]; then
       NEXT="INSTALL_CA"
    elif [ "$input" = "$MM_INSTALL_CCAT" ]; then
       NEXT="INSTALL_CCAT"
    elif [ "$input" = "$MM_REMOVE_CA" ]; then
       NEXT="REMOVE_CA"
    elif [ "$input" = "$MM_REMOVE_CCAT" ]; then
       NEXT="REMOVE_CCAT"
    elif [ "$input" = "$MM_REMOVE_WEBES" ]; then
       NEXT="REMOVE_WEBES"
    elif [ "$input" = "$MM_CFG_STARTUP" ]; then
       NEXT="CFG_STARTUP"
    elif [ "$input" = "$MM_CUST_INFO" ]; then
       NEXT="CUST_INFO"
    elif [ "$input" = "$MM_SERVOB" ]; then
       NEXT="SERVOB"
    elif [ "$input" = "$MM_SYS_INFO" ]; then
       NEXT="SYS_INFO"
    elif [ "$input" = "$MM_START_WEBES" ]; then
       NEXT="START_WEBES"
    elif [ "$input" = "$MM_STOP_WEBES" ]; then
       NEXT="STOP_WEBES"
    elif [ "$input" = "$MM_HELP" ]; then
       NEXT="HELP"
    elif [ "$input" = "$MM_QUIT" ]; then
       NEXT="QUIT"
    else
       /bin/echo ""
       /bin/echo "$input is not a valid selection."
       NEXT="DISPLAY_MENU"
    fi
 else
    /bin/echo "...Silent Uninstallation is in progress"
    NEXT="REMOVE_WEBES"
 fi
}

######################################################################
# The user input loop - this is a state machine that performs an action
# based on the value of $NEXT. Functions called from this loop can set
# $NEXT to control the next operation of the menu. 
#
# Depending on the operation, the Director may or may not need to be
# running.

main_menu_UI_loop ()
{
  while true
  do

    case "$NEXT" in

      DISPLAY_MENU)
        if [  -z "$UNINSTALL_SILENT" ]; then
           display_main_menu
        fi
	NEXT="READ_INPUT"
	;;
      READ_INPUT)
	read_main_menu_input    # NEXT is set in read_main_menu_input
	;;
      INSTALL_CA)
	CONSTRAINT="INIT"
	install_CA
	if [ "$?" = "0" ]; then
	   NEXT="CONFIGURE_CA"
	else
	   NEXT="DISPLAY_MENU"
	fi
	;;
      INSTALL_CCAT)
	CONSTRAINT="INIT"
         install_CCAT
        if [ "$?" = "0" ]; then
	   NEXT="CONFIGURE_CCAT"
	else
	   NEXT="DISPLAY_MENU"
	fi
	;;
      CONFIGURE_WEBES)
        # The Director should not be running.
	configure_webes
        /bin/echo ""
        /bin/echo "Initial configuration is complete"
	/bin/echo ""
	sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState system.state "CONFIGURED"
	get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ca.configure
	if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
	   NEXT="CONFIGURE_CA"
	else
	    get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ccat.configure
	    if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
		NEXT="CONFIGURE_CCAT"
	    else
		CONSTRAINT=""
		NEXT="DISPLAY_MENU"
	    fi
	fi
	;;
      CONFIGURE_NEW_MBRS)
        stop_WEBES_if_running "ALL_NODES"
	configure_newbies
	sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState system.state "CONFIGURED"
	/bin/echo ""
	/bin/echo "New member configuration is complete"
	/bin/echo ""
	CONSTRAINT=""
	NEXT="DISPLAY_MENU"
	;;
      CONFIGURE_CA)
        # The Director has been stopped already
	configure_CA
	if [ ! -e /etc/rc.d/rc3.d/S89desta ]; then
	   /bin/echo ""
	   /bin/echo "WEBES can now be configured to start at boot time."
	   configure_startOnBoot
	fi
	/bin/echo ""
	/bin/echo "System Event Analyzer installation is complete"
	/bin/echo ""
	sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ca.configure "CONFIGURED"
	get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ccat.configure;
	if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
	   NEXT="CONFIGURE_CCAT"
	else	
	    CONSTRAINT=""
	    NEXT="DISPLAY_MENU"
	fi
	;;
      CONFIGURE_CCAT)
	# The Director has been stopped already.
	configure_CCAT
	if [ ! -e /etc/rc.d/rc3.d/S89desta ]; then
	   /bin/echo ""
	   /bin/echo "WEBES can now be configured to start at boot time."
	   configure_startOnBoot
	fi
	/bin/echo ""
	/bin/echo "CCAT installation is complete"
	/bin/echo ""
	sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ccat.configure "CONFIGURED"
	CONSTRAINT=""
	NEXT="DISPLAY_MENU"
	;;
      REMOVE_CA)
        stop_WEBES_if_running "ALL_NODES"
	remove_CA
	remove_startOnBoot
	NEXT="DISPLAY_MENU"
	;;
      REMOVE_CCAT)
        stop_WEBES_if_running "ALL_NODES"
	remove_CCAT
	remove_startOnBoot
	NEXT="DISPLAY_MENU"
	;;
      REMOVE_WEBES)
	remove_all_WEBES
	NEXT="DISPLAY_MENU"
	;;
      CFG_STARTUP)
        configure_startOnBoot
	NEXT="DISPLAY_MENU"
	;;
      CUST_INFO)
        review_customer_info
	NEXT="DISPLAY_MENU"
	;;
      SERVOB)
	review_service_obligation
	NEXT="DISPLAY_MENU"
	;;
      SYS_INFO)
        review_system_info
        NEXT="DISPLAY_MENU"
	;;
      START_WEBES)
        user_start_WEBES
        NEXT="DISPLAY_MENU"
	;;
      STOP_WEBES)
        user_stop_WEBES
        NEXT="DISPLAY_MENU"
	;;
      HELP)
        help_webes thisUtility
	NEXT="DISPLAY_MENU"
	;;
      QUIT)
        return
        ;;
      *)
        NEXT="DISPLAY_MENU"
        ;;
    esac

  done
}

#############################################################################################
# Process the answer file, prior to a "desta start" during the initial configuration.
##############################################################################################
process_answerFile ()
{
  configure_webes
  sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState system.state "CONFIGURED"

  get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ca.configure
  if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
     configure_CA
     sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ca.configure "CONFIGURED"
  fi

  get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ccat.configure
  if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
     configure_CCAT
     sed_temp_registry $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ccat.configure "CONFIGURED"
  fi

  if [ ! -e /etc/rc.d/rc3.d/S89desta ]; then
    configure_startOnBoot
  fi 
}

######################################################################
#
# A subroutine to excute the wsea test nos command to ensure the test
# SMTP mail is sent for the configured information of SMTP details.
#
######################################################################
execute_wsea_test_command()
{
   # Fix for PTR 91-22-1482
   if [ -n "$CA_INSTALLED" -a -n "$CA_CONFIGURED" ]; then
      if [ "$EXIT_CODE"  = "0" ]; then
            get_registry_item common.SMTPContact; SMTP_TEMP="$GR_ITEM"
            get_registry_item common.SMTPServer; SMTP_SERVER_TEMP="$GR_ITEM"
            if [ "$SMTP_TEMP" != "" -a "$SMTP_SERVER_TEMP" != "" ]; then
               /usr/sbin/wsea test 1> ${SVCTOOLS_HOME}/common/bin/temp.txt 2> ${SVCTOOLS_HOME}/common/bin/temp.err
               /bin/echo "An SEA test SMTP email has been sent to the SMTP Contact Email address configured on "$NODE" "
               /bin/echo "If there is no email received from SEA, then please check your SMTP configurations."
            fi
       
            if [ -f ${SVCTOOLS_HOME}/common/bin/temp.txt ]; then
               /bin/rm -f ${SVCTOOLS_HOME}/common/bin/temp.txt
            fi

            if [ -f ${SVCTOOLS_HOME}/common/bin/temp.err ]; then
               /bin/rm -f ${SVCTOOLS_HOME}/common/bin/temp.err
            fi
      fi
   fi
  # Fix for PTR 91-22-1482
}

######################################################################
#
# START OF SCRIPT EXECUTION
#
######################################################################
# Other scripts may use this program's subroutines. If we're invoked with
# the parameter, "batch", just return. This makes exposes all symbols
# without executing anything EXCEPT the variable definitions at the top
# of the file.

  [ $# = 1 -a "$1" = "batch" ] && return
  [ "$from_script" = "TRUE" ]  && return

# Do the permissions check and include the utilities script.

  WHO=`/usr/bin/whoami`
  WHO=`echo $WHO|cut -f1 -d " "`
  if [ "$WHO" != "root" ]; then
     /bin/echo ""
     /bin/echo "Permission denied. Script may only be executed by root "
     /bin/echo ""
     exit 1
  fi

  USER_DIR=`/bin/pwd`
  cd $SVCTOOLS_HOME

  #if [ -f common/install/wcc_install_${VERSION}.sh ]; then
  #   . $SVCTOOLS_HOME/common/install/wcc_install_${VERSION}.sh
  if [ -f common/install/wcc_install_${WEBESVER}.sh ]; then
     . $SVCTOOLS_HOME/common/install/wcc_install_${WEBESVER}.sh
  else
     /bin/echo ""
#     /bin/echo "Failed to find required file: $SVCTOOLS_HOME/common/install/wcc_install_${VERSION}.sh"
     /bin/echo "Failed to find required file: $SVCTOOLS_HOME/common/install/wcc_install_${WEBESVER}.sh"
     /bin/echo ""
     exit 1
  fi

# Silent installation - Get the answer file name from the CL and check for its existence.
 ANSWER_FILE=""
  
 if [ $# = 2 -a "$1" = "-a" ]; then
   /bin/echo ""
   ANSWER_FILE=$2
#   if [ -f $ANSWER_FILE ]; then
   if [ -n $ANSWER_FILE  -a  -f $ANSWER_FILE ]; then
      /bin/echo "Installing using answer file ${ANSWER_FILE}."
   else
     /bin/echo "Unable to find answer file: ${ANSWER_FILE} "
     /bin/echo ""
     ANSWER_FILE=""
  fi
  export ANSWER_FILE
fi

# Give the user something to read while we collect data.

  display_welcome_banner

  verify_WEBES_installed

# Fix for bug 3639 -Vijayant

  NOTIFY_TYPES=""
  VAL=""

  NOTIFY_REG_VALUE=`/bin/grep "notification.Type" ${SVCTOOLS_HOME}/specific/desta/config/DESTA.REG | /bin/cut -f 2 -d=` 	
  VAL=`/bin/echo $NOTIFY_REG_VALUE | /bin/grep ISEE`
#  /bin/echo "Getting the Value from notification.Type" 	

  get_installed_product WCC_INSTALLED getdots
  get_installed_product CA_INSTALLED getdots
  get_installed_product CCAT_INSTALLED getdots

  if [ -n "${WCC_INSTALLED}" -o -n "${CA_INSTALLED}" -o -n "${CCAT_INSTALLED}" ]
  then
     /bin/echo "The following Web-Based Enterprise Service Suite"
     /bin/echo "components are currently installed:"
     /bin/echo ""
     [ -n "${WCC_INSTALLED}" ] && /bin/echo "  WEBES Common Components ${PREFIX}${CADOTVER}"
     [ -n "${CA_INSTALLED}" ] && /bin/echo "  System Event Analyzer ${PREFIX}${CADOTVER}"
     [ -n "${CCAT_INSTALLED}" ] && /bin/echo "  Computer Crash Analysis Tool ${PREFIX}${CCATDOTVER}"
     /bin/echo ""

     if [ $# = 1 -a "$1" = "-u" ]; then
        UNINSTALL_SILENT="TRUE"
        export UNINSTALL_SILENT
       /bin/echo ""
       /bin/echo " The installed products shown above will be removed."
       /bin/echo ""
        CONSTRAINT=""
        NEXT="DISPLAY_MENU"
     fi
  fi

  UPDATE_LOG="specific/webes/logs/webes_config.log"; export UPDATE_LOG

# Gather up the pertinent data. All called functions can assume they have
# $HOSTNAME, $*_INSTALLED, $MY_MEMBER_ID (may be null) and:
#
# $MY_MEMBER_ID - captured at install time, retrieved from the registry. On
#     standalone systems this is set to "member0" so utility functions can
#     work with it.
#
# $OTHER_MBRS_LIST - a list of member IDs, e.g., member20, member21, &c., that 
#     does NOT include member0 or the current member. If we're not on a cluster
#     this consists only of $MY_MEMBER_ID.
#
# $MBR_NODENAMES - a list of hostnames derived from the $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes
#     file that includes the current node but not the member0 node. If we're not on
#     a cluster, this consists only of $HOSTNAME.
#
# $NODE_LIST - ONLY if get_user_node_selection is called. A list of hostnames
#     that may include the current node.
#
# $NEW_MEMBER_MBRS and $NEW_MEMBER_NODES - list of newly added cluster nodes, as member
#     IDs and as node names.

  get_hostnames

  MY_MEMBER_ID=""
  get_registry_item common.ClusterID; MY_MEMBER_ID="$GR_ITEM"

  SYSTEM_STATE=""
  get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState system.state; SYSTEM_STATE="$GR_ITEM"

  isClusterMember

  if [ -n "$IS_CLUSTER_MEMBER" ]; then
     get_other_cluster_members
     get_cluster_hostnames
  else
     MY_MEMBER_ID="member0"
     MBR_NODENAMES=$FULL_HOSTNAME
     OTHER_MBRS_LIST=""
     NEW_MEMBER_MBRS=""
     NEW_MEMBER_NODES=""
     NUM_NEW_MEMBERS=0
  fi

  WEBES_SHUTDOWN="false"   # These are used by check_WEBES_running
  RUNNING_MBRS=""          
  RUNNING_NODES=""
  STOPPED_NODES=""
  NEW_COMPONENT=""

# Set up the user input loop by determining what the operational Constraint
# should be. If WEBES hasn't been configured yet, or if we're running on a
# new cluster member, don't display the menu - go straight to the appropriate
# configuration function. Constraint will be set to null after the needed
# configuration is performed.
#
# CONSTRAINT is a state indicator that changes the program's behavior. Values are:
#   "INIT", "NEW_MEMBER", or null. INIT implies that this is the first time the
#   program has run since Webes was installed. "NEW_MEMBER" implies that we are to
#   initialize a set of nodes that have been added to the cluster since last execution.
#   If set to null, business as usual.


   if [ "$SYSTEM_STATE" = "INSTALLED" ]; then
     if [ -z "$ANSWER_FILE" ]; then 
     /bin/cat <<EOF

This is the initial configuration session. You
will be asked to review or enter all of the
information required for the execution of WEBES.

You will need to know the following information:

  - Customer point of contacts phone and e-mail
  - Hewlett Packard Service Obligation numbers
  - System serial numbers
  - SMTP server name

EOF
     read_input "Are you prepared to continue?" "yes/no" "yes" "InitialConfig"
              if [ "$input" = "" ]; then
                   echo " "
#                  continue
              elif [ ! -z $input ]; then
                   input=`echo $input | /usr/bin/tr [A-Z]  [a-z]`
                   if [ $input = "yes" -o $input = "y" ]; then
#                  continue
                   /bin/echo ""  
                  else
                    exit 0
                  fi
             fi
            get_kit_path
      fi
     /bin/echo ""
     CONSTRAINT="INIT"
     NEXT="CONFIGURE_WEBES"

  elif [ "$SYSTEM_STATE" = "NEW_MEMBERS" ]; then

     get_new_members
     if [ -n "$NEW_MEMBER_MBRS" ]; then
        /bin/cat <<EOF

$NUM_NEW_MEMBERS new cluster member(s) have been added and must
be configured before the installed WEBES components
can run on the added node(s).

EOF
        CONSTRAINT="NEW_MEMBER"
        NEXT="CONFIGURE_NEW_MBRS"
     else
        CONSTRAINT=""
        NEXT="DISPLAY_MENU"
     fi

  elif [ "$SYSTEM_STATE" = "CONFIGURED" -o "$SYSTEM_STATE" = "PREV_CONFIGURED" ]; then
     if [ "$SYSTEM_STATE" = "PREV_CONFIGURED" ]; then
         prepare_for_webes_execution
     fi
     CONSTRAINT=""
     NEXT="DISPLAY_MENU"

    # WCC has been configured, but CA and CCAT may not have been. Always do CA first.

    get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ca.configure;
    if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
	/bin/echo ""
	/bin/echo "System Event Analyzer has been installed but not configured."
	stop_WEBES_if_running "ALL_NODES"
 	CONSTRAINT="INIT"
	NEXT="CONFIGURE_CA"
    else
	get_temp_registry_item $SVCTOOLS_HOME/common/desta/config/CommonFiles/SystemState ccat.configure;
	if [ "$GR_ITEM" = "NOT_CONFIGURED" ]; then
	  /bin/echo ""
	  /bin/echo "Computer Crash Analysis Tool has been installed but not configured."
	  stop_WEBES_if_running "ALL_NODES"
 	  CONSTRAINT="INIT"
	  NEXT="CONFIGURE_CCAT"
	fi
    fi  
  fi

  # Call the function that does all the work.
  # If the answer file does not exist call the UI otherwise process the answer file


  if [ -z "$ANSWER_FILE" ]; then
     main_menu_UI_loop
  else
     process_answerFile 
  fi


#Fix for Bug 3639 - Vijayant

 if [ -z "$VAL" ]; then
  	verify_ISEE_installed

  	if [ -n "$INSTALLED" ]; then
		
		output=`desta isee on nodir`
#	/bin/echo "Setting the Isee to ON"
        	
  	fi
  fi

  #Fix for Bug 3635 - Start

  #if [ -f $SVCTOOLS_HOME/specific/desta/save/managedentities/*.xml ]; then
  #	desta exec com.compaq.svctools.desta.services.managedentities.LoadManagedEntities
  # fi


  if [ -f $SVCTOOLS_HOME/specific/desta/save/managedentities ]; then
  XMLFILES=`/bin/ls $SVCTOOLS_HOME/specific/desta/save/managedentities/*.xml`
	if [ -n "$XMLFILES" ]; then
	   desta exec com.compaq.svctools.desta.services.managedentities.LoadManagedEntities
        fi
  fi
              
  #Fix for Bug 3635 - End

  # All done! If we shut down the Director to update the configuration, or if we 
  # installed a new component but haven't started the Director yet, give the user
  # a chance to startup now.


  /bin/echo ""
  if [ -n "$STOPPED_NODES" ]; then
     if [ -n "$IS_CLUSTER_MEMBER" ]; then
  	if [ "$SYSTEM_STATE" = "NEW_MEMBERS" ]; then
     	   for NODE in $NEW_MEMBER_NODES; do
	      N=`/bin/echo $STOPPED_NODES | /bin/grep $NODE`
	      if [ -z "$N" ]; then
	         if [ -z "$STOPPED_NODES" ]; then
		    STOPPED_NODES=$N
		 else
	            STOPPED_NODES="$STOPPED_NODES $N"
		 fi
	      fi
           done
        fi
        /bin/echo "The Director was shutdown during the execution of"
        /bin/echo "this script. Would you like to restart it on all"
        read_input "nodes on which it is configured to start?" "yes/no" "yes" "StartOnBoot"
     else
        /bin/echo "The Director was shutdown during the execution of"
        read_input "this script. Would you like to restart it now?" "yes/no" "yes" "StartOnBoot"
     fi
  else
     if [ -n "$NEW_COMPONENT" -o "$SYSTEM_STATE" = "NEW_MEMBERS" ]; then
        check_WEBES_running "ALL_NODES"
        if [ -z "$RUNNING_NODES" ]; then
           # WEBES is not running anywhere

          # Fix for PTR 91-22-1567  
           #where_can_WEBES_run
           COULD_RUN_NODES=""
           COULD_RUN_NODES=$FULL_HOSTNAME
          # Fix for PTR 91-22-1567

           if [ -n "$COULD_RUN_NODES" ]; then
	      # but it could run someplace
              STOPPED_NODES=$COULD_RUN_NODES
             if [ -n "$ANSWER_FILE" ]; then
                # Fix for PTR 91-22-1567
	        get_answer_item Start_DESTA_Now; ANSWER_START_DESTA="$GA_ITEM"
                if [ -z "$ANSWER_START_DESTA" -o "$ANSWER_START_DESTA" = "false" ]; then
                   input="no"
                else
                   input="yes" 
                fi
                # Fix for PTR 91-22-1567
              else  
              /bin/echo "The Director may be started in automatic analysis mode"
                 if [ -n "$IS_CLUSTER_MEMBER" ]; then
                    /bin/echo "now. Would you like to start it on all nodes on which"
                    read_input "it is configured to start?" "yes/no" "yes" "StartOnBoot"
                 else
                    read_input "now. Would you like to start it?" "yes/no" "yes" "StartOnBoot"
                 fi
             fi
           fi
        fi
     fi
  fi

  if [ "$input" = "yes" ]; then
     /bin/echo ""
     get_installed_product CA_INSTALLED ""
     get_installed_product CCAT_INSTALLED ""
     /bin/echo ""
     if [ -z "$CA_INSTALLED" -a -z "$CCAT_INSTALLED" ]; then
        /bin/echo "WEBES cannot be started - no optional components are installed"
        /bin/echo""
        exit 0
     fi
     for NODE in $STOPPED_NODES; do
        /bin/echo "...starting on $NODE"
        if [ "$NODE" = "$FULL_HOSTNAME" ]; then
           desta_process_start EXIT_CODE
 	   # Fix for PTR 91-22-1482
               execute_wsea_test_command
           # Fix for PTR 91-22-1482
        else
           MBR=`/bin/egrep "${NODE}$" $SVCTOOLS_HOME/common/desta/config/CommonFiles/member_nodes | /bin/cut -f 1 -d=`
           if [ -z "$MBR" ]; then
              /bin/echo "...unable to translate $NODE to cluster member ID"
           else
              desta_remote_start EXIT_CODE
           fi

        fi
        if [ "$EXIT_CODE" != "0" ]; then
           /bin/echo "...could not start on $NODE"
        fi
     done
  fi

/bin/touch $SVCTOOLS_HOME/specific/desta/data/webesInstalled.txt

  # Fix for PTR 91-22-1920
  #  sed_registry_file webes.Installed "t"
  #   sed_registry_file ISEE.proxyFailover "t"	
  # Fix for PTR 91-22-1920
  
  /bin/echo ""
  cd $USER_DIR
  exit 0
#****************************************************END************************************************************
