#!/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin
export PATH

# configuration
dir=/var/local/security
sum=sha1sum

lastfp="fp.last"
today="`date +%Y%m%d`"
newfl="fl.$today"
newfp="fp.$today"

cd $dir

# make new footprint file
echo "Creating new footprint and filelist files."
echo "It's a good idea to back them up off-system."
echo
echo "For verification, their checksums (before compression) are:"
filelist >"$newfl"
$sum "$dir/$newfl"
footprint >"$newfp"
$sum "$dir/$newfp"

if [ -r "$lastfp" ]
then
	# get date of last footprint/filelist files
	last="`cat $lastfp`"
	# compare old and new footprint/filelist files
	echo
	tracker "$last" "$today"
fi

echo "$today" >"$lastfp"

# compress new footprint file
gzip -9 "$newfl" "$newfp"

# clean out footprint/filelist files older than a month
find "$dir" -name 'f[pl].[0-9]*' -mtime +30 -print | xargs rm -f
