#!/bin/sh

# This script gathers together all of the appropriate packages of selected
# products and runs the .exe file of those packages with the TEST_INSTALL phase
# set.  The algorithm:
# * Assure selected product(s):
#    For all selected products,
#	For all packages of the product,
#	    If the package has a .att file AND TEST_INSTALL is set to 1,
#		Add the package to the list (if not already on the 
#			list).
#    For all packages on the list,
#	Execute the package's .exe script, with $phase set to 
#		TEST_INSTALL.
#############################################################################
#
#	Copyright (C) Cadence Design Systems, Inc. All rights
#	reserved.  Unpublished -- rights reserved under the
#	copyright laws of the United States of America.
#
#			RESTRICTED RIGHTS LEGEND
#	Use, duplication, or disclosure by the Government is subject
#	to restrictions as set forth in subparagraph (c)(l)(ii) of 
#	the Rights in Technical Data and Computer Software clause 
#	at DFARS 52.227-7013.
#
#			Cadence Design Systems, Inc.
#			555 River Oaks Parkway
#			San Jose, CA 95134	USA
#
#############################################################################
BOURNE=/bin/sh
XTERMPATH=/usr/openwin/bin
XTERMBIN=xterm
XTERMOPTS="-T 'SoftLoad 6.0 Console' -fn 9x15  -sl 200 -g 80x40+0+0 -bg \#e0e0e0 -fg \#800000 -sb -e ${BOURNE} softload_GUI"
sysPATH=/bin:/usr/bin:/usr/ucb:$XTERMPATH

jsr=''

OSvendor=sun4v
OSarchs=$OSvendor
Archtype() {
    echo $OSvendor
}



if [ -z "$Proot" ]; then
  echo "$0 environment not initialized.
$0 Can only be used when called from SoftLoad."                               1>&2
  exit 1
fi

# Set up environment:
inFile=$Proot/install/tmp/testProd.list
pkgFile=$Proot/install/tmp/testPkg.sh

selProds=`awk '{printf( "%s_%s_%s.ok ", $3, $5, $6 );}' $inFile`
rm -f $pkgFile

gotPkg="false"
for prod in $selProds; do
  # Assumes that if there is only one field in the line, it's a package nam
  prodPkgs=`awk '{ if (!$2) print $1 }' $Proot/install/pdts/$prod`
  for pkg in $prodPkgs; do
    pkgAtt=$Proot/install/pkgs/$pkg.att
    if [ -f $pkgAtt ]; then
      if grep "TEST_INSTALL=1" $pkgAtt > /dev/null; then
        if [ "$gotPkg" = "false" ]; then
          echo '' > $pkgFile
          echo 'phase=TEST_INSTALL; export phase' >> $pkgFile
          echo "ARCHTYPE=`Archtype`; export ARCHTYPE" >> $pkgFile
          gotPkg="true"
        fi
        if grep "^# PACKAGE: $pkg\$" $pkgFile > /dev/null; then
          :
        else
          echo "# PACKAGE: $pkg" >> $pkgFile
          echo "PKGNAME=$pkg; export PKGNAME" >> $pkgFile
          echo "$BOURNE $Proot/install/pkgs/$pkg.exe $useGUI" >> $pkgFile
        fi
      fi
    fi
  done
done
if [ "$gotPkg" = "true" ]; then
  echo "
Testing  selected products.
"
  cd $Proot
  $BOURNE $pkgFile
  echo ""
fi
echo ""
echo "Testing completed."
echo ""
rm -f $inFile $pkgFile
exit 0
