#!/bin/sh
#
# ident    "%Z%%M% %I%     %E% SMI" 
#
# Copyright (c) 2000 by Sun Microsystems, Inc.
# All rights reserved

# PatchNum & ROOTDIR are inherited from patch scripts
#
this_rev=`expr $PatchNum : '.*-\(.*\)'`
patch_base=`expr $PatchNum : '\(.*\)-.*'`

BEG_REV=03  # If another patch higher than this is installed 
			# do nothing

LOGDIR=$ROOTDIR/var/sadm/wbem

# Need to deal with the diskless client scenario
# where the root package and usr package info
# is not located in the same place.
# This means that the "rm" command should not be run
# when this patch is applied to the usr area of a
# diskless client, or look for SUNWwbcou if this
# patch is applied to a root area of a diskless client.
#
# First see if the SUNWwbcou package exists and
# if it doesn't get the pkginfo for SUNWwbcor
# Assume that one or the other exists.
# This should guarantee that the egrep command 
# will not fail because it can't find pkginfo

if [ -f $ROOTDIR/var/sadm/pkg/SUNWwbcou/pkginfo ]; then
    INFO="$ROOTDIR/var/sadm/pkg/SUNWwbcou/pkginfo"
else
    INFO="$ROOTDIR/var/sadm/pkg/SUNWwbcor/pkginfo"
fi

pids=`egrep '^PATCHLIST' $INFO | nawk -F= '{print $2}'`

# Cycle thru all patchids; when patchbase matches,
# determine if appropriate to reverse procedure done by
# patches starting with $BEG_REV

for i in `echo $pids`; do
	echo $i | egrep -s $patch_base || continue
	rev=`expr //$i : '.*-\(.*\)'`
	[ $rev -lt $BEG_REV ] && continue
	[ $rev -eq $this_rev ] && exit 0
	[ $rev -gt $this_rev ] && exit 0
done

# These commands should only be run in the root
# area of a diskless client configuration.
# only do them if logdir exists

if [ -d $LOGDIR ]; then
    /usr/bin/rm -rf ${LOGDIR}/log
    /usr/bin/mv -f ${LOGDIR}/logprepatch ${LOGDIR}/log 2>/dev/null
    # Remove the present
    /usr/bin/rm -rf ${LOGDIR}/logr
    # Move the old log back
    /usr/bin/mv ${LOGDIR}/logru3 ${LOGDIR}/logr 2> /dev/null
fi

exit 0


