#!/bin/sh

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

unset MAILFROM
unset MAILTO
unset MY_HOSTID
unset PARTICIPATE

# get configuration information
. /usr/share/popularity-contest/default.conf
. /etc/popularity-contest.conf

# don't run if PARTICIPATE is "no" or unset!
[ "$PARTICIPATE" = "no" ] || [ -z "$PARTICIPATE" ] && exit 0

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

run_popcon()
{
	# Set HOME to avoid bug #212013.
	HOME=/tmp su nobody -pc "sh -c /usr/sbin/popularity-contest"
}

# generate and transmit the popularity contest data

run_popcon \
	| tee /var/log/popularity-contest \
	| /usr/sbin/popcon-upload >/dev/null 2>&1
