#!/usr/bin/sh
#  @(#) Program name: AcquirePatches
#  @(#) Created:      04/11/02
#  @(#) Revision:     1.1, Modified: 02/12/03 , added front end
#  @(#) Revision:     1.2, Modified: 03/11/03 , added Datastore
#  @(#) Revision:     1.3, Modified: 07/26/06 , added Linux and HP-UX Datastore

PrintUsage() {
   print "\n\tusage: $0 [-S] [-c] [-s] [-w] [-p] [-dh] [-dl]\n"
   print "\twhere\n\n\tdefault:  Build audit for all processor types, most recent Fileset Revisions per Product only"
   print "\t -S:  Show all Fileset Revisions per Product"
   print "\t -c:  Build audit for Central Server"
   print "\t -s:  Build audit for site processors"
   print "\t -w:  Build audit for application servers and workstations"
   print "\t -p:  Build audit for probe processors"
   print "\t-dh:  Build audit for HP-UX datastore processors"
   print "\t-dl:  Build audit for Linux datastore processors\n"
}

Conf=Configuration

BuildAudit() {
   Proc=$1; Type=$2; Msg1=$3; File1=$4; Msg2=$5; File2=$6; x=""
   if [ $Proc = "c" ] && [ -f $Conf/stripped.a ]; then
      x1=`cat $Conf/stripped.$Proc`;  x2=`cat $Conf/stripped.a`; x=$x1" "$x2
   else
      if [ -f $Conf/stripped.$Proc ]; then x=`cat $Conf/stripped.$Proc` ; fi
   fi

   if [ "$x" != "" ]; then   # check to see fi $x is greater than 0 bytes
     if [ ShowAll_FLAG -eq 1 ]; then 
        print $Msg1 "(showing all Fileset Revisions per Product)"
        ./AuditSwlisting -S $x > $File1
        print $Msg2 "(showing all Fileset Revisions per Product)"
        ./AuditSwlisting -S -p $Type $x > $File2
     else
        print $Msg1
        ./AuditSwlisting $x > $File1
        print $Msg2
        ./AuditSwlisting -p $Type $x > $File2
     fi
   fi
}

ShowAll_FLAG=0
Central_FLAG=0
Sites_FLAG=0
Apps_FLAG=0
Probes_FLAG=0
DataStoreHPUX_FLAG=0
DataStoreLinux_FLAG=0

if [ $# -eq 0 ]; then   # default: Build audits for all processors in acceSS7 system
   ShowAll_FLAG=0; Central_FLAG=1; Sites_FLAG=1; Apps_FLAG=1; Probes_FLAG=1; DataStoreHPUX_FLAG=1; DataStoreLinux_FLAG=1
elif [ $# -eq 1 ] && [ $1 = "-S" ]; then   # default: Build audits for all processors in acceSS7 system showing all Fileset Revisions per Product
   ShowAll_FLAG=1; Central_FLAG=1; Sites_FLAG=1; Apps_FLAG=1; Probes_FLAG=1; DataStoreHPUX_FLAG=1; DataStoreLinux_FLAG=1
fi

while [ $# -gt 0 ]                  # Start looking for optional arguments
do
   case $1 in
     -S) ShowAll_FLAG=1
         shift ;;
     -c) Central_FLAG=1
         shift ;;
     -s) Sites_FLAG=1
         shift ;;
     -w) Apps_FLAG=1
         shift ;;
     -p) Probes_FLAG=1
         shift ;;
    -dh) DataStoreHPUX_FLAG=1
         shift ;;
    -dl) DataStoreLinux_FLAG=1
         shift ;;
    -* ) PrintUsage
         exit ;;
     * ) PrintUsage 
         exit ;;
    -- ) shift
         break ;;
   esac
done

# if [ ShowAll_FLAG -eq 1 ]; then print "the value of ShowAll_FLAG = \"$ShowAll_FLAG\""; fi
# if [ Central_FLAG -eq 1 ]; then print "the value of Central_FLAG = \"$Central_FLAG\""; fi
# if [ Sites_FLAG -eq 1 ]; then print "the value of Sites_FLAG = \"$Sites_FLAG\""; fi
# if [ Apps_FLAG -eq 1 ]; then print "the value of Apps_FLAG = \"$Apps_FLAG\""; fi
# if [ Probes_FLAG -eq 1 ]; then print "the value of Probes_FLAG = \"$Probes_FLAG\""; fi
# if [ DataStoreHPUX_FLAG -eq 1 ]; then print "the value of DataStoreHPUX_FLAG = \"$DataStoreHPUX_FLAG\""; fi
# if [ DataStoreLinux_FLAG -eq 1 ]; then print "the value of DataStoreLinux_FLAG = \"$DataStoreLinux_FLAG\""; fi

for n in c s w p d.hpux d.linux
do
   if [ Central_FLAG -eq 1 ] && [ $n = "c" ]; then
      BuildAudit $n svr "Creating a7.txt" a7.txt "Creating a7_patch.txt" a7_patch.txt; fi
   if [ Sites_FLAG -eq 1 ] && [ $n = "s" ]; then
      BuildAudit $n ste "Creating sites.txt" sites.txt "Creating sites_patches.txt" sites_patches.txt; fi
   if [ Apps_FLAG -eq 1 ] && [ $n = "w" ]; then
      BuildAudit $n wst "Creating work.txt" work.txt "Creating work_patches.txt" work_patches.txt; fi
   if [ Probes_FLAG -eq 1 ] && [ $n = "p" ]; then
      BuildAudit $n prb "Creating probes.txt" probes.txt "Creating probes_patches.txt" probes_patches.txt; fi
   if [ DataStoreHPUX_FLAG -eq 1 ] && [ $n = "d.hpux" ]; then
      BuildAudit $n dsp "Creating dsp_hpux.txt" dsp_hpux.txt "Creating dsp_hpux_patches.txt" dsp_hpux_patches.txt; fi
   if [ DataStoreLinux_FLAG -eq 1 ] && [ $n = "d.linux" ]; then
      BuildAudit $n dsp "Creating dsp_linux.txt" dsp_linux.txt "Creating dsp_linux_patches.txt" dsp_linux_patches.txt; fi
done

