#!/bin/sh
# This script gathers together all of the appropriate packages of selected
# products and runs the .exe file of those packages with the SYS_CONFIG phase
# set.  Additionally, it sections out those packages that require root
# privilege and runs those first...  The algorithm:
# * Configure selected product(s):
#    For all selected products,
#	For all packages of the product,
#	    If the package has a .att file AND the CONFIGLEVEL is
#		    not NONE,
#		If the NEEDSROOT attribute is set to 1,
#		    Add the package to the list of configurations 
#			    needing root privileges (if not already
#			    on the list).
#		Otherwise,
#		    Add the package to the list of configurations
#			    not needing root privileges (if not already
#			    on the list).
#    Get a "root shell" running.
#    For all packages needing root privileges,
#	Execute the package's .exe script, with $phase set to 
#	    SYS_CONFIG.
#    Resume using "normal" shell.
#    For all packages not needing root privileges,
#	Execute the package's .exe script, with $phase set to
#	    SYS_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=''

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


# Set up environment:
if [ -z "$Proot" ]; then
  echo "$0 environment not initialized.
$0 This 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
rootPkgFile=$Proot/install/tmp/rootConfPkg.sh

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

gotPkg="false"
gotRootPkg="false"
for prod in $selProds; do
  # Assumes that if there is only one field in the line, it's a package name
  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 "CONFIGLEVEL=" $pkgAtt > /dev/null; then
        if grep "CONFIGLEVEL=NONE" $pkgAtt > /dev/null; then
          :
        else
          if grep "NEEDSROOT=1" $pkgAtt > /dev/null; then
            if [ "$gotRootPkg" = "false" ]; then
              echo '' > $rootPkgFile
              echo 'phase=SYS_CONFIG; export phase' >> $rootPkgFile
              echo "ARCHTYPE=`Archtype`; export ARCHTYPE" >> $rootPkgFile
              gotRootPkg="true"
            fi
            if grep "^# PACKAGE: $pkg\$" $rootPkgFile > /dev/null; then
              :
            else
              echo "# PACKAGE: $pkg" >> $rootPkgFile
              echo "PKGNAME=$pkg; export PKGNAME" >>$rootPkgFile
              echo "$BOURNE $Proot/install/pkgs/$pkg.exe $useGUI" >> $rootPkgFile
            fi
          else
            if [ "$gotPkg" = "false" ]; then
              echo '' > $pkgFile
              echo 'phase=SYS_CONFIG; 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
      fi
    fi
  done
done
if [ "$gotRootPkg" = "true" ]; then
  echo 'echo "Root privilege configuration completed."' >> $rootPkgFile
  echo "One or more of the products you specified require root access in"
  echo "order to be configured.  After you log in as root, execute the"
  echo "following command to configure those products:"
  echo "$BOURNE $rootPkgFile"
  echo ""
  cd $Proot
  su root
  echo ""
fi
if [ "$gotPkg" = "true" ]; then
  echo ""
  cd $Proot
  $BOURNE $pkgFile
  echo ""
fi
echo ""
echo "Product Configuration completed."
echo ""
rm -f $inFile $rootPkgFile $pkgFile
exit 0
