#!/bin/sh
# DansGuardian logrotation script for version 2.12.0.0


LOG_DIR=/opt/local/var/log/dansguardian
NUM_LOGS=4
LOG=$LOG_DIR/access.log

/opt/local/sbin/dansguardian -q

# Keep a maximum of $NUM_LOGS logs around.
if [ -f $LOG.$NUM_LOGS ]; then rm -f $LOG.$NUM_LOGS; fi
n=$(( $NUM_LOGS - 1 ))
while [ $n -gt 0 ]; do
  if [ -f $LOG.$n ]; then
    mv $LOG.$n $LOG.$(( $n + 1 ))
  fi
  n=$(( $n - 1 ))
done
if [ -f $LOG ]; then
  mv $LOG $LOG.1
fi

sleep 5

/opt/local/sbin/dansguardian
