#!/bin/sh
#############################################################################
#
#	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=''

LoginName() {	# who'd you log in as
    who am i | sed -e 's/[ 	].*//' -e 's/.*\!//'
}

UserName() {
    whoami
}





Dirname() {					#print argument minus leaf, or .
    case $1 in
	*/* )	echo $1 | sed 's@/[^/]*$@/@' ;;
	*)	echo "." ;;
    esac
}

Leafname() {					#print leaf
    case $1 in
	*/* )	echo $1 | sed 's@.*/@@' ;;
	*)	echo $1 ;;
    esac
}

Fullpath() {					#print rooted path to arg dir
    ( cd $1 && /bin/pwd |
	sed 's@^/tmp_mnt/@/@' )			#print automount access dir
}

Dirpath() {					#print rooted path to arg - leaf
    $jsr Fullpath `$jsr Dirname $1`
}

Suffix() {
    echo $1 | sed -n 's@.*\.@@p'
}

Prefix() {
    echo $1 | sed 's@\.[^.]*$@@'
}


FlInfo() {
    /bin/ls -ldL $*  |
	sed -e 's@^\(..........\)\([^ 	]\)@\1 \2@'	\
    ;
}
	
FlOwner() {
    $jsr FlInfo $* | awk '{print $3}'
}

FlGroup() {
    $jsr FlInfo $* | awk '{print $4}'
}

FlSize() {
    $jsr FlInfo $* | awk '{print $5}'
}

LinkName() {
    $jsr FlInfo $* | awk '{print $11}'
}

IsSymLink() {
    test -h $1
    return $?
}


DirentExists() {		#non-referencing symLinks included
    test -d $1 -o -f $1 || $jsr IsSymLink $1
    return $?
}
	
FlsNewer() {
    than=`echo $1 | sed 's@[/.]@\\\\&@g'`	#stick in backslashes to escape
    {
	echo ""					#in case none newer
	/bin/ls -Ldtr $* 
    } | sed -e '1,/^'$than'$/d' -e '/^'$than'$/d'
}

FlsOlder() {
    than=`echo $1 | sed 's@[/.]@\\\\&@g'`	#stick in backslashes to escape
    {
	echo ""					#in case none older
	/bin/ls -Ldt $* 
    } | sed -e '1,/^'$than'$/d' -e '/^'$than'$/d'
}


Clear() {
    clear		2>/dev/null	#beware of bad termcap entry
}

Page() {
    MORE=""  more
}

EchoN() {
    echo  "$*\c"
}

Beep() {
    tput bel		2>/dev/null
}

OSvendor=sun4v
OSarchs=$OSvendor
tapeDev=/dev/rst4


MAXTARBSZ=20

SetExport() {
    file=$1
    variable=$2
    entry=$3

    test -f $file || touch $file
    grep -s ${variable} ${file} 2>&1 > /dev/null

    if [  "$?" = 0 ]; then
        grep -v ${variable} ${file} > /tmp/infile$$
        cp /tmp/infile$$ ${file}
        rm /tmp/infile$$
    fi

    echo "${variable}=\"${entry}\" ; export ${variable}" >> $file
}

#This did not work for the -v flag. Fixed it so that it works fine
#now



Fgrepf() {		# fgrep -v filename
    vset=false
    Util="fgrep"
    opts=
    while test $# -gt 0 ; do
       case $1 in
          -egrep)
               Util="egrep"
               shift;;
          -v)
               opts="$opts `expr X$1 : '.\(.*\)'`"
               shift
               vset=true;;
          -*)
               opts="$opts `expr X$1 : '.\(.*\)'`"
               shift;;
           *)  break;;
       esac
    done

    patFl=$1
    srcFl=$2

    split -75 $patFl /tmp/split$$_

    for pat in /tmp/split$$_* ; do
      if $vset; then
       count=0
       $Util $opts -f $pat $srcFl > /tmp/srcTFL$$
       srcTFL="/tmp/srcTFL$$"
       for pat1 in /tmp/split$$_* ; do
        count=`expr $count + 1`
        $Util $opts -f $pat1 $srcTFL > /tmp/srcFL${count}$$
        srcTFL="/tmp/srcFL${count}$$"
        echo $count > /tmp/count$$
       done
       if [ -s /tmp/count$$ ]; then
        read count < /tmp/count$$
       fi  
       cat /tmp/srcFL${count}$$ | sort -n | uniq >> /tmp/resFL$$
       while [ "$count" -gt 0 ]; do
         rm -f /tmp/srcFL${count}$$
         count=`expr $count - 1`
       done
       rm -f /tmp/srcTFL$$
      else
        $Util $opts -f $pat $srcFl
      fi
    done | sort -n | uniq
    if $vset; then
      cat /tmp/resFL$$ | sort -u | sort -n | uniq
    fi
    rm -f /tmp/resFL$$ /tmp/count$$ /tmp/split$$_* 
    
}

