# This script deletes the used backout data for a patch package
# and removes the deletes file entries.
#
# directory format options.
#
# ident "@(#)patch_postinstall	1.2 03/02/07 SMI"
#
# Copyright (c) 1995 by Sun Microsystems, Inc.
# All rights reserved
#

# XXXXX patch specific preremove stuff went in here. XXXXX
# preremove script for SUNWutscr - Sun Ray smartcard APIs

# if PKG_INSTALL_ROOT is not assigned from the env then
# set it to an empty string, set -u in effect below
#
if [ -z "$PKG_INSTALL_ROOT" ]; then
	PKG_INSTALL_ROOT=""
fi

set -u

  SHOWREV="/bin/showrev"
PATCH_NUM="111891"
     GREP="/bin/grep"
      AWK="/bin/awk"

SUNWUTLIB="${PKG_INSTALL_ROOT}${BASEDIR}/SUNWut/lib"

OCF_CP_FILE="/etc/smartcard/ocf.classpath"

CT_JAR="${SUNWUTLIB}/sunrayCTdriver.jar"
CT_JAR_BASE="`/bin/basename $CT_JAR`"

TMP="/tmp/$$.SUNWutscr"

# XXXXX patch revision specific stuff went here. XXXXX
 #
 # Need to know what revision of the 111891 patch are we backing out to.
 # Since SmartCard Framework was introduced as part of rev-07, we need
 # some changes to remain here, if the new rev is to be 7 or more.
 #

 #
 # Get the list of 111891 patches installed on this system.
 # Get only the revision number.
 #
 PATCH_LIST=`$SHOWREV -p |$GREP -ws $PATCH_NUM |$AWK -F' ' '{print $2}' | $AWK -F- '{print $2}'`

 #
 # Get the previous patch revision number.
 #
 if [ -n "$PATCH_LIST" ] ; then
    PATCH_REV_LIST=`echo $PATCH_LIST | awk '{ if (NF == 1) print 0; \
			else print $(NF - 1); }'`
    if [ -n "$PATCH_REV_LIST" -a $PATCH_REV_LIST -lt 7 ] ; then
  
    	egrep -vi $CT_JAR_BASE $OCF_CP_FILE >$TMP
    	mv $TMP $OCF_CP_FILE

    fi
 fi
# XXXXX patch revision specific stuff ended here. XXXXX


# XXXXX patch specific preremove stuff ended here. XXXXX

PATH=/usr/sadm/bin:$PATH
THIS_DIR=`dirname $0`

Our_Deletes=$THIS_DIR/deletes

#
# Delete the used backout data
#
if [ -f $Our_Deletes ]; then
	cat $Our_Deletes | while read path; do
		if valpath -l $path; then
			Client_Path=`echo "$CLIENT_BASEDIR/$path" | sed "s|//|/|"`
		else	# It's an absolute path
			Client_Path=$path
		fi
		rm `removef $PKGINST $Client_Path`
	done
	removef -f $PKGINST

	rm $Our_Deletes
fi

#
# Remove the deletes file, checkinstall and the postinstall
#
rm -r $PKGSAV/$ACTIVE_PATCH
rm -f $THIS_DIR/checkinstall $THIS_DIR/postinstall

exit 0
