#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 1.72 $ generated on Fri Jan 31 14:58:56 MST 1997
#
# (c)Copyright 1983-1996 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
########
#  Product: PHCO_23149
#  Fileset: ARRAY-MGMT
#  configure 
########

    set -a                      # Export all vars

    UTILS=/usr/lbin/sw/control_utils
    if [ ! -f $UTILS ]
    then
        echo "ERROR:   Cannot find $UTILS"
        exit 1
    fi

    . $UTILS

    exitval=$SUCCESS                 # Anticipate success

###############################################################################
# Prepare for conditional copying of files
# Insure /etc/hparray directory exists, just in case user removed it.

    cond_mkdir 0555 bin bin /etc/hparray

    TEMP_SW_LOCATION=${SW_LOCATION}
    SW_LOCATION="/"     # setup so newconfig will work from / and not /opt/hparray/

    file="/etc/rc.config.d/hparamgr"

    for i in $file
    do
      newconfig_cp $i
      retval=$?
      [[ $exitval -ne $FAILURE && $retval -eq $FAILURE ]] && exitval=$retval
      newconfig_msgs $retval
    done

    SW_LOCATION=${TEMP_SW_LOCATION}          # restore original

###############################################################################
#  Create path to /opt/hparray/bin

    typeset pathelement
    typeset pathfilename
    typeset retval=0

    pathfilename=${SW_ROOT_DIRECTORY}etc/PATH    
    pathelement=${SW_ROOT_DIRECTORY}opt/hparray/bin
    mptempfile=/var/tmp/SW_TMP$$
    
    if [[ ! -s $pathfilename ]]
    then
      echo $pathelement > $pathfilename
      retval=$?
      [[ $retval -eq $SUCCESS ]] && chmog 444 bin bin $pathfilename
    else
      awk -v p=$pathelement -v tmp=$mptempfile '
      BEGIN {FS = ":"}
	    {
              for (e=1; e <= NF; e++)
	        {
                  if ( $e == p ) exit 2
	          printf ("%s:", $e) > tmp
	        }
	    }
      END { printf ("%s\n", p)  > tmp }' $pathfilename

      retval=$?
      
      if [[ $retval = 0 ]]
      then 
        if [[ -s $mptempfile ]]
	  then
	    chmog 444 bin bin $mptempfile
	    mv $mptempfile $pathfilename
	    retval=$?
	  fi
      fi
    fi

    if [[ $retval = 2 ]]
    then
        echo "NOTE:    /etc/PATH already contains the \"${SW_ROOT_DIRECTORY}opt/hparray/bin\" path for"
        echo "         the HP Fibre Array/60 product."
        retval=0
    else
        echo "NOTE:    Processes may need to be restarted to inherit \"${SW_ROOT_DIRECTORY}opt/hparray/bin\""
        echo "         in their PATH."
    fi

    rm -rf $mptempfile

    exitval=$retval
    
###############################################################################
# Insure init.d script will be started following reboot
  
    if [[ ! -f ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr ]] 
    then
    	touch ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr
        echo "NOTE:    File ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr not found."
        echo "         It has been created."
	HPARAMGR_START_STOP=0
    else
    	. ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr
    fi
    
    if [[ $HPARAMGR_START_STOP != 1 ]]
    then
	ch_rc -a -R ${SW_ROOT_DIRECTORY} -p HPARAMGR_START_STOP=1 etc/rc.config.d/hparamgr 
        . ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr
    	if [[ $HPARAMGR_START_STOP = 1 ]]
    	then
            echo "NOTE:    HPARAMGR_START_STOP has been set to 1 in ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr"
            echo "         to allow the HP Array Manager/60 product to automatically"
            echo "         restart following a system reboot."
    	else
            echo "WARNING: HPARAMGR_START_STOP could not be set to 1 in ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparamgr."
            echo "         The HP Array Manager/60 product will not automatically restart"
            echo "         following a system reboot unless this value is changed."
            exitval=$WARNING
    	fi
    fi

##############################################################################
# Startup the daemon's (AM60Srvr and hparamgrd)
  
    if [[ ! -x ${SW_ROOT_DIRECTORY}usr/lbin/hparray/hparamgrrc ]] 
    then
      echo "ERROR:   There is a problem with the daemon startup file, check for "
      echo "         existence of the file, and if it has the correct permissions."
      echo "         The file is \"/usr/lbin/hparray/hparamgrrc\" and the permissions"
      echo "         are 0555, bin, bin.  Then try the SWINSTALL again."
      exit $FAILURE
    fi

    ps -e | grep hparamgrd >/dev/null 2>&1
    hparamgrd_stat=$?	
      
    ps -e | grep AM60Srvr >/dev/null 2>&1
    AM60Srvr_stat=$?

    if  [[ $hparamgrd_stat -ne 0 ]] && [[ $AM60Srvr_stat -ne 0 ]]
    then
      echo "NOTE:    Starting the disk array monitor daemons.                      "
      echo "NOTE:    Check the file ${SW_ROOT_DIRECTORY}etc/hparray/HPARAMGR.INFO"
      echo "         to determine if any arrays were found.                       "
      ${SW_ROOT_DIRECTORY}usr/lbin/hparray/hparamgrrc >> ${SW_ROOT_DIRECTORY}etc/hparray/HPARAMGR.INFO 2>&1 &
    elif [[ $AM60Srvr_stat -ne 0 ]]
    then
      echo "NOTE:    Starting the AM60Srvr daemon.                      "
      ${SW_ROOT_DIRECTORY}opt/hparray/bin/AM60Srvr >/dev/null 2>&1 &
    else
      echo "NOTE:    The disk array monitor daemons were already running."
    fi

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

exit $exitval

