#!/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_23262
#  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

###############################################################################
#  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 HPAutoRAID 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/hparray ]] 
    then
    	touch ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparray
        echo "NOTE:    File ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparray not found."
        echo "         It has been created."
	HPARRAY_START_STOP=0
    else
    	. ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparray
    fi
    
    if [[ $HPARRAY_START_STOP != 1 ]]
    then
	ch_rc -a -R ${SW_ROOT_DIRECTORY} -p HPARRAY_START_STOP=1 etc/rc.config.d/hparray 
        . ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparray
    	if [[ $HPARRAY_START_STOP = 1 ]]
    	then
            echo "NOTE:    HPARRAY_START_STOP has been set to 1 in ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparray"
            echo "         to allow the HPAutoRAID product to automatically restart"
            echo "         following a system reboot."
    	else
            echo "WARNING: HPARRAY_START_STOP could not be set to 1 in ${SW_ROOT_DIRECTORY}etc/rc.config.d/hparray."
            echo "         The HPAutoRAID product will not automatically restart"
            echo "         following a system reboot unless this value is changed."
            exitval=$WARNING
    	fi
    fi

##############################################################################
# Startup the daemon's (ARMServer and arraymond)
  
    if [[ ! -x ${SW_ROOT_DIRECTORY}usr/lbin/hpC2400/hparrayrc ]] 
    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/hpC2400/hparrayrc\" and the permissions"
      echo "         are 0555, bin, bin.  Then try the SWINSTALL again."
      exit $FAILURE
    fi

    ps -e | grep arraymond >/dev/null 2>&1
    arraymond_stat=$?	
      
    ps -e | grep ARMServer >/dev/null 2>&1
    ARMServer_stat=$?

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

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

exit $exitval

