#! /bin/sh
#
# radiusd-merit		Rotate the radiusd-merit logsfiles weekly.
#

[ -d /var/log/radiusd-merit/. ] || exit 0
umask 022

# Delete all the daily logfile more than a week old
cd /var/log/radiusd-merit
OLDLOG=`find . -name "logfile.*" -mtime +7 -print`
for LOGFILE in $OLDLOG; do
  rm $LOGFILE
done

# Keep a years worth of weekly copies of the accounting detail
# files for all the RADIUS terminal servers.
cd /var/log/radiusd-merit
LOGDIR=`find . -type d -print`
for DETAILDIR in $LOGDIR; do
  cd /var/log/radiusd-merit
  cd $DETAILDIR
  if [ -f detail ]
  then
    savelog -c 52 detail > /dev/null
  fi
done

# Send a reload signal to the radius server.
if [ -f /var/run/radiusd-merit.pid ]
then
  kill -1 `cat /var/run/radiusd-merit.pid` 2>/dev/null
fi

exit 0
