#!/bin/sh
#
# File: /etc/cron.daily/ftpmirror
# Description: Cron script to save a log of ftpmirror tasks.
# Author: Dario Minnucci <debian@midworld.net>
# 

CONFIG_DIR=/etc/ftpmirror
LOG_FILE=/var/log/ftpmirror/ftpmirror.daily

#
# Don't run if this package is removed but not purged
#
if [ ! -f /usr/sbin/ftpmirror ]; then
    exit 0
fi


#
# Logging section
#
if [ -x /usr/bin/savelog ]; then
    savelog -c 7 -m 644 -u root -g root $LOG_FILE >/dev/null
fi

exec >$LOG_FILE 2>&1


#
# Get package list from /etc/ftpmirror/list.daily
#
PACKAGES=`cat ${CONFIG_DIR}/list.daily | grep -v '#'`

for i in $PACKAGES; do

    TIMESTAMP=`date +"%Y-%m-%d %H:%M:%S"`

    echo ""
    echo "---------------------------------------------------------"
    echo " $TIMESTAMP - Package to process: $i"
    echo "---------------------------------------------------------"

    # Process parsed package
    /usr/sbin/ftpmirror $i

done

exit 0
