#!/bin/sh
#
# ident "@(#)postpatch.src	1.13 03/04/29 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 installed.
#

# We may be installed as part of a jumpstart, so check
# the install root

UT_ROOTDIR=${2:-/}

UT_BASEDIR=`pkginfo -R ${UT_ROOTDIR} -r SUNWuto`
NO_ACTION="no action taken"
$UT_BASEDIR/SUNWut/sbin/utfwadm -A -a -n all 2>&1 | grep -v "${NO_ACTION}"
$UT_BASEDIR/SUNWut/sbin/utfwadm -A -a -N all 2>&1 | grep -v "${NO_ACTION}"


#
# Save the modified pam.conf for later use, if this patch
# is removed
#

SAVE_DIR_PATH=/etc/opt/SUNWut/${PatchNum}
CP=/usr/bin/cp
PAM_CONF=/etc/pam.conf
SAVE_PAM_CONF=$SAVE_DIR_PATH/pam.conf.after_patch

$CP -p $PAM_CONF $SAVE_PAM_CONF

# 
# Edit auth.props to remove entry for acceptRedirectToken and
# related comments. 
# This code removes all non-comment lines from auth.props which contain the  
# acceptRedirectToken tag. It also removes any chunk of comments which 
# begins with a comment line containing this tag. 
# It saves the lines removed to the .saved file for restoration  
# on a patch remove. 
#

AWK=/usr/bin/awk
ECHO=/usr/bin/echo
MV="/usr/bin/mv -f"
RM="/usr/bin/rm -f"

TOKEN_TO_BE_REMOVED=acceptRedirectToken
AUTH_PROPS=/etc/opt/SUNWut/auth.props
SAVE_AUTH_PROPS=$SAVE_DIR_PATH/auth.props.saved
TMP_PROPS=$SAVE_DIR_PATH/auth.$$
INSTALLF=/usr/sbin/installf
UTO=SUNWuto

$AWK   "BEGIN {
		art_found=0
              }
              
	/^#.*$TOKEN_TO_BE_REMOVED/ {
        	print > \"$SAVE_AUTH_PROPS\"
		art_found=1
                next
              }

	/$TOKEN_TO_BE_REMOVED/ {
		print > \"$SAVE_AUTH_PROPS\" 
                art_found=0 
                next
              }

	/^#/ { 
		if (art_found == 1) 
			print > \"$SAVE_AUTH_PROPS\" 
		else 
			print > \"$TMP_PROPS\" 
			next 
	     }

	/^$/ {
        	art_found=0
             }

	/^[^#]/ {
		art_found=0
             }
         {
         	print > \"$TMP_PROPS\"
	  }
         " $AUTH_PROPS 

if [ "$?" = 0 ] ; then
	$MV $TMP_PROPS $AUTH_PROPS
	/usr/bin/chgrp other $AUTH_PROPS
	/usr/bin/chmod 444 $AUTH_PROPS
else
	$RM $TMP_PROPS
	$ECHO "Error updating $AUTH_PROPS"
	exit 1
fi

$INSTALLF $UTO $SAVE_AUTH_PROPS f 0444 root other
$INSTALLF $UTO $SAVE_PAM_CONF f 0644 root sys
$INSTALLF -f $UTO

exit 0
