#! /bin/sh
#set -x
#
# Copyright %G% by Sun Microsystems, Inc.
#
# @(#)install_required_patches "@(#)install_required_patches "%W% %E% Sun Microsystems" 
#
# interface to install patches for Sun projects

#
# Echo patch descriptions
#
echo_patch()
{
	patch=$1

	#
	# place patch descriptions here
	#
	case $patch in
	106300-05) PATCH_DESCRIPTION="/usr/lib/libC.so.5 64-bit for SPARC/Solaris 7"
		;;
	106327-04) PATCH_DESCRIPTION="/usr/lib/libC.so.5 for SPARC/Solaris 7"
		;;
	106328-04) PATCH_DESCRIPTION="/usr/lib/libC.so.5 for Intel/Solaris 7"
                ;;
	107058-01) PATCH_DESCRIPTION="/usr/ccs/bin/as 64-bit for SPARC/Solaris 7"
		;;
	105591-05) PATCH_DESCRIPTION="/usr/lib/libC.so.5 for SPARC/Solaris 2.6"
		;;
	104678-03) PATCH_DESCRIPTION="/usr/lib/libC.so.5 for Intel/Solaris 2.6"
		;;
	106529-03) PATCH_DESCRIPTION="/usr/lib/libC.so.5 for SPARC/Solaris 2.5.1"
		;;
	106530-03) PATCH_DESCRIPTION="/usr/lib/libC.so.5 for Intel/Solaris 2.5.1"
                ;;
        103801-07) PATCH_DESCRIPTION="sccs y2000 for SPARC/Solaris 2.5.1"
		;;
        103802-05) PATCH_DESCRIPTION="sccs y2000 for Intel/Solaris 2.5.1"
		;;
	*) PATCH_DESCRIPTION=""
		;;
	esac
	message "$patch - $PATCH_DESCRIPTION"
}
	
	
set_patches()
{
if [ "${OS}" = "${SOLARIS1}" ]
then
	MP_PATCHES=""
	ADA_PATCHES=""
	C_PATCHES=""
	CPL_PATCHES=""
	F77_PATCHES=""
	F90_PATCHES=""
	PC_PATCHES=""
	SW_PATCHES=""
	SWADA_PATCHES=""
	TW_PATCHES=""
	TOOLH_PATCHES=""
	LICENSE_PATCHES=""
	MP_OS_PATCHES=""
	ADA_OS_PATCHES=""
	C_OS_PATCHES=""
	CPL_OS_PATCHES=""
	F77_OS_PATCHES=""
	F90_OS_PATCHES=""
	PC_OS_PATCHES=""
	SW_OS_PATCHES=""
	SWADA_OS_PATCHES=""
	TW_OS_PATCHES=""
	TOOLH_OS_PATCHES=""
	LICENSE_OS_PATCHES=""

elif [ "${OS}" = "${SOLARIS2}" ]; then
        rel_val=`uname -r`

        case $rel_val in
          5.7)   # determine 64- or 32-bit hardware, install proper patch.
                 #Solaris 2.7 build21AL2
                    if [ "`isainfo -b`" = "64" ]; then
                       cpl_os_specific="106300-05 106327-04"
                       tools_os_specific="107058-01"
                    else
                       cpl_os_specific="106327-04"
                       tools_os_specific=""
                    fi
                    ;;
          5.6)   cpl_os_specific="105591-05";;
          5.5.1) cpl_os_specific="106529-03"
                 y2k_os_specific="103801-07";;
          *)     cpl_os_specific="";;
        esac

	# Use this macro for patches which must go out with all products
	#
	FOR_ALL_PROD=""

	MP_PATCHES=""
	ADA_PATCHES=""
	C_PATCHES=""
	CPL_PATCHES=""
	F77_PATCHES=""
	F90_PATCHES=""
	F90BR_PATCHES=""
	PC_PATCHES=""
	PERFLIB_PATCHES=""
	SW_PATCHES=""
	SWADA_PATCHES=""
	TW_PATCHES=""
	TOOLH_PATCHES=""
	TOOLS_PATCHES=""
	Y2K_PATCHES=""
	VISU_PATCHES=""
	LICENSE_PATCHES=""

	MP_OS_PATCHES=""
	ADA_OS_PATCHES=""
	C_OS_PATCHES="${FOR_ALL_PROD}"
	Y2K_OS_PATCHES="${FOR_ALL_PROD} $y2k_os_specific"
	TOOLS_OS_PATCHES="${FOR_ALL_PROD} $tools_os_specific"
	CPL_OS_PATCHES="${FOR_ALL_PROD} $cpl_os_specific"
	F77_OS_PATCHES="${FOR_ALL_PROD}"
	F90_OS_PATCHES="${FOR_ALL_PROD}"
	F90BR_OS_PATCHES="${FOR_ALL_PROD}"
	PC_OS_PATCHES="${FOR_ALL_PROD} "
	PERFLIB_OS_PATCHES="${FOR_ALL_PROD}"
	SW_OS_PATCHES="${FOR_ALL_PROD}"
	SWADA_OS_PATCHES="${FOR_ALL_PROD} "
	TW_OS_PATCHES="${FOR_ALL_PROD}"
	TOOLH_OS_PATCHES="${FOR_ALL_PROD} "
	VISU_OS_PATCHES="${FOR_ALL_PROD} "
	LICENSE_OS_PATCHES="${FOR_ALL_PROD} "
	NEO_OS_PATCHES="${FOR_ALL_PROD}"

