#!/bin/sh
#-------------------------------------------------------------------------------
# genUpgradeListForBackup.sh
#
# This shell script is invoked during boot processing to generate a list of
# files that are contained in each save upgrade data archive file.  First
# invocation ($1 = 0) indicates to start a new list.  Each subsequent call
# to this routine will concatenate to this list (/opt/hsc/data/backupUpgradeList)
# See 'backuphdr' script processing.
#
# Usage: backuphdr <tar acrhive filename> <invocation sequence#>
#
# Return Codes: Not applicable since no recovery/logging processing can be
#  done from the calling routine (RestoreUpgradedata.java)

#-------------------------------------------------------------------------------
# directory and filename which records the backup actions.
#-------------------------------------------------------------------------------
LOGDIR=/var/hsc/log
LOG=$LOGDIR/genUpgradeListForBackup.log

LOG_ERROR_LOG=/tmp/genUpgradeListForBackup.log

# backuphdr script is looking for this specific filename
OUTFILE=/opt/hsc/data/backupUpgradeList

#-------------------------------------------------------------------------------
# the filename of the save upgrade archive filename
#-------------------------------------------------------------------------------
ARCHIVE=$1

#-------------------------------------------------------------------------------
# sequence number
#-------------------------------------------------------------------------------
SEQ_NUM=$2


# Check if the directory for the log file exists.
if [ ! -d $LOGDIR ]; then
   echo "=================================================================" > $LOG_ERROR_LOG
   echo -e "genUpgradeListForBackup task log for `date`." >> $LOG_ERROR_LOG
   echo "genUpgradeListForBackup task log directory, <$LOGDIR>, does not exist. Program exiting" >> $LOG_ERROR_LOG
   exit 1
fi

# Start log to record backup actions.
echo -e "genUpgradeListForBackup log for `date`.\n" > $LOG


#
# Simply invoke the tar command to list the archive data and create/append
# to output file.  Create new file only if first invocation ($SEQ_NUM=0)
#
if [ $SEQ_NUM -eq 0 ]; then
   echo -e "genUpgradeListForBackup log for `date`.\n" > $LOG
   echo -e "now processing archive file: $ARCHIVE" >> $LOG
   tar -tf $ARCHIVE > $OUTFILE
   tarRC=$?
else
   echo -e "genUpgradeListForBackup log continuing...\n" > $LOG
   echo -e "now processing archive file: $ARCHIVE" >> $LOG
   tar -tf $ARCHIVE >> $OUTFILE
   tarRC=$?
fi

echo "genUpgradeListForBackup task completed on `date`." >> $LOG
exit $tarRC
