# checkinstall script to validate backing out a patch.
# directory format option.
#
#       @(#)patch_checkinstall 1.3 01/01/11 SMI
#
# Copyright (c) 1995 by Sun Microsystems, Inc.
# All rights reserved
#

PATH=/usr/sadm/bin:$PATH

LATER_MSG="PaTcH_MsG 6 ERROR: A later version of this patch is applied."
NOPATCH_MSG="PaTcH_MsG 2 ERROR: Patch number $ACTIVE_PATCH is not installed"
NEW_LIST=""

# Get OLDLIST
. $1

#
# Confirm that the patch that got us here is the latest one installed on
# the system and remove it from PATCHLIST.
#
Is_Inst=0
Skip=0
active_base=`echo $ACTIVE_PATCH | nawk '
	{ print substr($0, 1, match($0, "-")-1) } '`
active_inst=`echo $ACTIVE_PATCH | nawk '
	{ print substr($0, match($0, "-")+1) } '`
for patchappl in ${OLDLIST}; do
	appl_base=`echo $patchappl | nawk '
		{ print substr($0, 1, match($0, "-")-1) } '`
	if [ $appl_base = $active_base ]; then
		appl_inst=`echo $patchappl | nawk '
			{ print substr($0, match($0, "-")+1) } '`
		result=`expr $appl_inst \> $active_inst`
		if [ $result -eq 1 ]; then
			puttext "$LATER_MSG"
			exit 3
		elif [ $appl_inst = $active_inst ]; then
			Is_Inst=1
			Skip=1
		fi
	fi
	if [ $Skip = 1 ]; then
		Skip=0
	else
		NEW_LIST="${NEW_LIST} $patchappl"
	fi
done

if [ $Is_Inst = 0 ]; then
	puttext "$NOPATCH_MSG"
	exit 3
fi

#
# OK, all's well. Now condition the key variables.
#
echo "PATCHLIST=${NEW_LIST}" >> $1
echo "SUNW_PATCHID=" >> $1
echo "PATCH_INFO_$ACTIVE_PATCH=backed out" >> $1

# remove the used parameters
echo "ACTIVE_OBSOLETES=" >> $1
echo "SUNW_OBSOLETES=" >> $1

# $Id: ob.preremove,v 3.42 2002/10/04 06:45:57 vrigo Exp $  - %Q% 
#ident "%Z%isis:$RCSfile: ob.preremove,v $ $Revision: 3.42 $" 

# Copyright(C)1999 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
#
#               RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#               VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043

# Perform preremove processing for the ISIS package

# Refer to ob.checkinstall script for description of following parameters:
# BASEDIR, CLIENT_BASEDIR, PKG_INSTALL_ROOT
# before making any changes.

BASEDIR=/opt/VRTSob
PATH="/usr/sadm/bin:/sbin:/usr/sbin/:/usr/bin:/bin:$PATH"

LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$BASEDIR/lib"
export LD_LIBRARY_PATH

REGOPS="$BASEDIR/bin/vxregctl"
REGFILE="$PKG_INSTALL_ROOT/etc/vx/isis/Registry"

DEPENDENTPRODUCTS="Detected packages that depend on VRTSob. Please uninstall the products that depend on VRTSob before uninstalling this package."
SRVSHUTDOWN="Shutting down VEA server"
STOPSRV="Please stop the VEA Server"
FORCESHUTDOWN="VEA Server could not be stopped after 2 minutes. VEA Server will be stopped forcefully"


# Stop Isis server
VXSVC="$BASEDIR/bin/vxsvc"
KILLCMD="$VXSVC -k"
STATUSCMD="$VXSVC -m"

if [ "X$PKG_INSTALL_ROOT" = "X" ]
then
   RUNSTATE=`echo " RUNNING"`
   STARTPENDING=`echo " START PENDING"`
   STOPPENDING=`echo " STOP PENDING"`
   CURRENT_RUNSTATE=`$STATUSCMD|awk -F: '{ print $2 }'`

   while [ "$STARTPENDING" = "$CURRENT_RUNSTATE" ]
   do
      sleep 2
      CURRENT_RUNSTATE=`$STATUSCMD|awk -F: '{ print $2 }'`
   done

   if [ "$RUNSTATE" = "$CURRENT_RUNSTATE" ]
   then
      puttext -l 5 "$SRVSHUTDOWN"

      # stop the server in subshell

        ($KILLCMD >/dev/null 2>&1 </dev/null &)
        PID=$!
        echo $STATUSCMD | nawk '{
            for (i=0;i<30;i++)
            {
                $0 | getline output
                close($0)
                if (output ~ /NOT RUNNING/)
                {
                    break
                }
                else
                {
                    system("sleep 2");
                    printf ".";
                }
            }
            if (i == 30)
            {
                printf "\n";
            }
        }'

        # now kill vxsvc with a kill -9
        CURRENT_RUNSTATE=`$STATUSCMD|awk -F: '{ print $2 }'`
        if [ "$STOPPENDING" = "$CURRENT_RUNSTATE" ]
        then
            puttext -l 5 "$FORCESHUTDOWN"
            kill -9 $PID 2>/dev/null
            PID=`eval ps -aef | awk '/'vxsvc'/ && !/awk/ {print $2}'`
            kill -9 $PID 2>/dev/null
            rm -f /var/vx/isis/vxisis_shutdown.lock 2>/dev/null
        fi
   fi
else
   serviceRunning="1"
   [ -f $PKG_INSTALL_ROOT/var/vx/isis/vxisis.lock ] || serviceRunning=0
   if [ $serviceRunning -eq 1 ] >/dev/null
   then
       puttext -l 5 "$STOPSRV"
       exit 3
   fi
fi

exit 0

#XXXSpecial_CommandsXXX#

