| #!/bin/sh |
| |
| # Copyright 2007,2008 Duncan Findlay <duncf@debian.org> |
| # Copyright 2008-2019 Noah Meyerhans <noahm@debian.org> |
| |
| # This script does not do anything by default. If you are using systemd, |
| # invoke "systemctl enable --now spamassassin-maintenance.timer" to enable |
| # spamassassin's daily maintenance systemd timer. If you are not using |
| # systemd, or otherwise prefer to use cron for daily maintenance, set CRON=1 |
| # in /etc/cron.daily/spamassassin |
| |
| CRON=0 |
| |
| test -f /etc/default/spamassassin && . /etc/default/spamassassin |
| |
| test -x /usr/bin/sa-update || exit 0 |
| command -v gpg > /dev/null || exit 0 |
| |
| if [ "$CRON" = "0" ] ; then |
| exit 0 |
| fi |
| |
| # If the systemd timer is active, there's nothing else for us to do: |
| if [ -d /run/systemd/system ] && \ |
| systemctl is-enabled --quiet spamassassin-maintenance.timer; then |
| exit 0 |
| fi |
| |
| # If we're running under systemd, and we reach this point, then we can |
| # safely convert to the timer. If you'd rather run the daily |
| # maintenance task from cron, even if systemd is present, then create |
| # a file named /etc/spamassassin/skip-timer-conversion to avoid |
| # running this conversion. |
| if [ -d /run/systemd/system ] && [ ! -e /etc/spamassassin/skip-timer-conversion ]; then |
| echo "Converting /etc/cron.daily/spamassassin to systemd timer" | |
| logger -p mail.notice |
| systemctl enable spamassassin-maintenance.timer |
| systemctl start spamassassin-maintenance.service |
| exit 0 |
| fi |
| |
| # Sleep for up to 3600 seconds if not running interactively |
| if [ ! -t 0 ]; then |
| RANGE=3600 |
| number=`od -vAn -N2 -tu4 < /dev/urandom` |
| number=`expr $number "%" $RANGE` |
| sleep $number |
| fi |
| |
| exec /usr/sbin/spamassassin-maint |