Compare commits

...

4 Commits

Author SHA1 Message Date
Bill Allombert cb37d0e362 Update changelog 8 years ago
Bill Allombert 1fa6d1b295 cron.daily: Add support for --crond option 8 years ago
Bill Allombert e01f902be4 generate a file /etc/cron.d/popularity-contest 8 years ago
Bill Allombert 0394909fad debian/cron.daily: Only update /var/log/popcon if submission was successful 8 years ago
  1. 12
      debian/changelog
  2. 24
      debian/cron.daily
  3. 15
      debian/postinst

12
debian/changelog

@ -1,4 +1,14 @@
popularity-contest (1.63) unstable; urgency=low
popularity-contest (1.63~pre2) unstable; urgency=low
* debian/cron.daily:
- Only update /var/log/popcon if submission was successful
- Add support --crond option
* debian/postinst:
- Generate a file /etc/cron.d/popularity-contest
-- Bill Allombert <ballombe@debian.org> Sun, 07 Jun 2015 17:28:42 +0200
popularity-contest (1.63~pre1) unstable; urgency=low
* Patches from Paul Wise:
- debian/changelog: fix some typos

24
debian/cron.daily

@ -6,6 +6,8 @@ if [ ! -f /usr/sbin/popularity-contest ]; then
exit 0
fi
MODE="$1"
unset MAILFROM
unset MAILTO
unset MY_HOSTID
@ -35,16 +37,22 @@ if [ -n "$HTTP_PROXY" ]; then
export http_proxy="$HTTP_PROXY";
fi
POPCON=/var/log/popularity-contest
POPCONOLD=/var/log/popularity-contest
POPCON=/var/log/popularity-contest.new
# Only run on the given day, to spread the load on the server a bit
if [ "$DAY" ] && [ "$DAY" != "$(date +%w)" ] ; then
# Ensure that popcon runs at least once in the last week
if [ -f "$POPCON" ] ; then
if [ -f "$POPCONOLD" ] ; then
now=$(date +%s)
lastrun=$(date -r $POPCON +%s)
# 6.5 days, in seconds
week=561600
lastrun=$(date -r $POPCONOLD +%s)
if [ "$MODE" = "--crond" ]; then
# 6.5 days, in seconds
week=561600
else
# 7.5 days, in seconds
week=648000
fi
if [ "$(( $now - $lastrun ))" -le "$week" ]; then
exit 0
fi
@ -109,11 +117,11 @@ fi
# try to email the popularity contest data
if [ yes != "$SUBMITTED" ] && [ "$MAILTO" ]; then
if [ "$MODE" = "--crond" ] && [ yes != "$SUBMITTED" ] && [ "$MAILTO" ]; then
if [ -x "`which sendmail 2>/dev/null`" ]; then
(
if [ -n "$MAILFROM" ]; then
echo "From: <$MAILFROM>"
echo "From: <$MAILFROM>"
echo "Sender: <$MAILFROM>"
fi
echo "To: $MAILTO"
@ -131,4 +139,6 @@ fi
if [ "yes" != "$SUBMITTED" ] ; then
logger -t popularity-contest "unable to submit report."
else
mv $POPCON $POPCONOLD
fi

15
debian/postinst

@ -39,8 +39,18 @@ select_random_day() {
DAY=`bash -c 'echo $(($RANDOM % 7))'`
}
generate_crond() {
MIN=`bash -c 'echo $(($RANDOM % 60))'`
HOUR=`bash -c 'echo $(($RANDOM % 24))'`
FILE=/etc/cron.daily/popularity-contest
cat > /etc/cron.d/popularity-contest <<EOF
SHELL=/bin/sh
$MIN $HOUR * * * root test -x $FILE && $FILE --crond
EOF
}
generate_conffile() {
generate_id
generate_id
generate_crond
select_random_day
cat <<-EOF >$conffile
# Config file for Debian's popularity-contest package.
@ -96,6 +106,9 @@ case "$1" in
select_random_day
echo "DAY=\"$DAY\"" >> $conffile
fi
if [ ! -f /etc/cron.d/popularity-contest ] ; then
generate_crond
fi
# Replace only if the content changed, to avoid changing the
# config file date when no change was done.

Loading…
Cancel
Save