elif [ "${OS}" = "${INTEL_SOL2}" ]; then
        rel_val=`uname -r`

        case $rel_val in
          5.7)  cpl_os_specific="106328-04" ;; 
          5.6)   cpl_os_specific="104678-03";;
          5.5.1) cpl_os_specific="106530-03"
                 y2k_os_specific="103802-05";;
          *)     cpl_os_specific="";;
        esac

	# Use this macro for patches which must go out with all products
	#
	FOR_ALL_PROD=""

	MP_PATCHES=""
	ADA_PATCHES=""
	C_PATCHES=""
	CPL_PATCHES=""
	F77_PATCHES=""
	F90_PATCHES=""
	F90BR_PATCHES=""
	PC_PATCHES=""
	PERFLIB_PATCHES=""
	SW_PATCHES=""
	SWADA_PATCHES=""
	TW_PATCHES=""
	TOOLH_PATCHES=""
	Y2K_PATCHES=""
	VISU_PATCHES=""
	LICENSE_PATCHES=""

	MP_OS_PATCHES=""
	ADA_OS_PATCHES=""
	C_OS_PATCHES="${FOR_ALL_PROD}"
	Y2K_OS_PATCHES="${FOR_ALL_PROD} $y2k_os_specific"
	CPL_OS_PATCHES="${FOR_ALL_PROD} $cpl_os_specific"
	F77_OS_PATCHES="${FOR_ALL_PROD}"
	F90_OS_PATCHES="${FOR_ALL_PROD}"
	F90BR_OS_PATCHES="${FOR_ALL_PROD}"
	PC_OS_PATCHES="${FOR_ALL_PROD} "
	PERFLIB_OS_PATCHES="${FOR_ALL_PROD}"
	SW_OS_PATCHES="${FOR_ALL_PROD}"
	SWADA_OS_PATCHES="${FOR_ALL_PROD} "
	TW_OS_PATCHES="${FOR_ALL_PROD}"
	TOOLH_OS_PATCHES="${FOR_ALL_PROD} "
	VISU_OS_PATCHES="${FOR_ALL_PROD} "
	LICENSE_OS_PATCHES="${FOR_ALL_PROD} "
fi
}