mediaBlocking=$MAXTARBSZ
NL="
"

Exit()
{
   status=$1; shift
   files="$*"
   for file in $files; do
       test -f $file && rm $file
   done
   exit $status
} 


saveWO()
{
  wo=`cat ${tmpdir}/workorder.${InstPlat}`
  tarFName="${tmpdir}/cdsWO#${wo}#${InstPlat}#tar"
  mv $tmpdir/$cdsWorkOrder $tarFName

 }


Intr_Clean () {
   echo "${NL}Cleaning up...${NL}"
   rm -f ${tmpdir}/ctl_files_xtract*
   rm -f ${tmpdir}/tmpfl*
   rm -f ${tmpdir}/awk* ${tmpdir}/dels* ${tmpdir}/load* ${tmpdir}/pkginfo.ld*
   rm -f ${tmpdir}/totalSize* ${tmpdir}/mediaLoc*
   rm -f /tmp/df*
}

GUItrap () {
    echo ""
    echo "${NL}Current operation interrupted."
    echo "${NL}Type 'exit' to quit, anything else to proceed."
    echo "(Not all operations will continue from the point of interruption)"
    read byebye
    if [ "X$byebye" = "Xexit" ]; then
      $jsr Intr_Clean
      Exit 0 
    fi
}


if [ -z "$bin_dir" ]; then  #{
  bin_dir=$Proot/install/bin.$OSvendor; export bin_dir 
fi  #}

tmpdir=$Proot/install/tmp
pkginfo=$tmpdir/pkginfo.$InstPlat
vld="$BOURNE vld"
allsourceMedia=$Proot/install/tmp/allsourceMedia.$InstPlat
process_file=$bin_dir/process_file
recordFile=$Proot/install/.cdsloadrc.$OSvendor
tmpEmailOut=$Proot/install/.tmpEmailOut
cmndStat=/tmp/stat$$
InstPlatFile=$tmpdir/cdsInstPlat


#
# GUI MACRO
#

trap GUItrap 2

echo "$legalNotice

Leave this window open so that you can read
any messages from the installation process.

"

#This variable indicates whether we want to any form other than the
#main menu. If we want to go to another form the value of AnotherForm
#is changed to that forms number


