#!/bin/bash
#
# Collect EED
#
# Description: Issue to Collect EED for the machinne
#
# Change Activity:
#   02/29/2004 Maui        - initial version
#   04/04/2004 Maui        - fix up the file processing
#   07/01/2004 Maui        - add the command info to the output
#   03/08/2005 Feustel     - make type-model and serial separate params, add pmap collection
#   05/03/2005 Feustel     - add VPD data collection
#   05/24/2005 Dovin       - on bpa/bpc reported errors limit EED collection
#   01/18/2006 Dovin       - add lslic -m xxxx -t syspower
#   05/11/2006 Dovin       - add lslic for BPA Reported if ownCEC exists
#   06/28/2006 Feustel     - only run VPD file generation if no new file for 30 days (553423)
#
#STARTUSAGE
#
# Usage:
#   collecteed -t machineTypeModel -s machineSerial -d directory
#
# Where:
#   -t   The machine type and model to collect the data for.  It must be of the format type*model
#
#   -s   The machine serial number to collect the data for.
#
#   -d   The directory to place the results into.  The results file will be called eed.results
#
#   -b   the reporting machine was a bpa, can't do all eed collection
#
#   -o   The machine type and model of the owning CEC for a BPA
#
#   -r   The machine serial number of the owning CEC for a BPA
#
#   -i   if true, generate VPD file instead of using existing one
#
#ENDUSAGE
#****************************************************************************
noopt=1
giveUsage=0

echo the parms are "$1"

# Parse the options
while getopts 't:s:d:b:i:o:r:?' optname; do
   case "$optname" in
      t) mtype="$OPTARG";;
      s) serial="$OPTARG";;
      d) directory="$OPTARG";;
      b) bpa="$OPTARG";;
      i) runinv="$OPTARG";;
      o) otype="$OPTARG";;
      r) oserial="$OPTARG";;
      \?) giveUsage=1; break;;
   esac
   noopt=0
done

# Have 2 different formats for MTMS for different commands
machine=${mtype}*${serial}
machUnder=${mtype}_${serial}

if [ "$giveUsage" -eq 1 ]; then
   # Print out the prologue comments as usage info
   sed -e '/STARTUSAGE/,/ENDUSAGE/ s/^#//' -e '1,/STARTUSAGE/ d' -e '/ENDUSAGE/,$ d' "$0"
   exit 0
fi

if [ "$noopt" -eq 1 ]; then
   # Print out the prologue comments as usage info
   sed -e '1 d' -e '2,/ENDUSAGE/ s/^#//' -e '/ENDUSAGE/,$ d' "$0"
   exit 0
fi


echo bpa was $bpa
echo runinv was $runinv

if [ $bpa == "true" ]; then
  echo "this was a bpa"
    echo "/opt/hsc/bin/lssyscfg -r cage"
    /opt/hsc/bin/lssyscfg -r cage -e $machine
    echo "/opt/hsc/bin/lssyscfg -r frame"
    /opt/hsc/bin/lssyscfg -r frame -e $machine

    # get the rest of the data
    echo "/opt/hsc/bin/lsdump -e $machine -s a && b"
    /opt/hsc/bin/lsdump -e $machine -s a
    /opt/hsc/bin/lsdump -e $machine -s b

  # create managed systems
  /opt/hsc/bin/lshsc -i -a  >> ${directory}managedSystems

  # owning system query
  if [ $otype ]; then
    if [ $oserial ]; then
      owningCEC=${otype}*${oserial}
      echo " about to do lslic -m ${owningCEC} -t systpower"
      /opt/hsc/bin/lslic -m ${owningCEC} -t syspower
    fi
  fi
else
  "echo this was not a bpa"
  # get the partition map
  echo "/opt/hsc/bin/lssyscfg -r lpar"
  /opt/hsc/bin/lssyscfg -r lpar -m $machine
  echo "/opt/hsc/bin/lshwres -r proc --level lpar"
  /opt/hsc/bin/lshwres -r proc -m $machine --level lpar
  echo "/opt/hsc/bin/lshwres -r mem -m $machine --level lpar"
  /opt/hsc/bin/lshwres -r mem -m $machine --level lpar
  echo "/opt/hsc/bin/lshwres -r io -m $machine --rsubtype slot"
  /opt/hsc/bin/lshwres -r io -m $machine --rsubtype slot
  # get the rest of the data
  echo "/opt/hsc/bin/lsdump -m $machine"
  /opt/hsc/bin/lsdump -m $machine
  echo "/opt/hsc/bin/lssyscfg -r sys -m $machine"
  /opt/hsc/bin/lssyscfg -r sys -m $machine
  echo "/opt/hsc/bin/lssyscfg -m $machine -r sys"
  /opt/hsc/bin/lssyscfg -m $machine -r sys
  echo "/opt/hsc/bin/lssyscfg -m $machine -r lpar"
  /opt/hsc/bin/lssyscfg -m $machine -r lpar
  echo "/opt/hsc/bin/lssyscfg -m $machine -r sysprof"
  /opt/hsc/bin/lssyscfg -m $machine -r sysprof
  echo "/opt/hsc/bin/lslic -m $machine -t syspower"
  /opt/hsc/bin/lslic -m $machine -t syspower
  # create partition map file
  echo "/opt/hsc/bin/lshsc -w -c${machUnder}" > ${directory}PMap.eed
  echo "--------------------------------------" >> ${directory}PMap.eed
  /opt/hsc/bin/lshsc -w -c${machUnder} >> ${directory}PMap.eed
  if [ $runinv == "true" ]; then
    # create new VPD file  /var/adm/invscout/<mtype>_<serial>.VPD.xml
    echo "/usr/sbin/invscout -v -m ${mtype} -s ${serial}"
    /usr/sbin/invscout -v -m ${mtype} -s ${serial}
  fi
  # copy to eed directory
  echo "copying VPD to ${directory}"
  rm ${directory}*.VPD.xml
  cp -p /var/adm/invscout/${machUnder}.VPD.xml ${directory}
fi



exit 0