install_solaris2()
{
	if [ $prod_patch -eq 1 ]
	then
		for patch in $PATCHES
		do
			ret=0
			cd $USE_CURRENT_DIR
			if [ $confirm -eq 1 ]
			then
				message ""
				generic_answer "Install patch $patch?"
				if [ "$answer" = "n" -o "$answer" = "N" ]
				then
					continue
				fi
			fi
			if [ ! -d $USE_CURRENT_DIR/$PATCH_DIR/$patch ]
			then
				message ""
				message "***Cannot find patch $patch***"
				continue
			fi
			message ""
			message "Installing patch $patch"
			cd $USE_CURRENT_DIR/$PATCH_DIR/$patch

			if [ "${saveold}" != "" ]
			then
			    if [ "$rel_val" = "$SOS57" ]; then
				message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch ${saveold} -M $USE_CURRENT_DIR/$PATCH_DIR $patch"
				$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch "${saveold}" -M $USE_CURRENT_DIR/$PATCH_DIR $patch  2>&1
				ret=$?
			    else
				message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch ${saveold} $USE_CURRENT_DIR/$PATCH_DIR/$patch"
				$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch "${saveold}" $USE_CURRENT_DIR/$PATCH_DIR/$patch  2>&1
				ret=$?
			    fi

			        case $ret in
			        # These look like the right return codes  from
			        # installpatch to indicate success
			        0)
				        message ""
				        message "***Installation of Patch $patch was successful***"
				        ret=0;;
			        2) ret=0;;
			        6) ret=0;;
			        8) ret=0;;
			        *) ret=1
				        ;;
			        esac
			        if [ $ret -ne 0 ]
			        then
				        message ""
				        message "***Installation of Patch $patch FAILED***"
				        generic_answer "Do you want to continue installing remaining patches?"
				        if [ "$answer" = "n" -o "$answer" = "N" ]
				        then
					        break
				        fi
			        fi
			else
			    if [ "$rel_val" = "$SOS57" ]; then
				message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch -M $USE_CURRENT_DIR/$PATCH_DIR $patch"
				$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch -M $USE_CURRENT_DIR/$PATCH_DIR $patch  2>&1
				ret=$?
			    else
				message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch"
				$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch  2>&1
				ret=$?
			    fi

			        case $ret in
			        # These look like the right return codes  from
			        # installpatch to indicate success
			        0)
				        message ""
				        message "***Installation of Patch $patch was successful***"
				        ret=0;;
			        2) ret=0;;
			        6) ret=0;;
			        8) ret=0;;
			        *) ret=1
				        ;;
			        esac
			        if [ $ret -ne 0 ]
			        then
				        message ""
				        message "***Installation of Patch $patch FAILED***"
				        generic_answer "Do you want to continue installing remaining patches?"
				        if [ "$answer" = "n" -o "$answer" = "N" ]
				        then
					        break
				        fi
			        fi
			fi | tee -a $LOG
		done
	fi
	if [ $os_patch -eq 1 ]
	then
		for patch in $OS_PATCHES
		do
			ret=0
			is_mp_patch=0;

			cd $USE_CURRENT_DIR
			
			if [ $ret -eq 0 ]; then
				if [ $confirm -eq 1 -o $is_mp_patch -eq 1 ]
				then
					message ""
					generic_answer "Install patch $patch?"
					if [ "$answer" = "n" -o "$answer" = "N" ]
					then
						message ""
						continue
					fi
				fi
				if [ ! -d $USE_CURRENT_DIR/$PATCH_DIR/$patch ]
				then
					message ""
					message "***Cannot find patch $patch***"
					continue
				fi
				message ""
				message "Installing patch $patch"
				message "***This is a patch to the operating system and must be***"
				message "***installed on all machines where the software is to be used.***"

				cd $USE_CURRENT_DIR/$PATCH_DIR/$patch

				ret=0

				case $patch in
                                  # Solaris 7
        			  106300-05|106327-04|106328-04|107058-01)
				    patchadd -M $USE_CURRENT_DIR/$PATCH_DIR $patch > /tmp/$USER.ws_save.$$
                                    cat /tmp/$USER.ws_save.$$
                                    cat /tmp/$USER.ws_save.$$ >> $LOG
                                    rm -f /tmp/$USER.ws_save.$$

				    if [ $? -ne 0 ]; then
				      ret=1
				    fi;;
                                     
                                   105591-05|104678-03)
                                    # Solaris 2.6 
                                    patchadd  -p 2>/dev/null | grep SUNWlibC 2>/dev/null 2>&1 1>/dev/null
                                    if [ $? -eq 0 ]
                                     then
                                            #SUNWlibC has been patched. You need to remove it first
                                            pkgrm -n -a $USE_CURRENT_DIR/packages/.admin_file-noninter SUNWlibC 2>/dev/null
                                            pkgadd -d $USE_CURRENT_DIR/$PATCH_DIR/$patch/pkg SUNWlibC 2>/dev/null 1>/dev/null
                                            patchadd -M  $USE_CURRENT_DIR/$PATCH_DIR $patch 2>&1
                                     else
				            patchadd -M  $USE_CURRENT_DIR/$PATCH_DIR $patch 2>&1

                                            if [ $? -ne 0 ]; then
                                            ret=1
                                            fi
                                     fi
                                   ;;
                                   106529-03|106530-03)
                                   # solaris 2.5.1
                                    showrev -p 2>/dev/null | grep SUNWlibC 2>/dev/null 2>&1 1>/dev/null
                                    if [ $? -eq 0 ]
                                     then
                                            #SUNWlibC has been patched. You need to remove it first
                                            pkgrm -n -a $USE_CURRENT_DIR/packages/.admin_file-noninter SUNWlibC 2>/dev/null
                                            pkgadd -d $USE_CURRENT_DIR/$PATCH_DIR/$patch/pkg SUNWlibC 2>/dev/null 1>/dev/null
                                            message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch"
                                            $USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch 2>&1
                                     else
				            message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch"
				            $USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch 2>&1
				            ret=$?

			                    case $ret in
			        	    # These look like the right return codes from
				            # installpatch to indicate success
				            0)
					       message ""
					       message "***Installation of Patch $patch was successful***"
					       ret=0;;
			        	    2) ret=0;;
			        	    6) ret=0;;
			        	    8) ret=0;;
			        	    *) ret=1;;
			                    esac

                                     fi
			           ;;
                                   103801-07|103802-05)
                                   # solaris 2.5.1 y2k
				            message "$USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch"
				            $USE_CURRENT_DIR/$PATCH_DIR/$patch/installpatch $USE_CURRENT_DIR/$PATCH_DIR/$patch 2>&1
				            ret=$?

			                    case $ret in
			        	    # These look like the right return codes from
				            # installpatch to indicate success
				            0)
					       message ""
					       message "***Installation of Patch $patch was successful***"
					       ret=0;;
			        	    2) ret=0;;
			        	    6) ret=0;;
			        	    8) ret=0;;
			        	    *) ret=1;;
			                    esac
			           ;;
				esac

				if [ $ret -ne 0 ]; then
				  message ""
				  message "***Installation of Patch $patch FAILED***"
				  generic_answer "Do you want to continue installing remaining patches?"
				  if [ "$answer" = "n" -o "$answer" = "N" ]
				  then
				    break
				  fi
				elif [ "${os_okay}" -eq 1 ]; then
				  message ""
				  message "***Installation of Patch $patch has completed***"
				  message "***Remember to install this patch on all machines where the software is used***"
				fi
			fi
		done
	fi
		
	message "$INSTALL_COMPLETED"
	message "$LOGFILE_MESSAGE"
	message "$LOG"
}
install_solaris1()
{

	message "Solaris 1.x patch installation not supported"
	exit 1
}

