#!/bin/sh
#
# Script to verify a file's MD5 sum.  If it matches, it renames the file to
# the specified new name.

if [ $# -ne 3 ]; then
	logger -i -p local1.err -t 'verify' "[ERR] Wrong command line arguments"
	exit 1
fi

oldfile=$1
newfile=$2
sum=$3

# Verify the md5 sum of the old file
testsum=`md5 -q ${oldfile}`
if [ "${sum}" != "${testsum}" ]; then
	logger -i -p local1.warn -t 'rebuild' "[warn] Corrupt file ${oldfile}"
	rm -f ${oldfile}
	exit 3
fi

# File matched, so rename
mv $oldfile $newfile
