#!/bin/sh #---------------------------------------------------------------------------------------- # /var/install/bin/antispam-update-channels - update spamassassin rule files # # Copyright (c) 2001-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2012-01-10 jed # Last Update: $Id$ # # Options/Parameters: # # antispam-update-channels [date-stamp], e.g. "20120110" # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------------- # read eislib etc. . /var/install/include/eislib #exec 2>/tmp/antispam-update-channels-$$.log #set -x #---------------------------------------------------------------------------------- # my own echo #---------------------------------------------------------------------------------- myecho () { if [ ${quiet} -eq 0 -o ${debug} -eq 1 ] then mecho $* fi } #---------------------------------------------------------------------------------- # check channel configuration #---------------------------------------------------------------------------------- check_channels () { _icc_ret=1 _icc_num=0 _icc_idx=1 if [ ${cf_n} -eq ${ANTISPAM_RULE_CHANNEL_N} ] then while [ ${_icc_idx} -le ${cf_n} ] do # read new rule eval new_cf='$cf_'${_icc_idx} _icc_jdx=1 while [ ${_icc_jdx} -le ${ANTISPAM_RULE_CHANNEL_N} ] do # read old rule eval old_cf='$ANTISPAM_RULE_CHANNEL_'${_icc_jdx}'_NAME' if [ "${new_cf}" = "${old_cf}" ] then # count matches _icc_num=`expr ${_icc_num} + 1` break fi _icc_jdx=`expr ${_icc_jdx} + 1` done if [ ${_icc_num} -eq ${cf_n} ] then # all rules exist _icc_ret=0 break fi _icc_idx=`expr ${_icc_idx} + 1` done fi return ${_icc_ret} } #---------------------------------------------------------------------------------- # check key configuration #---------------------------------------------------------------------------------- check_keys () { _ick_ret=1 _ick_num=0 _ick_idx=1 while [ ${_ick_idx} -le ${url_n} ] do # read new rule eval new_url='$url_'${_ick_idx} eval new_key='$key_'${_ick_idx} _ick_jdx=1 while [ ${_ick_jdx} -le ${ANTISPAM_RULE_KEY_N} ] do # read old rule eval old_url='$ANTISPAM_RULE_KEY_'${_ick_jdx}'_URL' eval old_key='$ANTISPAM_RULE_KEY_'${_ick_jdx}'_ID' if [ "${new_url}" = "${old_url}" -a "${new_key}" = "${old_key}" ] then # count matches _ick_num=`expr ${_ick_num} + 1` break fi _ick_jdx=`expr ${_ick_jdx} + 1` done if [ ${_ick_num} -eq ${url_n} ] then # all rules exist _ick_ret=0 break fi _ick_idx=`expr ${_ick_idx} + 1` done return ${_ick_ret} } #======================================================================================== # main #======================================================================================== ### set path names ### tmp_path=/tmp antispam_config_path=/var/antispam antispam_config_spam_path=${antispam_config_path}/spamassassin ### set files ### antispamfile=/etc/config.d/antispam installfile=/var/run/antispam.install antispam_marker_file=${antispam_config_spam_path}/sa-update-channels full_pgmname="`which ${0}`" debug=0 quiet=0 last_update='' # command line parameter if [ $# -gt 0 ] then # read parameter(s) while [ $# -gt 0 ] do case $1 in --debug ) debug=1 shift ;; --quiet ) quiet=1 shift ;; *) last_update="$1" shift ;; esac done fi last_update='20120311' antispam_channel_file=${tmp_path}/sa-update-channels.${last_update} # load configuration . ${antispamfile} check=0 inform=0 if [ -f ${antispam_channel_file} ] then # update recommendation exists . ${antispam_channel_file} if [ ! -f ${antispam_marker_file} ] then # check required myecho myecho "Force channel/url/id check because it has never be done." check=1 elif [ "`cat ${antispam_marker_file}`" -lt "${last_update}" ] then # check unstanding myecho myecho "Force channel/url/id check because definition might be outdated." check=1 fi if [ ${check} -eq 1 ] then # check of channel definition and key urls/ids recommended if check_channels then myecho --info "The channel definition is up-to-date!" else myecho --warn "The channel definition differs, please check the configuration!" inform=1 fi if check_keys then myecho --info "The key url/id definition is up-to-date!" else myecho --warn "The key url/id definition differs, please check the configuration!" inform=1 fi if [ ${inform} -eq 1 -a ${quiet} -eq 0 ] then myecho myecho --warn "New channel/url/id definition available!" myecho if /var/install/bin/ask "Should the configuration updated automatically" "y" then cp ${antispamfile} ${installfile} /var/install/config.d/antispam-update.sh "update-channel" "${last_update}" else myecho myecho "You've decided not to update the channel configuration." myecho "If you want to apply the modification later please check" myecho "the following file for further information:" myecho myecho "${antispam_config_spam_path}/sa-update-channels.${last_update}" myecho fi else # write to log file /usr/bin/logger -p "local7.info" -t "antispam" "update: A new channel configuration exists. If you want" /usr/bin/logger -p "local7.info" -t "antispam" "update: to apply the modification later please check the" /usr/bin/logger -p "local7.info" -t "antispam" "update: following file for further information:" /usr/bin/logger -p "local7.info" -t "antispam" "update: ${antispam_config_spam_path}/sa-update-channels.${last_update}" fi rm -f ${antispam_marker_file}.* mv ${antispam_channel_file} ${antispam_config_spam_path}/ echo "${last_update}" > ${antispam_marker_file} fi fi #======================================================================================== # exit #======================================================================================== exit 0