#!/bin/bash
#	Copyright 2007, IBM Corporation

#      fullIntegrityVerify.sh - Do master.sh, ghost items check, and bad blob reporting, 
#       for a given source catalog and all its associated collaboration areas catalogs.

#
# Usage 
if [[ $# -ne 5 ]]
then
 echo "Usage "
 echo "fullIntegrityVerify.sh --code=<cmp code> --ctg=<catalog name> --basic=<y/n> --wf=<y/n> --serialization=<y/n> "
 echo ""
 echo "Sample command line: fullIntegrityVerify.sh --code=trigo --ctg=MyCatalog  --basic=n --wf=y --serialization=y" 
 echo ""
  
 exit 0
fi
#Declare variable
CMPCODE=`echo $1 | cut -d "=" -f2`;export CMPCODE
CTGNAME=`echo $2 | cut -d "=" -f2`;export CTGNAME
RUNBASIC=`echo $3 | cut -d "=" -f2`;export RUNBASIC
RUNWF=`echo $4 | cut -d "=" -f2`;export RUNWF
RUNSER=`echo $5 | cut -d "=" -f2`;export RUNSER
if [ ${CCD_DB} = "db2" ]
then
    ./fullIntegrityVerifyDb2.sh --code=$CMPCODE --ctg=$CTGNAME --basic=$RUNBASIC --wf=$RUNWF --serialization=$RUNSER
    exit 0
fi
#ReportFile="${CtgID}`date |awk '{print "fullIntegrityVerify_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`.txt";export ReportFile
#ConsoleReportFile="${CtgID}`date |awk '{print "console_fullIntegrityVerify_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`.txt";export ConsoleReportFile
#
# initialize output file
#echo "" > ${ReportFile}
#
# Logging directory
#if [ "$TOP" ]
#then
#mkdir ${TOP}/logs  >>${ReportFile} 2>&1
#mkdir ${TOP}/logs/fullVerifyReports   >>${ReportFile} 2>&1
#else
#mkdir logs  >>${ReportFile} 2>&1
#mkdir logs/fullVerifyReports  >>${ReportFile} 2>&1
#fi 

# Run master.sh

curdir="`pwd`"
echo "===================================================================================================================="
echo ">>>> STARTING FULL INTEGRITY CHECK;  DIRECTORY IS $curdir <<<<<<<<<<"
echo "===================================================================================================================="
echo " "
if [ $RUNBASIC = 'y' ]
then
# get src connection descriptor
cd ../basic/oracle
echo "==============================================="
echo "NOW BASIC_INTEGRITY_VERIFY.SH"
echo "==============================================="

# Redundant, but matches with analagous redundant line that will be produced in ghost items and bad blobs runs
#echo "==============================================="
echo "DIRECTORY NOW IS `pwd`"
#echo "==============================================="

./basic_integrity_verify.sh --code=$CMPCODE

# Be sure we're in original working directory
cd $curdir
echo "================================================"
echo "DONE WITH BASIC_INTEGRITY_VERIFY.SH;  DIRECTORY NOW IS `pwd`"
echo "================================================"
echo " "
echo " "
echo " "
echo " "
fi

# Run ghostitems checks

# get src connection descriptor
if [ $RUNWF = 'y' ]
then
cd workflow/oracle
echo "==============================================="
echo "NOW RUNNING WORKFLOW INTEGRITY CHECKS"
echo "==============================================="

./workflow_integrity_verify.sh --code=$CMPCODE --ctg="$CTGNAME"
#./doreportall.sh --ctg="$CTGNAME"

# Go back to original working directory
cd $curdir
echo "================================================"
echo "DONE WITH WORKFLOW INTEGRITY CHECKS;  DIRECTORY NOW IS `pwd`"
echo "================================================"
echo " "
echo " "
echo " "
echo " "
fi


# Run dobadblob checks

# get src connection descriptor
if [ $RUNSER = 'y' ]
then
cd serialization/oracle
echo "==============================================="
echo "NOW RUNNING SERIALIZATIONINTEGRITYCHECKS"
echo "==============================================="

./serialization_integrity_verify.sh --code=$CMPCODE --ctg="$CTGNAME"
#./doreportbloball.sh --code=$CMPCODE --ctg="$CTGNAME"

# Go back to original working directory
cd $curdir
echo "================================================"
echo "DONE WITH SERIALIZATIONINTEGRITYCHECKS;  DIRECTORY NOW IS `pwd`"
echo "================================================"
echo " "
echo " "
echo " "
echo " "
fi


# save logs to proper location
#if [ "$TOP" ]
#then
#mv ${ReportFile}  ${TOP}/logs/fullVerifyReports
#mv ${ConsoleReportFile}  ${TOP}/logs/fullVerifyReports
#else
#mv ${ReportFile}  logs/fullVerifyReports
#mv ${ConsoleReportFile}  logs/fullVerifyReports
#fi    >>${ReportFile} 2>&1


echo "===================================================================================================================="
echo ">>>> FINISHED FULL INTEGRITY CHECK; DIRETORY NOW IS `pwd` <<<<<<<<<<"
echo "===================================================================================================================="
echo " "



# done
exit $?

