#!/bin/sh 
#
#ident  "@(#)postbackout.src 1.15     03/09/25 SMI"
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
#
# Check if the interconnect has been configured. If so,
# update the firmware on all units as soon as the patch 
# is removed.
#

UT_ROOTDIR=${2:-/}
UT_TMP=/var/opt/SUNWut/tmp

${UT_TMP}/${PatchNum}/utfwadm -R

NO_ACTION="no action taken"
${UT_TMP}/${PatchNum}/utfwadm -A -a -n all 2>&1 | grep -v "${NO_ACTION}"
${UT_TMP}/${PatchNum}/utfwadm -A -a -N all 2>&1 | grep -v "${NO_ACTION}"

/bin/rm -rf ${UT_TMP}/${PatchNum}


SAVE_DIR_PATH=/etc/opt/SUNWut/${PatchNum}
PAM_CONF=/etc/pam.conf
SAVE_PAM_CONF=$SAVE_DIR_PATH/pam.conf.orig.saved
MOD_PAM_CONF=$SAVE_DIR_PATH/pam.conf.after_patch
PAM_CONF_CURRENT=$SAVE_DIR_PATH/pam.conf.current
AUTH_PROPS=/etc/opt/SUNWut/auth.props

SAVE_AUTH_PROPS=$SAVE_DIR_PATH/auth.props.saved
CP=/usr/bin/cp
DIFF=/usr/bin/diff
CAT=/usr/bin/cat
INSTALLF=/usr/sbin/installf
UTO=SUNWuto


#
# Append the original auth.props entries, removed at patch install time
# Append an extra blank line.(to make sure other lines are always 
# added at the end of the file).
#

if [ -f $SAVE_AUTH_PROPS ]
then
	$CAT $SAVE_AUTH_PROPS >> $AUTH_PROPS
	echo "" >> $AUTH_PROPS
fi

#
# Restore the old pam.conf to revert system state to before
# this patch add. If file has changed after the patch add, there 
# is some manual work required to edit those changes in again.  
# Output warning message and save the files for reference. 
#

$DIFF $PAM_CONF $MOD_PAM_CONF > /dev/null 
if [ $? != 0 ]; then 

	# File has changed  
	# output warning message 
	$CP -p $PAM_CONF $PAM_CONF_CURRENT 
	$INSTALLF $UTO $PAM_CONF_CURRENT f 0644 root sys
	$INSTALLF -f $UTO

	echo "" 
	echo "****!!!!!!!!!! WARNING !!!!!!!!!!****" 
	echo "" 
	echo "It has been detected that changes were made to the $PAM_CONF file after this" 
	echo "patch was installed.  Removing this patch, will cause these changes to be lost" 
	echo "and will have to be manually added back." 
	echo "A copy of the current $PAM_CONF file has been saved " 
	echo "at : $PAM_CONF_CURRENT"
	echo "Also, a copy of the $PAM_CONF file, right after the patch was applied has been" 
	echo "saved at : $MOD_PAM_CONF" 
	echo "Please use the appropriate diff utilities to determine the changes and then add" 
	echo "them back to the $PAM_CONF file." 
	echo "The $PAM_CONF file will now be in the state it was before this patch was applied." 
	echo "" 
	echo "*************************************" 
	echo ""  

fi

$CP -p $SAVE_PAM_CONF $PAM_CONF 

exit 0
