cat > ck_sum.bff
#!/bin/ksh
#
# %Z%%M% %I% %W% %G% %U%

# set -x

#####################################################
#
# This is shipped with each release to Fix Central
#
# This file will be downloaed with each release
# on Fix Central.
#
# The customer can execute this file and verify
# that the downloaded files are all there and
# that their chsum value is correct for each file.
#
#####################################################
typeset SOURCEDIR=$1
typeset DESTPTH=/tmp
typeset INPUTFILE

if [ -f $DESTPTH/pd.sdd ]; then
rm -f $DESTPTH/pd.sdd
fi
if [ -f $DESTPTH/sdd.failure ]; then
rm -f $DESTPTH/sdd.failure
fi

########################################################
#
# gen_sum function
#
########################################################
gen_sum()
{
# set -x
awk ‘
BEGIN { RS=”<sdd-pd:Content\ “; FS=”<ds:”; filename=”/tmp/pd.sdd” }
{
# print “field_1:” $1
cnt = index($1,”pathname”)
if ( cnt != “0” )
{
n=split($1,a,”=”)
n2=split(a[3],b,”\””)
if ( b[2] != “” )
{
print b[2] > filename
}
}

cnt = index($1,”DigestValue>”)
if ( cnt != “0” )
{
n3=split($1,c,”>”)
if ( c[2] != “” )
{
print c[2] > filename
}
}

}’ $INPUTFILE
}

########################################################
#
# Compare function
#
########################################################

compare()
{
# set -x
exec 3<$DESTPTH/pd.sdd
while read -u3 -r line
do
gsa_file=$SOURCEDIR/$line
#
# is this an iFix
#
iFix=”false”
rc=`echo $gsa_file | grep epkg.Z`
if [[ -n $rc ]]; then
iFix=”true”
fi

unique_file=`echo $line | awk -F _ ‘{print $1}’`
# echo “Verify $line”
if [[ $unique_file = “VIOS” && \
$iFix != “true” ]]; then
read -u3 -r line
continue
fi

gsa_cksum=`cat $gsa_file | openssl dgst -sha1`

echo ” Verify cksum on $gsa_file ”
read -u3 -r sum
if [ $sum = “” ]; then
return 0
fi
if [ $sum = $gsa_cksum ]; then
# echo “SUM value: $sum”
continue
else
# echo “SUM value: $sum”
echo “CKSUM Failure on $gsa_file” >> $DESTPTH/sdd.failure
fi
done
}

###################################################
#
# main
#
# Description:
# Parse the sdd file, received from
# Fix Central, when you download an
# update and verifies that the cksum
# generated by Fix Central is the same
# as the cksum created against the same
# file, that resided in gsa.
# It is required that you run:
# fmtdata.setenv.vios
# first, to establish the correct directory
# paths.
#
# INPUTFILE=<file_name>.pd.sdd
# This is the sdd file received
# from Fix Central
# SOURCEDIR=$1
# This is the directory path to the
# individual update files in gsa
#
# DESTPTH=/tmp
# Used as temporary work space
# and placement for the failing results
# in /tmp/pd.sdd
#
###################################################
if [[ $1 = “” ]]; then
echo “Syntax:”
echo ” ck_sum.bff SOURCE_DIRECTORY”
echo ” ”
echo ” Example: ”
echo ” ck_sum.bff /home/padmin/update”
echo ” ”
exit 1
fi

ls -a $SOURCEDIR/*pd.sdd
if [ $? -ne 0 ]; then
echo “\n”
echo “Missing files, download is incomplete!\n”
exit 1
else
INPUTFILE=`ls -a $SOURCEDIR/*pd.sdd`
fi
gen_sum
compare
if [ -s $DESTPTH/sdd.failure ]; then
echo ” ”
echo ” All cksum failures are written to: ”
echo ” /tmp/sdd.failure ”
echo ” ”
cat /tmp/sdd.failure
else
echo “\n ”
echo “All VIOS update files, verified correctly.\n”
fi
exit 0

Syntax:
======
chmod 777 /home/padmin/ck_sum.bff
./ck_sum.bff /home/padmin/<VIO Package>

Example:
=======
chmod 777 /home/padmin/ck_sum.bff
./ck_sum.bff /home/padmin/VIOS_2.2.2.1-FP26
./ck_sum.bff VIOS_2.2.2.2-FP26_SP01

Advertisements