#!/bin/sh
# This script gathers together all of the appropriate packages of selected
# products and runs the .exe file of those packages with the USER_CONFIG phase
# set.  The algorithm:
# * Configure selected product(s):
#    For all selected products,
#	For all packages of the product,
#	    If the package has a .att file AND USER_CONFIG 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 
#		USER_CONFIG.
#############################################################################
#
#	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=''

# Set up environment:
if [ -z "$Proot" ]; then
  echo "$0 environment not initialized.
$0 can only be used when called from SoftLoad"                               1>&2
  exit 1
fi
inFile=$Proot/install/tmp/confProd.list
pkgFile=$Proot/install/tmp/confPkg.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 "USER_CONFIG=1" $pkgAtt > /dev/null; then
        if [ "$gotPkg" = "false" ]; then
          echo '' > $pkgFile
          echo 'phase=USER_CONFIG; export phase' >> $pkgFile
          gotPkg="true"
        fi
        if grep "^# PACKAGE: $pkg\$" $pkgFile > /dev/null; then
          :
        else
          echo "# PACKAGE: $pkg" >> $pkgFile
          echo "$BOURNE $Proot/install/pkgs/$pkg.exe $useGUI" >> $pkgFile
        fi
      fi
    fi
  done
done
if [ "$gotPkg" = "true" ]; then
  echo ""
  echo "Product configuration starting."
  echo ""
  cd $Proot
  $BOURNE $pkgFile
  echo ""
fi
echo ""
echo "Product configuration completed."
echo ""
rm -f $inFile $pkgFile
exit 0
