
#!/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 4 ]]
then
 echo "Usage "
 echo "fullIntegrityVerify.sh --code=<cmp code> --basic=<y/n> --wf=<y/n> --serialization=<y/n> "
 echo "For example to verify all the corruptions"
 echo "Sample command line: fullIntegrityVerify.sh --code=trigo --basic=y --wf=y --serialization=y" 
 echo "To verify only workflow corruptions"
 echo "Sample command line: fullIntegrityVerify.sh --code=trigo --basic=n --wf=y --serialization=n" 
 exit 0
fi

#Declare variable
CMPCODE=`echo $1 | cut -d "=" -f2`;export CMPCODE
RUNBASIC=`echo $2 | cut -d "=" -f2`;export RUNBASIC
RUNWF=`echo $3 | cut -d "=" -f2`;export RUNWF
RUNSER=`echo $4 | cut -d "=" -f2`;export RUNSER
DBName=`${GREP} '^ *db_url' ${CCD_ETC_DIR}/default/common.properties | ${SED} -e 's/^.*:\([^:]*\) *$/\1/' -e's/[0-9]*//' -e s_/__ -e 's/@//'`;export DBName
DBUser=`${GREP} '^ *db_userName' ${CCD_ETC_DIR}/default/common.properties | cut -f2 -d "="`;export DBUser
DBUserPassword=`${GREP} '^ *db_password' ${CCD_ETC_DIR}/default/common.properties | cut -f2 -d "="`;export DBUserPassword
echo $DBName
echo $DBUser
echo $DBUserPassword
#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 " "

# get src connection descriptor
#cd masterAndCleanup
if [[ $RUNBASIC = 'y' ]]
then
    cd ../basic/db2
    echo "==============================================="
    echo "NOW RUNNING BASIC INTEGRITY VERIFY.SH"
    echo "==============================================="

    # Redundant, but matches with analagous redundant line that will be prod    uced 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/db2
    echo "==============================================="

    echo "NOW RUNNING WORKFLOW INTEGRITY CHECKS"
    echo "==============================================="

    #./workflow_integrity_verify.sh db=$DBName --dbuser=DBUser --dbpassword=DBUserPassword --code=$CMPCODE
    ./workflow_integrity_verify.sh db=$DBName --dbuser=$DBUser --dbpassword=$DBUserPassword --code=$CMPCODE 

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


# Run dobadblob checks

# get src connection descriptor
if [ ${RUNSER} = 'y' ]
then
   
    cd serialization/db2
    echo "==============================================="
    echo "NOW RUNNING SERIALIZATION INTEGRITY CHECKS"
    echo "==============================================="
    echo $CMPCODE
    ./serialization_integrity_verify.sh --db=$DBName --dbuser=$DBUser --dbpassword=$DBUserPassword --code=$CMPCODE
    #./doreportbloball.sh --code=$CMPCODE

# Go back to original working directory
    cd $curdir
    echo "================================================"
    echo "DONE WITH SERIALIZATION INTEGRITY CHECKS;  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 $?