message()
{
	/usr/bin/echo "$1" | tee -a $LOG
}

# Generic abort routine
call_abort()
{
	message " "
	message "PATCH INSTALLATION ABORTED"
	message " "
	# Remove admin files
	exit 1
}

# Generic answer routine
generic_answer()
{
	STRING=$1
	answer=
	while [ "$answer" != "y" -a "$answer" != "Y" -a "$answer" != "n" -a "$answer" != "N" ]
	do
             	/usr/bin/echo "$STRING [y,n] " | tr -d '\012' | tee -a $LOG
		read answer
		/usr/bin/echo $answer >> $LOG
	done
}

check_component()
{
	COMPONENT=$1
	NEW_PATCHES=""
	NEW_OS_PATCHES=""
	case "$COMPONENT" in
	   c++)	DESCRIPTION="Sun WorkShop Compilers C/C++ 5.0"
			NEW_PATCHES="${CPL_PATCHES}"
			NEW_OS_PATCHES="${CPL_OS_PATCHES}";;
	   tools)	DESCRIPTION="Bundled Developer Tools for SPARC/Solaris 7"
			NEW_PATCHES="${TOOLS_PATCHES}"
			NEW_OS_PATCHES="${TOOLS_OS_PATCHES}";;
	   y2k)	DESCRIPTION="sccs y2000 for Solaris 2.5.1"
			NEW_PATCHES="${Y2K_PATCHES}"
			NEW_OS_PATCHES="${Y2K_OS_PATCHES}";;
	     *)	message "ERROR, invalid option, $COMPONENT"
		#message "$USAGE"
		return 1;;
	esac
if [ "${OS}" = "${SOLARIS1}" ]
then
		DESCRIPTION_TOTAL="$DESCRIPTION_TOTAL$DESCRIPTION
