Question for cron für amavis/spamassassin ruleupdater

Discussion in 'ISPConfig 3 Priority Support' started by chico11mbit, May 31, 2017.

  1. chico11mbit

    chico11mbit Member

    Hallo,
    this cronjob is in cron.hourly. it handles the rule update from the services from heinlein and schaal.
    Unfortunately i am not firm with crons for spamassassin/amavis for ispconfig. could anyone check the syntax for me, especially the last part where the rules are downloaded?

    Code:
    #!/bin/sh
    
    # Duncan Findlay
    # [email protected]
    
    # Daily cronjob for SpamAssassin updates. This isn't pretty but it
    # should do the job.
    
    CRON=0
    
    test -f /etc/default/spamassassin && . /etc/default/spamassassin
    
    test -x /usr/bin/sa-update || exit 0
    test -x /etc/init.d/spamassassin || exit 0
    
    if [ "$CRON" = "0" ] ; then
        exit 0
    fi
    
    # If there's a problem with the ruleset or configs, print the output
    # of spamassassin --lint (which will typically get emailed to root)
    # and abort.
    die_with_lint() {
        su - debian-spamd -c "spamassassin --lint -D 2>&1"
        exit 1
    }
    
    do_compile() {
    # Compile rules if the required tools are available. Prior to version
    # 3.3.2-8, there was an additional check to verify that an sa-compile
    # run had previously been executed by hand. With sa-learn now
    # distributed in a separate, optional, package, this check is no
    # longer necessary.
        if [ -x /usr/bin/re2c -a -x /usr/bin/sa-compile ]; then
            su - debian-spamd -c "sa-compile --quiet"
            # Fixup perms -- group and other should be able to
            # read and execute, but never write.  Works around
            # sa-compile's failure to obey umask.
                chmod -R go-w,go+rX /var/lib/spamassassin/compiled
        fi
    }
    
    # Tell a running spamd to reload its configs and rules.
    reload() {
        # Reload
        if which invoke-rc.d >/dev/null 2>&1; then
            invoke-rc.d spamassassin reload > /dev/null
        else
            /etc/init.d/spamassassin reload > /dev/null
        fi
        if [ -d /etc/spamassassin/sa-update-hooks.d ]; then
            run-parts --lsbsysinit /etc/spamassassin/sa-update-hooks.d
        fi
    }
    
    # Sleep for up to 3600 seconds
    RANGE=3600
    number=`od -vAn -N2 -tu4 < /dev/urandom`
    number=`expr $number "%" $RANGE`
    sleep $number
    
    
    # Update
    umask 022
    su - debian-spamd -c "sa-update --gpghomedir /var/lib/spamassassin/sa-update-keys"
    retcode1=$?
    su - debian-spamd -c "sa-update --nogpg --channel spamassassin.heinlein-support.de"
    retcode2=$?
    su - debian-spamd -c "sa-update --nogpg --channel sa.schaal-it.net"
    retcode3=$?
    
    if [ $retcode1 -eq 0 ] || [ $retcode2 -eq 0 ] || [ $retcode3 -eq 0 ]; then
    retcode=0
    elif [ $retcode1 -eq 2 ] || [ $retcode2 -eq 2 ] || [ $retcode3 -eq 2 ]; then
    retcode=2
    else
    retcode=$retcode2
    fi
    
    case $retcode in
    0)
    # got updates!
    su - debian-spamd -c "spamassassin --lint" || die_with_lint
    do_compile
    reload
    ;;
    1)
    # no updates
    exit 0
    ;;
    2)
    # lint failed!
    die_with_lint
    ;;
    *)
    echo "sa-update failed for unknown reasons" 1>&2
    ;;
    esac
     
  2. florian030

    florian030 Well-Known Member HowtoForge Supporter

    You don't need the spamd-stuff. You can use a simple script: sa.schaal-it.net/sa-update
    To update Peer's rules, too just add
    Code:
    sa-update --nogpg --channel spamassassin.heinlein-support.de
    retval="$?"
    if [ $retval -eq 0 ]; then compile=1; fi
    
    before
    Code:
    if [ $compile -eq 1 ]; then
     
  3. chico11mbit

    chico11mbit Member

    you mean i can i can replace the whole script with yours in sa.schaal-it.net/sa-update ?
     
  4. florian030

    florian030 Well-Known Member HowtoForge Supporter

    I have only one script in /etc/cron.hourly (you can also use .daily) provided on my page. I did not run additional scripts for sa-updates.
     
  5. chico11mbit

    chico11mbit Member

    ok. it works. i had only to install sa-compile.
     

Share This Page