AnotherForm=0;
proceed=true
while $proceed ; do  #{	
  # electronic distribution 
  tmpfl1=$tmpdir/tmpfl1_$$

  if [ "X$AnotherForm" = "X0" ]; then  #{
    configOpt=1; export configOpt 
    testOpt=1;   export testOpt
    loadOpt=1;   export loadOpt
    removeOpt=1; export removeOpt
    listOpt=1;   export listOpt
    defaultConfigOpt=0; 

    echo "${NL}Loading current installation history..." 1>&2
  
    if $BOURNE chk_attr SYS_CONFIG ; then : ; else
      if $BOURNE chk_attr USER_CONFIG ; then : ; else
        configOpt=0; export configOpt
      fi
    fi

    if $BOURNE chk_attr TEST_INSTALL ; then : ; else
      testOpt=0; export testOpt
    fi

    rm -f $tmpdir/product.list

    #This is for specifying whether configure products option has to be the
    #default or not

    if [ -f $tmpdir/defconfig.opt ]; then
      if grep "1" $tmpdir/defconfig.opt > /dev/null; then
      defaultConfigOpt=1;
    else
      defaultConfigOpt=0;
    fi
    else
      defaultConfigOpt=0;
    fi

    #remove the file generated by load_pkgs to store the configure flag

    rm -f $tmpdir/defconfig.opt
  fi  #}



  if [ "X$AnotherForm" = "X20" -o  "X$AnotherForm" = "X0" ]; then  #{
    getControlInfo="no"
    default_install="no" export default_install #will be used in bundle_fltr
    sselection=""
    default=2
    rm -f $tmpdir/workorders
    ls $tmpdir/cdsWO*#tar 2> /dev/null > $tmpdir/workorders
    if [ -s $tmpdir/workorders ]; then  #{
      default=1  #Workorder the default 
      WorkOrder=1;
    else
      WorkOrder=0; 
    fi  #}
  fi  #}


  if [ "X$AnotherForm" = "X0" ]; then  #{
    if [ "X$defaultConfigOpt" = "X1" -a "X$configOpt" = "X1" ]; then #{
      $BOURNE $bin_dir/toplevel.sh 0 11 "$loadOpt" "$removeOpt" "$configOpt" "$testOpt" "$listOpt" 
    else
      $BOURNE $bin_dir/toplevel.sh 0 20  "$loadOpt" "$removeOpt" "$configOpt" "$testOpt" "$listOpt"
    fi  #}
    sstatus=$?
  else
    sstatus=$AnotherForm
    AnotherForm=0;
  fi #} AnotherForm if statement

  case $sstatus in #{
    23 | 20 ) #Load or Update 

      DeviceTAPE=$tapeDev
      DeviceCD=/cdrom/cdrom0

      MediaType=CDROM
      test -s $recordFile && . $recordFile
        case $MediaType in  #{
          CDROM)   device=$DeviceCD;;
          TAPE)    device=$DeviceTAPE;;
        esac  #}

      MediaSet="CD#1"
      MediaLabel="CD#1"
      getCDError=0
      #We get the mount point of CD#1
      $BOURNE $bin_dir/toplevel.sh 5 "" "CD#1" $DeviceCD 1 > $tmpdir/MediaLoc$$ 
      case $? in  #{
        0 | 221)
         . $tmpdir/MediaLoc$$
         rm -f $tmpdir/MediaLoc$$
         SetExport $recordFile DeviceCD $DeviceCD
        ;;
        250 ) 
          getCDError=1
          AnotherForm=0
          $Rm $tmpdir/MediaLoc$$
        ;;
        * )
          getCDError=1
          AnotherForm=0
          $Rm $tmpdir/MediaLoc$$
        ;;
      esac  #}

      CDError=0
      
      if [ $getCDError -eq 0 ]; then #{
        MediaType=CDROM
        test -s $recordFile && . $recordFile
          case $MediaType in  #{
            CDROM)   device=$DeviceCD;;
            TAPE)    device=$DeviceTAPE;;
          esac  #}
  
        mediaSet="CDROM#1"
        mediaTxt="CD#1"
        mediaType="CDROM"
        mediaNum=1
        skipcheck_flag="skipcheck"
        if $BOURNE  $bin_dir/media_iface $$ open $DeviceCD $mediaSet $mediaNum $mediaType $skipcheck_flag ; then  #{
          #We read FS.0
          workDir=`pwd`
          mkdir /tmp/sl$$
          cd /tmp/sl$$
          if $BOURNE  $bin_dir/media_iface $$ xtract 0 ./install/tmp ; then #{
            allbundlesF=`/bin/ls /tmp/sl$$/install/tmp/allbundles.* 2>/dev/null`
            ctlbundlesF=`/bin/ls /tmp/sl$$/install/tmp/ctl_bundles.* 2>/dev/null`
            #Sample line out of the allbundles or ctl_bundles file
            #972:~SDLIN iccommonDoc95.04-p008 972 92808 sun4 9504
  
            if [ "X$allbundlesF" != "X" ]; then #{
              PlatF=`head -1 $allbundlesF | awk '{print $5}'`
              rel=`head -1 $allbundlesF | awk '{print $6}'`
            elif [ "X$ctlbundlesF" != "X" ]; then
              #ctl_bundles file can have lines
              PlatF=`cat $ctlbundlesF | awk ' { if (NF > 1) print $5 }' | sort -u`
              rel=`cat $ctlbundlesF | awk ' { if (NF > 1) print $6 }' | sort -u`
            #Here we need OSvendor as InstPlat is not defined
            elif [ -s ${tmpdir}/mksoftload.run ]; then
              PlatF=`cat ${tmpdir}/mksoftload.run`
              rel=`head -1 ${tmpdir}/allbundles.${PlatF} | awk '{print $6}'`
            else
              msg="${NL}Could not determine the platform or release${NL}from the files on CD#1."
              $BOURNE $bin_dir/msgDialog.sh "$msg"
              AnotherForm=0
              CDError=1
            fi #}
  
            if [ "X$PlatF" = "X" -o "X$rel" = "X" ]; then #{
              msg="${NL}Could not determine the platform or release${NL}from the files on CD#1."
              $BOURNE $bin_dir/msgDialog.sh "$msg"
              AnotherForm=0
              CDError=1
            else
              if [ -s $Proot/.FMrelease ]; then  #{
                CDS_Release=`head -1 $Proot/.FMrelease`
                if [ "X$CDS_Release" = "X$rel" ]; then #{
                  InstPlat=$PlatF ; export InstPlat
                  Release=$rel ; export Release
                else
                  msg="${NL}Error:The current installation hierarchy is for $CDS_Release release.${NL}CD#1 is for $rel release. ${NL}Cannot install $rel release in this hierarchy.${NL}"
                  $BOURNE $bin_dir/msgDialog.sh "$msg"
                  AnotherForm=0
                  CDError=1
                fi #}
              else #If the .FMrelease file does not exist dont bother
                InstPlat=$PlatF ; export InstPlat
                Release=$rel ; export Release
              fi #}
            fi #}
          else #If extract fails
            msg="${NL}Could not extract information from FS.0 of CD#1.${NL}Could not get platform or release information"
            $BOURNE $bin_dir/msgDialog.sh "$msg"
             AnotherForm=0
             CDError=1
          fi #}
          cd $workDir
          $Rm  -r /tmp/sl$$
          
          #If everything is OK here we show the README
          #and extract FS.0 into the installation hierarchy.

          if [ $CDError -eq 0 ]; then #{
            cd $Proot
            $jsr EchoN "${NL}${NL}Extracting installation information from CD#1.${NL}"
            $BOURNE  $bin_dir/media_iface $$ xtract 0 ./install/tmp 
            cd $workDir
            if [ -s ${DeviceCD}/README ]; then #{
              $BOURNE $bin_dir/msgDialog.sh QUES "${NL}Do you want to view the README file?${NL}"
              case $? in #{
                15) #Yes
                  msg="${NL}This is the readme file on CD#1.${NL}You can look this over or print it out for reference.${NL}Click OK to proceed, Cancel to return to Main Menu.${NL}"
                  $BOURNE $bin_dir/toplevel.sh 24 "${DeviceCD}/README" "$msg" 
                  case $? in #{
                    51) ;;
                    52) #Cancel Go back to main menu
                      CDError=1
                      AnotherForm=0
                    ;;
                  esac #}
                  ;;
                16) #No
                  ;;
              esac #}
            fi #}If there is a README file
          fi #}If CDError=0

          $BOURNE $bin_dir/media_iface $$ close
        else  #If open media fails
          msg="${NL}Could not access CD#1 at ${NL} $DeviceCD.${NL}"
          $BOURNE $bin_dir/msgDialog.sh "$msg"
          AnotherForm=0
          CDError=1
        fi #}
      fi #} getCDError

      if [ $getCDError -eq 0 -a $CDError -eq 0 ]; then #{
        
        if $BOURNE $bin_dir/read_label $DeviceCD $mediaNum  > /tmp/label$$; then #{
          . /tmp/label$$
          if [ "X$updateUniq"  = "X" ]; then #{
            updateMedia=false
          else
            updateMedia=true
          fi #}
          mountedCD=$dataTapeset
          export mountedCD
          $Rm  /tmp/label$$
        fi #}
        if [ "X$sstatus" = "X23" ]; then #{
          AnotherForm=25
        else
          AnotherForm=26
        fi #}
      fi #}
      ;;
     25) 
          getControlInfo="yes" # We go on to load products
          AnotherForm=56
          sselection=6; export sselection
      ;;
      26) #If user chooses to load products
          EmailFile=
          grayCadenceCatalog=0
          grayDocCatalog=0
 
          $BOURNE $bin_dir/toplevel.sh 1 "$default" "$WorkOrder"  "$DeviceTAPE" "$grayCadenceCatalog"  "$grayDocCatalog" > $tmpEmailOut
          sstatus=$?
          case $sstatus in   #{
            2) #emailFile
              sselection=2; export sselection
              test -s $tmpEmailOut && . $tmpEmailOut
              export EmailFile
              tmpWorkOrder=
              echo "${NL}Extracting installation information from $EmailFile ${NL}" 1>&2
              tmpWorkOrder=`$bin_dir/cdsudp $EmailFile`
    	      mystatus=$?
              case $mystatus in  #{
                0) #succeed
                  WorkOrder=`echo $tmpWorkOrder | sed 's@\.[^.]*\.[^.]*$@@'`
                  export WorkOrder
                  cdsWorkOrder="cds.$WorkOrder"; export cdsWorkOrder
                  mv $tmpWorkOrder $tmpdir/$cdsWorkOrder
                  # uncompress, untar cds.workOrder file
                  cd $Proot
                  cat $tmpdir/$cdsWorkOrder | $bin_dir/io_fltr x | $bin_dir/vtar xpBf - ./install 
                  cd $bin_dir
                  echo "${NL}Extraction of installation information from $EmailFile complete ${NL}"   1>&2
                  
                  if [ -s ${InstPlatFile} ]; then  #{
                    PlatF=`head -1 $InstPlatFile | awk '{ print $1}'`
                    if [ ! -z "$PlatF"  -a "X$InstPlat" = "X$PlatF" ]; then #{
                      if [ -f $tmpdir/ctl_bundles.${PlatF} -a \
                           -f $tmpdir/ctl_pkginfo.${PlatF} -a \
                           -f $tmpdir/ctl_mediaMap.${PlatF} ]; then #{
                        getControlInfo="yes"
                        AnotherForm=54  #Bring up the default/custom installation form
                        cd $Proot
                        $jsr  saveWO 
                        cd $bin_dir 
                      else
                        msg="${NL}    Corrupted or incompatible installation information in $EmailFile (ctl files) ${NL} ${CALLCRC}"
                        $BOURNE $bin_dir/msgDialog.sh "$msg"
                        #getControlInfo is still "no" here
    	                AnotherForm=20
                      fi  #}
                    else
                      msg="${NL}    Installation  platform not specified. ${NL}    Wrong format of cdsInstPlat file in $EmailFile ${NL}     OR Installation information is for $PlatF platform. CD#1 is for $InstPlat platform.${NL} ${CALLCRC}"
                      $BOURNE $bin_dir/msgDialog.sh "$msg" 
    	          AnotherForm=20
                    fi  #}
                  else
                    msg="${NL}    Corrupted or incompatible installation information in $EmailFile (cdsInstPlat) ${NL} ${CALLCRC}"
                   $BOURNE $bin_dir/msgDialog.sh "$msg"
                    #getControlInfo is still "no" here
    	        AnotherForm=20
                  fi  #}
    	 
                  ;;
                 2 | 14 | 16 | 4 | 6 | 12) #Can't open output file
                       msg="${NL}SL-3: Failed to decode e-mail file $EmailFile ${NL} ${NL} Unable to extract installation information from $EmailFile. Verify that this file contains the mail message from Cadence ${NL} and check whether you have necessary write permissions ${NL} to install_dir (Error: $mystatus) ${NL} " 
                   $BOURNE $bin_dir/msgDialog.sh "$msg"
                   getControlInfo="no"
    	       AnotherForm=20
                   ;;
                  8 | 10 | 18 | 20 | 22 | 24) #corrupted email file
                         getControlInfo="no"
    		     msg="${NL}SL-4: Corrupted e-mail file $EmailFile ${NL} ${NL} Unable to extract installation information from $EmailFile ${NL} Verify that this file contains the mail message from Cadence ${NL} and if this is the correct file, Call the Cadence Customer ${NL} Response Center (CRC) at 1-800-Cadenc2 (1-800-223-3622) ${NL} for assistance (Error: $mystatus). ${NL}"
                         $BOURNE $bin_dir/msgDialog.sh "$msg"
    	             AnotherForm=20
                      ;;
                   *) #corrupted email file
                         getControlInfo="no"
    		     msg="${NL}SL-5: Unable to extract installation information from $EmailFile ${NL} Verify that this file contains the mail message from Cadence ${NL} and if this is the correct file, Call the Cadence Customer ${NL} Response Center (CRC) at 1-800-Cadenc2 (1-800-223-3622) ${NL} for assistance. ${NL}"
                         $BOURNE $bin_dir/msgDialog.sh "$msg"
    	             AnotherForm=20
                      ;;
                  esac  #}
    	    ;;
            1) #work order
              sselection=1; export sselection
              $jsr EchoN "${NL}Generating list of available workorders ...${NL}"
              if [ -s $tmpdir/workorders ]; then  #{
                awk -F# '{ print $2 " " $3 }' $tmpdir/workorders > $tmpdir/wo_$$
                file1="${tmpdir}/wo_$$"
                file2="${tmpdir}/platforms"
    
                 awk '
                     FILENAME == "'$file1'" {
                       wo [ $1 " " $2 ] = $2
                     }
                 
                     FILENAME == "'$file2'" {
                       for ( i=2; i<=NF; i++)
                         plat[$1]=plat[$1]" "$i;
                     }
                     END {
                       for ( item in wo ) 
                       {
                         a=split(item,entry, " ");
                         printf("%-20s%-26s\n",entry[1], plat[wo[ item ]]);
                       }
                   }' $file1 $file2 > $tmpdir/wo1_$$
    
                   rm -f $tmpdir/wo_$$
    
                   $BOURNE $bin_dir/toplevel.sh 22 $tmpdir/wo1_$$
                   mystatus=$?
                   case $mystatus in  #{
                     250) AnotherForm=0;;
                     255) AnotherForm=26;; #back to where is inst info
                     *) lineNo=$mystatus
                       wofile=`sed -n "${lineNo},${lineNo}p" $tmpdir/wo1_$$ | awk '{print $1}'`
                       Plat=`sed -n "${lineNo},${lineNo}p" $tmpdir/wo1_$$ | awk '{print $2}'`
                       Plat1=`awk '{ if ($2 == "'$Plat'" ) print $1 }' $tmpdir/platforms`
                       wofile="cdsWO#${wofile}#${Plat1}#tar"
                       rm -f $tmpdir/wo1_$$
    
                       if [ ! -z "$wofile" ]; then  #{
                         wofile="${tmpdir}/${wofile}"
                       fi  #}
    
                       if [ -s $wofile ]; then #{
                         cd $Proot
                         $jsr EchoN "${NL}Extracting information from workorder....${NL}"
                         cat $wofile | $bin_dir/io_fltr x |  $bin_dir/vtar xpfB - ./install
                         cd $bin_dir
                         if [ -s $InstPlatFile ]; then  #{
                           PlatF=`head -1 $InstPlatFile | awk '{ print $1}'`
                           if [ ! -z "$PlatF" -a "X$InstPlat" = "X$PlatF" ]; then #{
                             if [ -f $tmpdir/ctl_bundles.${PlatF} -a \
                                -f $tmpdir/ctl_pkginfo.${PlatF} -a \
                                -f $tmpdir/ctl_mediaMap.${PlatF} ]; then #{
                               getControlInfo="yes"
                               AnotherForm=54  #Bring up the default/custom installation form
                             else #If bundles file not found
                               msg="${NL}    Corrupted installation information in workorder fille. ${NL}"
                               $BOURNE $bin_dir/msgDialog.sh "$msg" 
                               AnotherForm=20 #Go back to where is installation form
                             fi #}
                           else #If platform not correct
                             msg="${NL}    Installation  platform not specified. ${NL}    Wrong format of cdsInstPlat file in workorder file ${NL}     OR Installation information is for $PlatF platform. CD#1 is for $InstPlat platform. ${NL}${CALLCRC}"
                             $BOURNE $bin_dir/msgDialog.sh "$msg" 
                             AnotherForm=20 #Go back to where is installation form
                           fi #}
                               
                         else
                           msg="${NL}    Error: File not found: ${NL}     $InstPlatFile ${NL}"  1>&2
                           $BOURNE $bin_dir/msgDialog.sh "$msg" 
                           AnotherForm=20 #Go back to where is installation form
                         fi  #}
                       else
                         msg="${NL}    Error: Work Order file not found.${NL}"  1>&2
                         $BOURNE $bin_dir/msgDialog.sh "$msg" 
                         AnotherForm=20 #Go back to where is installation form
                       fi  #}
                       
                       rm -f $tmpdir/wo1_$$ 
                       ;;
                     esac  #}
                   fi  #}
            ;;
            3) #DeviceTAPE=tapeDevname
              sselection=3; export sselection
              test -s $tmpEmailOut && . $tmpEmailOut
              export DeviceTAPE
              SetExport $recordFile DeviceTAPE $DeviceTAPE
    
              mediaSet="Installation_Information_Tape"
              mediaNum=0
              mediaTxt="TAPE ${mediaSet}:$mediaNum"
              media_type="TAPE" 
              skipcheck_flag="skipcheck"
              if $BOURNE  $bin_dir/media_iface $$ open $DeviceTAPE $mediaSet $mediaNum $media_type $skipcheck_flag ; then  #{
                cd $Proot
   
                echo "${NL} Reading installation information from $DeviceTAPE .....${NL}"
                if $BOURNE $bin_dir/media_iface $$ xtract 0 ./install/tmp ./install/pdts ./install/pkgs ./install/IMAGES.DIR ; then  #{
                  if [ -s ${InstPlatFile} ]; then  #{
                    PlatF=`head -1 $InstPlatFile | awk '{ print $1}'`
                    if [ ! -z "$PlatF" -a "X$InstPlat" = "X$PlatF" ]; then #{
                      if [ -f $tmpdir/ctl_bundles.${PlatF} -a \
                                -f $tmpdir/ctl_pkginfo.${PlatF} -a \
                                -f $tmpdir/ctl_mediaMap.${PlatF} ]; then #{
                        getControlInfo="yes"
                        AnotherForm=54  #Bring up the default/custom installation form
                      else
                        msg="${NL}    Corrupted or incompatible installation information (ctl files) on inserted tape in $DeviceTAPE ${NL} ${CALLCRC}"
                        $BOURNE $bin_dir/msgDialog.sh "$msg" 
    	                AnotherForm=20
                      fi  #}
                    else
                      msg="${NL}    Installation  platform not specified. ${NL}    Wrong format of cdsInstPlat file on inserted tape in $DeviceTAPE ${NL}     OR Installation information is for $PlatF platform. CD#1 is for $InstPlat platform. ${NL}${CALLCRC}"
                      $BOURNE $bin_dir/msgDialog.sh "$msg" 
    	              AnotherForm=20
                    fi  #}
                  else
                    msg="${NL}    Corrupted or incompatible installation information (cdsInstPlat) on inserted tape in $DeviceTAPE ${NL} ${CALLCRC}"
                    $BOURNE $bin_dir/msgDialog.sh "$msg" 
    	            AnotherForm=20
                 fi  #}
               else
                 getControlInfo="no"
                 msg="${NL}   Error extracting installation information from tape in $DeviceTAPE. ${NL}    Specify the source of installation information again.${NL}"
                 $BOURNE $bin_dir/msgDialog.sh "$msg"
                 AnotherForm=20
               fi  #} media_iface xtract if stmt
               $BOURNE $bin_dir/media_iface $$ close
             else
               getControlInfo="no"
               msg="${NL}   Error accessing the tape in $DeviceTAPE. ${NL}    Specify the source of installation information again.${NL}"
               $BOURNE $bin_dir/msgDialog.sh "$msg"
               AnotherForm=20
             fi  #}
            ;;
            4 | 5) #cadence catalog or Doc Catalog
              if [ "$sstatus" -eq 4 ]; then  #{
                sselection=4; export sselection
              else
                if $updateMedia; then
                  sselection=7; export sselection
                else
                  sselection=5; export sselection
                fi
              fi  #}
              getControlInfo="yes" # We go on to load products

              AnotherForm=56
            ;;
            255) break;;
          esac   #}
     ;;
     54) #The Default/Custom installation form
        #We check whethere the customer is using the control
        #information for the update Media with the production
        #media

       prodPat="_64bit"
       defPrompt="Default Installation (install licensed 32-bit products automatically)"
       cusPrompt="Custom Installation (select licensed 32-bit and 64-bit products to install)"

       allbundles="$tmpdir/allbundles.${InstPlat}"
       ctlbundles="$tmpdir/ctl_bundles.${InstPlat}"

       #complain if any file is missing
       stopUser="no"
       if [ ! -s $allbundles -o ! -s $ctlbundles ]; then #{
          msg="${NL}Error: Could not locate files:${NL}${allbundles}${NL}${ctlbundles}"
          stopUser="yes"
          AnotherForm=0
       fi #}

       # Now we check for QSR/Production Infor mismatch
       if [ "X$stopUser" != "Xyes" ]; then #{
         numTSets=`awk '{ if ( $2 == "CDROM" ) print $1}' $tmpdir/ctl_mediaMap.${InstPlat} | awk -F: '{print $1}' | sort -u | wc -l`

         if [ "X$sselection" = "X1" ]; then #{
           w1="in"
           word="workorder"
         elif [ "X$sselection" = "X2" ]; then 
           w1="in"
           word="email"
         else
           w1="on"
           word="tape"
         fi #}

         if $updateMedia; then #{
           if [ $numTSets -eq 1 ]; then #{
             stopUser="yes"
             msg="It seems that the control information ${w1} this $word ${NL}can only be used with a production media. You cannot ${NL}continue the installation using the update (QSR/ISR) media.${NL}Install products ${w1} this ${word} using the appropriate ${NL}production media.${NL}${NL}"
           else #If -gt than 1 then check
             grep "${mountedCD}:1" $tmpdir/ctl_mediaMap.${InstPlat} 1>&2 > /dev/null
             if [ $? -ne 0 ]; then #{
               stopUser="yes"
               med=`cat $tmpdir/ctl_mediaMap.${InstPlat} | grep "_CD:1" | tail -1 | awk '{print $3 }' | tr '~' ' ' | awk '{print $1 " " $2 " " $3 " " $4 " " $5 " 1" }'`
               msg="${NL}It seems that the control information ${w1} this ${word} is for ${NL}${med}${NL}You are currently using ${mountedCD}${NL}Use the correct media to install products ${w1} this ${word}${NL}${NL}"
             fi #}
           fi #}
         else
           if [ $numTSets -gt 1 ]; then #{
             stopUser="yes"
             msg="It seems that the control information ${w1} this $word ${NL}can only be used with an update (QSR/ISR) media. You cannot ${NL}continue the installation using the production media.${NL}Install products ${w1} this ${word} using appropriate ${NL}update (QSR/ISR) media. ${NL}${NL}"
           else #If -gt than 1 then check
             grep "${mountedCD}:1" $tmpdir/ctl_mediaMap.${InstPlat} 1>&2 > /dev/null
             if [ $? -ne 0 ]; then #{
               stopUser="yes"
               med=`cat $tmpdir/ctl_mediaMap.${InstPlat} | grep "CDROM" | head -1 | awk '{print $3 }' | tr '~' ' ' | awk '{print $1 " " $2 " " $3 " " $4 " " $5 " 1" }'`
               msg="${NL}It seems that the control information ${w1} this ${word} is for ${NL}${med}${NL}You are currently using ${mountedCD}${NL}Use the correct media to install products ${w1} this ${word}${NL}${NL}"
             fi #}
           fi #}
         fi #}

       fi #}If stopUser not YES 

       if [ "X$stopUser" = "Xyes" ]; then #{
         $BOURNE $bin_dir/msgDialog.sh "$msg"
         AnotherForm=0
       fi #}

       if [ "X$stopUser" != "Xyes" ]; then #{
          #Now we check if there are any 64 bit products that
          #that are licensed
            
          awk '{print $3 }' $allbundles | sort -u > /tmp/allprds$$
          awk '{ if ( NF == 1 ) { print $1 "'$prodPat'" ; } 
                 else { print $3 "'$prodPat'" ; }
                }' $ctlbundles | sort -u > /tmp/ctlprds$$
   
          fgrep  -f /tmp/ctlprds$$ /tmp/allprds$$ 2>/dev/null 1>/tmp/availprds$$

          if [ $? -eq 0 ]; then #{Yes
            $BOURNE $bin_dir/toplevel.sh 23 "$defPrompt" "$cusPrompt"
          else
            $BOURNE $bin_dir/toplevel.sh 23
          fi #}
          defstatus=$?

          /bin/rm -f /tmp/allprds$$ /tmp/ctlprds$$

          case $defstatus in  #{
            231) default_install="yes" 
              export default_install
              AnotherForm=56;;  #Call vld -l
            232) default_install="no" 
              #Add corresponding 64 bit products to list
              /bin/cat /tmp/availprds$$ >> $ctlbundles
              export default_install

              /bin/rm -f /tmp/availprds$$
              AnotherForm=56;;  #Call vld -l


            255) AnotherForm=26;; #Back to installation information form
            250)AnotherForm=0;;
          esac  #};;
       fi #} #The last check for stop user

     ;;
    56)
      #Separated this is from the case 20. It becomes easier to go back
      #to previous forms etc.

      export sselection 
      if [ "X$sselection" != "X" -a "X$getControlInfo" = "Xyes"   ]; then  #{
        while : ; do #{
          checkControl=yes; export checkControl # check control for load option only
          CDS_INST_PLAT=$InstPlat
          export CDS_INST_PLAT InstPlat
          if [ "X$sselection" = "X6" ]; then #{
            vldFlag=-u
            if $updateMedia; then #{
              :
            else
              sselection=4; export sselection
            fi #}
          else
            vldFlag=-l
            if $updateMedia; then #{
              sselection=6; export sselection
            fi #}
          fi #}
          $vld "$vldFlag"
	  vldstatus=$?
          case $vldstatus in  #{
            222) #if he wants to reselect products 
                 #when disk_chk fails (call vld -l again) 
                 #If we have default installation change
                 #it to custom install
                 default_install="no"
                 export default_install
                 ;;
            250) break ;; #back to main menu
	    255) AnotherForm=0 
                 break #back to the installation medium menu
                 ;;
            201) #Media Required form returning The previous form was
                 #Default/Custom Install  
                 AnotherForm=54 #Pop up the default/custom form
                 break;;
            202) #Media Required form returning The previous form was
                 #Select Platform
                 AnotherForm=20 #Pop up the select Platform form
                 break;;
            *)   break;;
          esac  #}
        done  #}
      fi  #}end if sselection
      ;;

    21 | 22) #list installed and failed products.
      checkControl=no; export checkControl # check control for load option only
      if [ -s $tmpdir/platforms ]; then   #{
        $BOURNE $bin_dir/toplevel.sh 19 $tmpdir/platforms > $tmpdir/tmpplat
        platstatus=$?
        case $platstatus in  #{
          0)
            InstPlat=`head -1 $tmpdir/tmpplat`
            rm  -f $tmpdir/tmpplat
            CDS_INST_PLAT="$InstPlat"
            export CDS_INST_PLAT InstPlat
            if [ "$sstatus" -eq "21" ]; then  #{
              $vld -i
            else
              $vld -d
            fi  #}

            case $? in
              250)  ;; #back to main menu
              *)  ;;
            esac
            ;;
          * ) AnotherForm=0
             ;;
         esac  #} 
      else
        InstPlat="$OSvendor"
      fi  #}
      ;;
    11) #config
        if $BOURNE chk_attr SYS_CONFIG ; then : ; else
           actionOpt="noSystem"
        fi
        if $BOURNE chk_attr USER_CONFIG ; then : ; else
           actionOpt="noUser"
        fi
        rm -f $tmpdir/product.list      # clean up after chk_attr
        while : ; do
          $BOURNE $bin_dir/toplevel.sh 10 $actionOpt
          sstatus=$?

          case $sstatus in
            40) $BOURNE sconf_fltr
                case $? in
                  1 | 250) break;;
                esac
                ;;
            41) $BOURNE uconf_fltr
                case $? in
                  1 | 250) break;;
                esac
                ;;
            *) break;;
          esac
        done
        ;;
    12) #test
        $BOURNE tstinst_fltr
        case $? in
           *) ;;
        esac
        ;;
    250) Exit 1;;   #exit
  esac  #}
done  #}
