#!/bin/sh
#
# Name: check_cdbs
#
# Description: Does consistency checks against the CDBS_DB content,
#              looking for potential problems.
#
# Called by:   deliver_cdbs.s
#
# Returns: 0 - if no errors are found
#          1 - if errors are found
#
#--------------------------------------------------------------------------
export CDBS_DB CDBS_SERVER
echo "starting check_cdbs "
echo "database " ${CDBS_DB?"CDBS_ERROR: CDBS_DB is undefined"}
echo "server " ${CDBS_SERVER?"CDBS_ERROR: CDBS_SERVER is undefined"}
date
dn=`get_current_delivery_number.s $CDBS_DB | awk '/^ *[0-9]/{print $1}'`
#
if test $# -lt 1
then
  cc_check_cdbs.s check_cdbs_$dn.out
else
  cc_check_cdbs.s check_cdbs_$dn.out $1
fi
echo " "
echo "output file check_cdbs_$dn.out created"
nwarn=`grep 'WARN' check_cdbs_$dn.out | wc -l` 
if test $nwarn -gt 0
then
   echo "$nwarn warning(s): see output file check_cdbs_$dn.out"
else
   echo "No warnings."
fi
nerr=`grep 'ERROR' check_cdbs_$dn.out | wc -l` 
if test $nerr -gt 0
then
   echo "$nerr error(s): see output file check_cdbs_$dn.out"
   exit 1
else
   echo "No errors."
   exit 0
fi
