Updated integrity check: added option to compare two integrity files.

This commit is contained in:
Sancho Lerena 2014-09-24 19:46:43 +02:00
parent 5c5af03584
commit 6b3019ec61
1 changed files with 61 additions and 3 deletions

View File

@ -19,9 +19,9 @@ if [ $# -lt 2 ]
then
echo "Syntax:"
echo " "
echo "integrity_chech new|check <path_to_console> [<path_to_integrity_file]>"
echo "integrity_chech new|check|compare [<path_to_console>] [<path_to_integrity_file>] [<path_to_integrity_file_2>]"
echo " "
echo " If mode 'check' is selected, it will require a integrity file (generated by this tool) to check it against current setup"
echo " If mode 'check' is selected, it will require a integrity file (generated by this tool) to check it against current setup. If mode 'compare' is selected, it wil require two integrity files, and will report differences between them"
echo " "
exit -1
fi
@ -32,12 +32,70 @@ INTEGRITY_REPORT=$INTEGRITY_FILE.report
MODE=$1
ERROR=0
if [ ! -d "$CONSOLE_PATH" ]
if [ ! -d "$CONSOLE_PATH" ] && [ "$MODE" != "compare" ]
then
echo "Error: Console path doesn't exist"
exit -1
fi
if [ "$MODE" == "compare" ]
then
FILE1=$2
FILE2=$3
if [ ! -f "$FILE1" ] || [ ! -f "$FILE2" ]
then
echo "Error, at least one of the integrity files provided not found"
exit -1
fi
IFS="
"
COUNTER=0
for a in `cat $FILE1 | grep -v "^#"`
do
if [ $COUNTER -eq 0 ]
then
echo -ne "\b|"
fi
if [ $COUNTER -eq 1 ]
then
echo -ne "\b/"
fi
if [ $COUNTER -eq 2 ]
then
echo -ne "\b-"
fi
if [ $COUNTER -eq 3 ]
then
echo -ne "\b\\"
COUNTER=-1
fi
COUNTER=`expr $COUNTER + 1`
F1=`echo $a | awk '{ print $2 }'`
M1=`echo $a | awk '{ print $1 }'`
BUF=`cat $FILE2 | grep "$F1\$"`
if [ -z "$BUF" ]
then
echo " "
echo "[MISS] $F1 is not present in $FILE2"
else
M2=`echo $BUF | awk '{ print $1 }'`
if [ "$M2" != "$M1" ]
then
echo " "
echo "[DIFF] $F1 has changed"
fi
fi
done
fi
if [ "$MODE" == "check" ]
then
if [ ! -f "$INTEGRITY_FILE" ]