#!/bin/sh
# fwlogwatch's daily cron job
# Copyright 2001 Alberto Gonzalez Iniesta <agi@agi.as>
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
# 
set -e
test $DEBIAN_SCRIPT_DEBUG && set -v -x

FWLOGWATCH=/usr/sbin/fwlogwatch
CONFIG=/etc/default/fwlogwatch
EXTRA_HEADER="Content-Type: text/plain"

test -x $FWLOGWATCH || exit 0
test -r $CONFIG || exit 0

# Source configuration generated from debconf's values
. $CONFIG

if [ "$CRON_EMAIL" = "none" ]; then
  exit 0
fi

OUTPUT=`$FWLOGWATCH $CRON_PARAMS`

(echo "$OUTPUT" | grep -q 'No valid time entries found') \
  && exit 0

(echo "$OUTPUT" | grep -q '<html>') \
  && EXTRA_HEADER="Content-Type: text/html"

echo "$OUTPUT" | /usr/bin/mail -a "$EXTRA_HEADER" -s "fwlogwatch daily news" $CRON_EMAIL

# vim:set ai et sts=2 sw=2 tw=0:
