#!/bin/sh

#
#    make_pdtnok infile 
#
#	make_pdtnok is used to create products nok files and all the package
#	lines which should list in products nok file
#	
#############################################################################
#############################################################################
#
#	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=ibmrs
OSarchs=$OSvendor

test -z "$Rm" && Rm=/bin/rm;            export Rm

if [ -z "$Proot" ]; then  
    echo "$0 environment not initialized" 				1>&2
    exit 1 
fi
export Proot

if [ -z "$InstPlat" ]; then
  echo "$0 Installation platform not  specified"  1>&2
  exit 1
fi

export InstPlat


pdts=$Proot/install/pdts
pkgs=$Proot/install/pkgs
bundles=$Proot/install/tmp/bundles.${InstPlat}

infile=$1 ; shift

while read pdtdesc pkgname pdtname pdtsize platform FMrelease ; do
      pdtRoot="$pdts/${pdtname}_${platform}_${FMrelease}"
      if [ -s $bundles ]; then
         packages=`awk '$3 == "'$pdtname'" { print $2 }' $bundles | sort -u`
      else 	# if bundles not exists, use products nok file
         test -s $pdtRoot.nok && packages=`sed -n '2,$p' $pdtRoot.nok`
      fi
      for package in $packages ; do
  	  pkgfile=${pkgs}/${package}.ok	
          test -s ${pkgfile} && {
		test `egrep -c "^$pdtname" ${pkgfile}` -eq 0 && {
                echo $pdtname $platform $FMrelease >> ${pkgs}/${package}.ok
		}
                continue
          }
          echo $package $pdtname $platform $FMrelease
      done
      test -s ${pdtRoot}.nok && continue	
      echo "$pdtdesc pkgname $pdtname $pdtsize $platform $FMrelease" > ${pdtRoot}.nok
      packages=`awk '$1 == "'$pdtdesc'" { print $2 }' $bundles | sort -u`	
      for package in $packages ; do
          echo $package >> ${pdtRoot}.nok
      done	
done < $infile
