#!/bin/sh

file=`tempfile`
md5=`tempfile`
sha=`tempfile`

# This assumes the existance of three files:
# files - a list of files in the chroot
# md5sum - a list of md5 sum's of those files
# sha1sum -a list of sha1 sum's of those files
# they can be generated from a slight modification of the commands below.

find /home/singe/check -type f|grep -v sum > $file
find /home/elinks -type f >> $file
find /home/elinks -type l >> $file
cat $file|xargs -n1 md5sum > $md5
cat $file|xargs -n1 sha1sum > $sha

error=0
echo

echo "* Checking file lists"
diff files $file
if [ $? = 1 ]; then
	file_error="WARN: List of files differs"
	error=1
fi

echo "* Checking MD5 sums"
diff md5sum $md5
if [ $? = 1 ]; then
	md5_error="WARN: MD5 sums differ"
	error=1
fi

echo "* Checking SHA1 sums"
diff sha1sum $sha
if [ $? = 1 ]; then
	sha_error="WARN: SHA1 sums differ"
	error=1
fi

echo "* Performing virus scan"
clamscan --no-summary -ir /home/elinks
if [ $? = 1 ]; then
	clam_error="WARN: Virus found "
	error=1
fi
echo

if [ $error = 1 ]; then
	echo $file_error
	echo $md5_error
	echo $sha_error
	echo $clam_error
else
	rm $file $md5 $sha
	echo "GOOD"
fi

