#!/sbin/sh 
# 
# *****************************************************************
# *                                                               *
# *    Copyright Compaq Computer Corporation, 2001                *
# *                                                               *
# *   The software contained on this media  is  proprietary  to   *
# *   and  embodies  the  confidential  technology  of  Compaq    *
# *   Computer Corporation.  Possession, use,  duplication  or    *
# *   dissemination of the software and media is authorized only  *
# *   pursuant to a valid written license from Compaq Computer    *
# *   Corporation.                                                *
# *                                                               *
# *   RESTRICTED RIGHTS LEGEND   Use, duplication, or disclosure  *
# *   by the U.S. Government is subject to restrictions  as  set  *
# *   forth in Subparagraph (c)(1)(ii)  of  DFARS  252.227-7013,  *
# *   or  in  FAR 52.227-19, as applicable.                       *
# *                                                               *
# *****************************************************************
#
# HISTORY
# 
# @(#)$RCSfile: patch_template.scp,v $ $Revision: 1.1.2.2 $ (DEC) $Date: 2000/04/21 18:12:52 $
# 

[ "$CHECK_SYNTAX" ] ||
{ 
	. ./usr/share/lib/shell/libpat

	:       - PCH_CINSTALL
	#               actions to be taken when ACT=C INSTALL
	PCH_CINSTALL ()
	{
		#  check the .inv file to see if we are shipping ddr.dbase
		#  and run ddr_config -c 

		_SUBSET_NAME=`basename $0 .scp`
		_SMDB="./usr/.smdb."

		grep -q './etc/.new..ddr.dbase	' $_SMDB/$_SUBSET_NAME.inv && {
			/sbin/ddr_config -c
		}
		return 0
	}

	PCH_POSTM_1()
	{
		FAILURE_INDICATOR=$_DUPATCH_TMP/PatchToolsVersionTestFailed
		SUCCESS_INDICATOR=$_DUPATCH_TMP/PatchToolsVersionTestSucceeded
		
		# Have we been through here already ?
		[ -e $FAILURE_INDICATOR ] && {
			[ "$PATCH_DEBUG" = 1 ] && {
				echo "%SCP-D-Had Previous failure"
			}
			return 1
		}
		[ -e $SUCCESS_INDICATOR ] && {
			[ "$PATCH_DEBUG" = 1 ] && {
				echo "%SCP-D-Had Previous success"
			}
			return 0
		}

		# Figure out latest rev of patch tools installed on latest OS kit.
		
		OSF_BASE_SUBSET=`( cd ./usr/.smdb./ ; /bin/ls OSFBASE???.lk ) | tail -1 | sed 's/.lk//'`
		OS_VERSION=`expr $OSF_BASE_SUBSET : '^.*\(...\)$'`
		PATCH_TOOLS_SUBSET=`( cd ./usr/.smdb./ ; /bin/ls OSFPAT?$_TOOLSUB??$OS_VERSION.lk ) | tail -1 | sed 's/.lk//'`
		PATCH_TOOLS_REVISION=`expr $PATCH_TOOLS_SUBSET : '.*\([0-9][0-9]\)...'`
		
		#
		# What is the minimum patch tools version required ?
		#

		# General default - first rev this logic was required in.
		_MINIMUM_PATCH_TOOLS_VERSION=12

		# Parameter from the control file.
		[ "$PATCH_MINIMUM_TOOLS_VERSION" != "" ] && {
			_MINIMUM_PATCH_TOOLS_VERSION=$PATCH_MINIMUM_TOOLS_VERSION
		}

		# Ability to override it from the outside.
		[ "$GLOBAL_MINIMUM_PATCH_TOOLS_VERSION" != "" ] && {
			_MINIMUM_PATCH_TOOLS_VERSION=$GLOBAL_MINIMUM_PATCH_TOOLS_VERSION
		}

		# Check for the minimum version
		[ "$PATCH_TOOLS_REVISION" -lt "$_MINIMUM_PATCH_TOOLS_VERSION" ] && {
			touch $FAILURE_INDICATOR

			REAL_KIT_TOP=$_DUPATCH_KIT
			[ "$REAL_KIT_TOP" = "" ] && {
				REAL_KIT_TOP=$_KIT_TOP
			}
			# Since they cd'ed into here the real top is two more above.
			REAL_KIT_TOP=`dirname $REAL_KIT_TOP`
			REAL_KIT_TOP=`dirname $REAL_KIT_TOP`

			echo "\007\007\007"
                	echo "
****************************************************************************

The Updated tools subset must be loaded before you can install the patches.

To load the latest tools subset, run the local copy of 'dupatch' in the
patch kit directory: $REAL_KIT_TOP

Enter the command: $REAL_KIT_TOP/dupatch

****************************************************************************
" | tee -a $_SLOG
			return 1
		}
		touch $SUCCESS_INDICATOR
		return 0
	}

	PCH_MAIN "$@"
}
