#!/bin/sh
#
# @(#)prepatch.src	1.9		03/04/28	SMI
#
# If S8 is installed, the following patches must be installed:
# 
# 	108919-14 CDE Patch
#	109354-14 CDE Patch
#	109887-13 OCF Patch
#
# The version above is the minimum version which must be installed

retval=0

if [ `uname -r` = "5.8" ]
then
   # REQPATCH1 checks the minimum revision of 108919
   REQPATCH1=`showrev -p | sed -n 's/Patch: 108919-\([^ ]*\).*/\1/p' \
	| sort -n | tail -1`
   # REQPATCH2 checks the minimum revision of 109354
   REQPATCH2=`showrev -p | sed -n 's/Patch: 109354-\([^ ]*\).*/\1/p' \
	| sort -n | tail -1`
   # REQPATCH3 checks the minimum revision of 109887
   REQPATCH3=`showrev -p | sed -n 's/Patch: 109887-\([^ ]*\).*/\1/p' \
	 | sort -n | tail -1`

   # Check the installed version against the minimum version
   if [ x"$REQPATCH1" = "x" ] || [ $REQPATCH1 -lt 14 ]
   then
       echo "You must install patch 108919-14 or later before proceeding"
       # force the patchadd to fail
       retval=1
   fi
   
   if [ x"$REQPATCH2" = "x" ] || [ $REQPATCH2 -lt 14 ]
   then
       echo "You must install patch 109354-14 or later before proceeding"
       # force the patchadd to fail
       retval=1
   fi

   if [ x"$REQPATCH3" = "x" ] || [ $REQPATCH3 -lt 13 ]
   then
       echo "You must install patch 109887-13 or later before proceeding"
       # force the patchadd to fail
       retval=1
   fi
fi

if [ $retval != 0 ]
then
    exit $retval
fi

#
# Save the pam.conf, and auth.props files away before applying this patch
#

MKDIR=/usr/bin/mkdir 
SAVE_DIR_PATH=/etc/opt/SUNWut/${PatchNum} 
INSTALLF=/usr/sbin/installf
CP=/usr/bin/cp
RM=/usr/bin/rm
PAM_CONF=/etc/pam.conf
SAVE_PAM_CONF=$SAVE_DIR_PATH/pam.conf.orig.saved 
UTO=SUNWuto

if [ -d $SAVE_DIR_PATH ]; then 
	$RM -rf $SAVE_DIR_PATH 
fi 
 
$MKDIR -p -m 0755 $SAVE_DIR_PATH
$CP -p $PAM_CONF $SAVE_PAM_CONF

$INSTALLF $UTO $SAVE_DIR_PATH d 0755 root sys
$INSTALLF $UTO $SAVE_PAM_CONF f 0644 root sys
$INSTALLF -f $UTO

exit 0
