#!/bin/sh
# vim: set sw=4 ts=4 et: 
# written by guido socher
ver="0.1"
logfile="/usr/local/spamy/tmp/sums.txt"
help()
{
    cat <<HELP
spamylogrotate -- rotate the log of spam checksums 

USAGE: spamylogrotate [-h] 

OPTIONS: -h this help

spamylogrotate rotate the $logfile but keeps always
the last 50 entries.

version $ver
HELP
    exit 0
}

error()
{
    echo "$1"
    exit 1
}
while [ -n "$1" ]; do
case $1 in
    -h) help;shift 1;;
    --) break;;
    -*) echo "error: no such option $1. -h for help";exit 1;;
    *)  break;;
esac
done

# input check:
[ -f "$logfile" ] || error "ERROR: file $logfile does not exist" 
filen="$logfile"
for n in  5 4 3 2 1; do
    if [ -f "$filen.$n" ]; then
        p=`expr $n + 1`
	    mv $filen.$n $filen.$p
    fi
done
if [ -f "$filen" ]; then
    cp $filen $filen.1
    tail -50 $filen.1 > $filen
fi
