# This script deletes the used backout data for a patch package
# and removes the deletes file entries.
#
# directory format options.
#
#       @(#)patch_postinstall 1.4 07/07/02 SMI
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms. 
#

PATH=/usr/sadm/bin:$PATH
THIS_DIR=`dirname $0`
RMF=/usr/sbin/removef
PATCH_COMMON_LIB="/usr/lib/patch/patch_common_lib"
SAFEMODE_FAILED="Exiting! Patch deferred activation failed"

if [ "$SAFEMODE_INSTALL" = "true" ] ; then
        if [ ! -s "$PATCH_COMMON_LIB" ]; then
                puttext "$SAFEMODE_FAILED"
                exit 1
        fi
        . $PATCH_COMMON_LIB
        InitSafemode || {
                puttext $SAFEMODE_FAILED
                exit 1
        }
fi

Our_Deletes=$THIS_DIR/deletes

#
# Delete the used backout data
#
#
# If this is a safemode patch package and it has a deletes file in it
# handle the deletion of an object for safemode patching.
#
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
		
		if [ "$SAFEMODE_INSTALL" = "true" ] ; then
			HandleSafemodeDeleteObject $PKGINST $Client_Path
                else
                        rm `$RMF $PKGINST $Client_Path`
                fi
	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
