#!/bin/sh
# This script determines which (if any) of the installed products meet the
# appropriate criterion for either the SYS_CONFIG, USER_CONFIG, or TEST_INSTALL
# phases of installation.  If a product meets the criterion, it is added to
# an output list.  Additionally, if no products meet the criterion, this script
# returns 1, else 0.
# * Determine appropriate products attributes:
#    For all installed products,
#	For all packages of the product,
#	    If the package has a .att file AND appropriate attributes are set,
#		The product should be included - add it to the list.
#############################################################################
#
#	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
#
#############################################################################
OSvendor=hppa
OSarchs=$OSvendor

# Set up environment:
returnStat=1
if [ -z "$Proot" ]; then
  echo "$0 environment not initialized"                               1>&2
  exit 1
fi
outFile=$Proot/install/tmp/product.list
if [ "x$1" = "x" ]
then
  echo "Usage: $0 [ SYS_CONFIG | USER_CONFIG | TEST_INSTALL ]"
  exit 2
fi
installPhase="$1"
rm -f $outFile

instProds=""
for thisArch in $OSarchs; do
  platProds=`ls $Proot/install/pdts/*_${thisArch}_*.ok 2>/dev/null`
  if [ "x$platProds" = "x" ]; then
    :
  else
    if [ "x$instProds" = "x" ]; then
     instProds="$platProds"
    else
     instProds="$instProds $platProds"
    fi
  fi
done
if [ "x$instProds" = "x" ]; then
  # No products installed!
  exit $returnStat
fi

for prod in $instProds; do
  # Assumes that if there is only one field in the line, it's a package name,
  # and that the product description is the first line of the file.
  prodDesc=`head -1 $prod`
  prodPkgs=`awk '{ if (!$2) print $1 }' $prod`
  for pkg in $prodPkgs; do
    pkgAtt=$Proot/install/pkgs/$pkg.att
    if [ -f $pkgAtt ]; then
      case "$installPhase" in
        "SYS_CONFIG" )
  	  if grep "CONFIGLEVEL=" $pkgAtt > /dev/null; then
  	    if grep "CONFIGLEVEL=NONE" $pkgAtt > /dev/null; then
              :
            else
              returnStat=0
              echo "$prodDesc" >> $outFile
	      break
            fi
          fi
          ;;
        "USER_CONFIG" )
	  if grep "USER_CONFIG=1" $pkgAtt > /dev/null; then
            returnStat=0
            echo "$prodDesc" >> $outFile
	    break
          fi
          ;;
        "TEST_INSTALL" )
	  if grep "TEST_INSTALL=1" $pkgAtt > /dev/null; then
            returnStat=0
            echo "$prodDesc" >> $outFile
	    break
          fi
          ;;
      esac 
    fi
  done
done
exit $returnStat
