#!/bin/sh

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

# get configuration information
. /etc/popularity-contest.conf

# don't run if MAILTO address is blank!
if [ -z "$MAILTO" ]; then
	exit 0
fi

# keep old logs
cd /var/log
umask 022
savelog -c 7 popularity-contest >/dev/null

# generate and transmit the popularity contest data
( echo 'Subject: popularity-contest submission';
  echo;
  popularity-contest ) \
  	| tee /var/log/popularity-contest \
  	| sendmail -oi "$MAILTO"