"
else
		DESCRIPTION_TOTAL="$DESCRIPTION_TOTAL$DESCRIPTION\n"
fi
	for i in $NEW_PATCHES
	do
		found_pkg=0
		for j in $PATCHES
		do
			if [ "$i" = "$j" ]
			then
				found_pkg=1
				break
			fi
		done
		if [ $found_pkg -eq 0 ]
		then
			PATCHES="$PATCHES $i"
		fi
	done
	for i in $NEW_OS_PATCHES
	do
		found_pkg=0
		for j in $OS_PATCHES
		do
			if [ "$i" = "$j" ]
			then
				found_pkg=1
				break
			fi
		done
		if [ $found_pkg -eq 0 ]
		then
			OS_PATCHES="$OS_PATCHES $i"
		fi
	done
	return 0
}

component_input()
{
	message ""
	message "Specify 1 or more products for which patches should be installed, followed"
	message "by a carriage return. Type <help> for a list of valid products:"

	read ans

	if [ "${ans}" = "" ]
	then
# The case where no components have been selected
		return 2
	elif [ "${ans}" = "help" ]
	then

		cat << %%
Please enter in one of the following selection, separated by spaces 
and hit return. Patches are only required for the products listed below.
If you don't want to install patches for any products, hit return.

Please note that some of the products listed below may not be
available on your OS or platform.

Keyword       Product Component

c++     :     Sun WorkShop Compiler C/C++  5.0
tools   :     Bundled Tools Solaris 7
y2k     :     sccs Y2000 Solaris 2.5.1 

%%
		return 1
	else
		PATCHES=""
		OS_PATCHES=""
		for inp in $ans
		do
			check_component $inp
			if [ $? -ne 0 ]
			then
				return 1
			fi
		done
		return 0
	fi

}
#-------------------------------------------------------------------


# BEGIN SCRIPT, check for arguments and root
#The main body of the shell script

#####
#####
#####
trap "call_abort" 2

# global variables
USAGE="Usage: $0 [ -s < 1 | 2 > ] [ -d ] [ -o ] [ -p ] [ -c ] [ -l <patch_directory> ] [ c++ tools y2k ]"


CURRENT_DIR=`pwd`
PATCH_DIR="Patch"

INSTALL_COMPLETED="***Patch Installation Completed.***"
LOGFILE_MESSAGE="The log file for the installation can be found in "

#
# The OS_TYPE variable is used to determine which OS we are installing
# on. Normally, the OS is determined automatically by the presence of
# the /vmunix file (indicating Solaris_1.x)
# Note that the user can override this with the -o option as the first option
# on the command line to the wrapper, with the OS number as its argument
#
# Otherwise, the OS against which the install runs depends on
# the absence or presence of /vmunix (If the file is present, it means
# Solaris_1.x)
#

OS=""
SOLARIS1="4x"
SOLARIS2="5x"
INTEL_SOL2="i5x"

os_patch=0
prod_patch=0
saveold=""
confirm=0
USE_CURRENT_DIR=""
while [ $# -gt 0 ]
do
	case "$1" in
	-d) saveold="-d"
		shift
		;;
	-o) os_patch=1
		shift
		;;
	-p) prod_patch=1
		shift
		;;
	-c) confirm=1
		shift
		;;
	-l) shift
		if [ $# -le 0 ]
		then
			message "$USAGE"
		else
			USE_CURRENT_DIR=$1
			shift
		fi
		;;
	*) break
		;;
	esac
done

if [ "$USE_CURRENT_DIR" = "" ]
then
	USE_CURRENT_DIR="$CURRENT_DIR"
fi
if [ $os_patch -eq 0 -a $prod_patch -eq 0 ]
then
	os_patch=1
	prod_patch=1
fi

if [ "$OS" = "" ]
then
	if [ -f /vmunix ]
	then
		OS="${SOLARIS1}"
	else
		# What architecture?
		PLT=`uname -p`
		if [ ${PLT} = "sparc" ]; then
			OS="${SOLARIS2}"
		elif [ ${PLT} = "i386" ]; then
			OS="${INTEL_SOL2}"
		else
			# Shouldn't get here
			OS="${SOLARIS2}"
		fi
	fi
fi

# root test for 4.x and 5.x is different
# Do this before setting the log file, because if we attempt to set the
# log file and we are not root, then we get some nasty errors that
# are tough to read.

if [ "${OS}" = "${SOLARIS1}" ]
then
# 4.x test
#	Indicate that we don't support patch install for 4.x and exit

	message "Patch Installation not supported for Solaris 1.x - Exiting"
	exit 1
	DF="df"
	ret=`whoami`
	if [ "$ret" != "root" ]
		then
		/usr/bin/echo " "
		/usr/bin/echo "ERROR You must be root to install the required patches"
		/usr/bin/echo " "
		exit 1
	fi
else
# 5.x test
	DF="df -k"
	if [ `id | sed -e 's/[^(]*(//' -e 's/).*//'` != root ]
	then
		/usr/bin/echo " "
		/usr/bin/echo "ERROR You must be root to install the required patches"
		/usr/bin/echo " "
		exit 1
	fi
fi

program=`basename $0`
tmpfile=/tmp/$program"_tmp".$$
SOS57="5.7"
LOG=/usr/tmp/$program"_log".$$
install -m 1777 -u sys -g sys -d /usr/tmp >/dev/null
rm -rf $LOG
if [ "${OS}" = "${SOLARIS1}" ]
then
	message "install_required_patches Version vol6num1 for Solaris 1.x"
else
	message "install_required_patches Version vol6num1 for Solaris 2.5.1, 2.6 or 7"
fi
message "DATE 	= `date`"
message "SYSTEM	= `/usr/bin/uname -a`"
message "LOG	= $LOG"
message " "
interactive_input=0
if [ $# -lt 1 ]
then
	interactive_input=1
fi

# Get the list of packages set up

	set_patches

PATCHES=""
OS_PATCHES=""
# Set variables and make temp directory
if [ ${interactive_input} -eq 1 ]
then
	while true
	do
		OTHER_DESCRIPTION=""
		PATCHES=""
		DESCRIPTION_TOTAL=""
		component_input
		save_stat=$?
		if [ ${save_stat} -eq 2 ]
		then
			message "No products selected for patch installation - Exiting"
			exit 1
		elif [ ${save_stat} -eq 0 ]
		then
			message "Patches should be installed for the following products:"
			message "$DESCRIPTION_TOTAL"
			generic_answer "Is this correct?"
			if [ "$answer" = "n" -o "$answer" = "N" ]
			then
				continue
			fi
			break
		fi
	done
	
	
else
	while [ $# -ge 1 ]
	do
		check_component $1
		if [ $? -ne 0 ]
		then
			message "$USAGE"
			rm -rf $LOG
			exit 1
			#shift
			#continue
		fi
		shift
	done

	message "Patches should be installed for the following products:"
	message "$DESCRIPTION_TOTAL"
fi

if [ $os_patch -eq 0 ]
then
	TOTAL_PATCHES="$PATCHES"
elif [ $prod_patch -eq 0 ]
then
	TOTAL_PATCHES="$OS_PATCHES"
else
	TOTAL_PATCHES="${PATCHES} ${OS_PATCHES}"
fi
found_patch=0
for patch in $TOTAL_PATCHES
do
	found_patch=1
done
if [ $found_patch -eq 0 ]
then
	message "The products selected do not require any patches - Exiting"
	exit 1
fi

if [ $prod_patch -eq 1 ]
then
	found_patch=0
	for patch in $PATCHES
	do
		if [ $found_patch -eq 0 ]
		then
			message ""
			message "The following product patches will be installed:"
			message ""
		fi
    	found_patch=1
		echo_patch $patch
	done
	if [ $found_patch -eq 0 ]
	then
			message ""
			message "No product patches to install"
			message ""
	fi
else
	message "Only OS patches are being installed"
fi

if [ $os_patch -eq 1 ]
then
	found_patch=0
	for patch in $OS_PATCHES
	do
		if [ $found_patch -eq 0 ]
		then
			message ""
			message "The following OS patches will be installed:"
			message ""
		fi
    	found_patch=1
		echo_patch $patch
	done
	if [ $found_patch -eq 0 ]
	then
			message ""
			message "No OS patches to install"
			message ""
	fi
else

	message "Only product patches are being installed"
fi

if [ $confirm -eq 1 ]
then
	message ""
	message "You will be asked for confirmation before each patch is installed"
	message ""
fi

if [ "${OS}" != "${SOLARIS1}" ]; then
	install_solaris2
else
	install_solaris1
fi
exit 0
