diff options
author | Alin Năstac <mrness@gentoo.org> | 2007-08-17 18:19:27 +0000 |
---|---|---|
committer | Alin Năstac <mrness@gentoo.org> | 2007-08-17 18:19:27 +0000 |
commit | 9c807ae47e46c0b80bad1201edf534b12b897597 (patch) | |
tree | 50b8527c11dfd55d1caa4a36e1edcbd5b954da87 /mail-filter/dspam | |
parent | Version bump, bug #188741. (diff) | |
download | gentoo-2-9c807ae47e46c0b80bad1201edf534b12b897597.tar.gz gentoo-2-9c807ae47e46c0b80bad1201edf534b12b897597.tar.bz2 gentoo-2-9c807ae47e46c0b80bad1201edf534b12b897597.zip |
Improve cron script, thanks to steveb <steeeeeveee at gmx dot net> (#189033).
(Portage version: 2.1.2.11)
Diffstat (limited to 'mail-filter/dspam')
-rw-r--r-- | mail-filter/dspam/ChangeLog | 8 | ||||
-rw-r--r-- | mail-filter/dspam/dspam-3.8.0-r4.ebuild (renamed from mail-filter/dspam/dspam-3.8.0-r3.ebuild) | 2 | ||||
-rw-r--r-- | mail-filter/dspam/files/digest-dspam-3.8.0-r4 (renamed from mail-filter/dspam/files/digest-dspam-3.8.0-r3) | 0 | ||||
-rw-r--r-- | mail-filter/dspam/files/dspam.cron | 354 |
4 files changed, 228 insertions, 136 deletions
diff --git a/mail-filter/dspam/ChangeLog b/mail-filter/dspam/ChangeLog index bf1c1d79af02..e1e6f145af96 100644 --- a/mail-filter/dspam/ChangeLog +++ b/mail-filter/dspam/ChangeLog @@ -1,6 +1,12 @@ # ChangeLog for mail-filter/dspam # Copyright 1999-2007 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/ChangeLog,v 1.93 2007/07/19 08:28:32 mrness Exp $ +# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/ChangeLog,v 1.94 2007/08/17 18:19:27 mrness Exp $ + +*dspam-3.8.0-r4 (17 Aug 2007) + + 17 Aug 2007; Alin Năstac <mrness@gentoo.org> files/dspam.cron, + -dspam-3.8.0-r3.ebuild, +dspam-3.8.0-r4.ebuild: + Improve cron script, thanks to steveb <steeeeeveee at gmx dot net> (#189033). *dspam-3.8.0-r3 (19 Jul 2007) diff --git a/mail-filter/dspam/dspam-3.8.0-r3.ebuild b/mail-filter/dspam/dspam-3.8.0-r4.ebuild index fdcd2df7d2ef..4708a480b096 100644 --- a/mail-filter/dspam/dspam-3.8.0-r3.ebuild +++ b/mail-filter/dspam/dspam-3.8.0-r4.ebuild @@ -1,6 +1,6 @@ # Copyright 1999-2007 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/dspam-3.8.0-r3.ebuild,v 1.2 2007/07/19 08:39:01 mrness Exp $ +# $Header: /var/cvsroot/gentoo-x86/mail-filter/dspam/dspam-3.8.0-r4.ebuild,v 1.1 2007/08/17 18:19:27 mrness Exp $ WANT_AUTOCONF="latest" WANT_AUTOMAKE="latest" diff --git a/mail-filter/dspam/files/digest-dspam-3.8.0-r3 b/mail-filter/dspam/files/digest-dspam-3.8.0-r4 index 86dd9ae31fc9..86dd9ae31fc9 100644 --- a/mail-filter/dspam/files/digest-dspam-3.8.0-r3 +++ b/mail-filter/dspam/files/digest-dspam-3.8.0-r4 diff --git a/mail-filter/dspam/files/dspam.cron b/mail-filter/dspam/files/dspam.cron index 0aa2085f12b1..b617bcd1c6b6 100644 --- a/mail-filter/dspam/files/dspam.cron +++ b/mail-filter/dspam/files/dspam.cron @@ -7,21 +7,34 @@ # # +# Parse optional command line parameters +# +for foo in $@ +do + case "${foo}" in + --logdays=*) LOGROTATE_AGE="${foo#--logdays=}";; + --sigdays=*) SIGNATURE_AGE="${foo#--sigdays=}";; + esac +done + +# # Parameters # -LOGROTATE_AGE=30 # Delete log entries older than $LOGROTATE_AGE days +[ -z "${LOGROTATE_AGE}" ] && LOGROTATE_AGE=30 # Delete log entries older than $LOGROTATE_AGE days +[ -z "${SIGNATURE_AGE}" ] && SIGNATURE_AGE=30 # Delete signatures older than $SIGNATURE_AGE days # # Function to run dspam_clean # run_dspam_clean() { - if [ ! -f "/usr/bin/dspam_clean" ] + if [ ! -e "/usr/bin/dspam_clean" ] then - echo "/usr/bin/dspam_clean not found!" + echo "Can not run DSPAM clean application:" + echo " /usr/bin/dspam_clean does not exist" return 1 else - /usr/bin/dspam_clean -s -p -u >/dev/null 2>&1 - return 0 + /usr/bin/dspam_clean -s${SIGNATURE_AGE} -p${SIGNATURE_AGE} -u${SIGNATURE_AGE},${SIGNATURE_AGE},${SIGNATURE_AGE},${SIGNATURE_AGE} >/dev/null 2>&1 + return $? fi } @@ -44,81 +57,19 @@ check_for_tools() { # -# Acquire lock file and start processing +# Function to clean DSPAM MySQL data # -DSPAM_CRON_LOCKFILE="/var/run/$(basename $0 .sh).pid" -if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then - - trap 'rm -f "${DSPAM_CRON_LOCKFILE}"; exit $?' INT TERM EXIT - - # - # Check for needed tools - # - if ! check_for_tools - then - # We have not all needed tools installed. Run just the dspam_clean part. - run_dspam_clean - exit $? - fi - - - # - # Try to get DSPAM config directory - # - DSPAM_CONFIGDIR=$(getent passwd dspam | awk -F : '{print $6}') - if [ ! -f "${DSPAM_CONFIGDIR}/dspam.conf" ] - then - # Something is wrong in passwd! Check if /etc/mail/dspam exists instead. - if [ -f /etc/mail/dspam/dspam.conf ] - then - DSPAM_CONFIGDIR="/etc/mail/dspam" - fi - fi - if [ ! -d "${DSPAM_CONFIGDIR}" ] - then - echo "Configuration directory not found!" - exit 2 - fi - - # - # Try to get DSPAM data home directory - # - DSPAM_HOMEDIR=$(awk '$1 ~ /^[[:space:]]*Home[[:space:]]/ {print $2}' "${DSPAM_CONFIGDIR}/dspam.conf") - if [ ! -d "${DSPAM_HOMEDIR}" ] - then - # Something is wrong in dspam.conf! Check if /var/spool/dspam exists instead. - if [ -d /var/spool/dspam ] - then - DSPAM_HOMEDIR="/var/spool/dspam" - fi - fi - if [ ! -d "${DSPAM_HOMEDIR}" ] - then - echo "Home directory not found! Please fix your dspam.conf." - exit 2 - fi - - - # - # User log purging - # - if [ -d "${DSPAM_CONFIGDIR}/data" ] - then - dspam_logrotate -a ${LOGROTATE_AGE} -d "${DSPAM_CONFIGDIR}/data" >/dev/null # 2>&1 - fi - - +clean_mysql_drv() { # # MySQL # if [ -f "${DSPAM_CONFIGDIR}/mysql.data" ] then - if [ ! -f "/usr/bin/mysql_config" ] + if [ ! -e "/usr/bin/mysql_config" ] then echo "Can not run MySQL purge script:" echo " /usr/bin/mysql_config does not exist" - run_dspam_clean - exit 1 + return 1 fi DSPAM_MySQL_PURGE_SQL= DSPAM_MySQL_VER=$(/usr/bin/mysql_config --version | sed "s:[^0-9.]*::g") @@ -148,16 +99,14 @@ if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then then echo "Can not run MySQL purge script:" echo " No mysql_purge SQL script found" - run_dspam_clean - exit 1 + return 1 fi - if [ ! -f "/usr/bin/mysql" ] + if [ ! -e "/usr/bin/mysql" ] then echo "Can not run MySQL purge script:" echo " /usr/bin/mysql does not exist" - run_dspam_clean - exit 1 + return 1 fi # Get DSPAM MySQL username and password @@ -177,22 +126,36 @@ if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then # Run the MySQL purge script /usr/bin/mysql --silent --user="${DSPAM_MySQL_USER}" --password="${DSPAM_MySQL_PWD}" ${DSPAM_MySQL_HOSTCMD}="${DSPAM_MySQL_HOST}" ${DSPAM_MySQL_DB} < ${DSPAM_MySQL_PURGE_SQL} + _RC=$? + if [ ${_RC} != 0 ] + then + echo "MySQL purge script returned error code ${_RC}" + fi - # Run the dspam_clean command - run_dspam_clean - # Optimize the MySQL tables for DSPAM for foo in $(/usr/bin/mysql --user="${DSPAM_MySQL_USER}" --password="${DSPAM_MySQL_PWD}" ${DSPAM_MySQL_HOSTCMD}="${DSPAM_MySQL_HOST}" --silent --skip-column-names --batch ${DSPAM_MySQL_DB} -e 'SHOW TABLES;' 2>&1) do /usr/bin/mysql --user="${DSPAM_MySQL_USER}" --password="${DSPAM_MySQL_PWD}" ${DSPAM_MySQL_HOSTCMD}="${DSPAM_MySQL_HOST}" ${DSPAM_MySQL_DB} -e "OPTIMIZE TABLE ${foo};" 1>/dev/null 2>&1 + _RC=$? + if [ ${_RC} != 0 ] + then + echo "MySQL optimize script for table \"${foo}\" returned error code ${_RC}" + fi done - exit 0 + + return 0 + fi +} +# +# Function to clean DSPAM PostgreSQL data +# +clean_pgsql_drv() { # # PostgreSQL # - elif [ -f "${DSPAM_CONFIGDIR}/pgsql.data" ] + if [ -f "${DSPAM_CONFIGDIR}/pgsql.data" ] then DSPAM_PgSQL_PURGE_SQL="" [ -f "${DSPAM_CONFIGDIR}/config/pgsql_purge.sql" ] && DSPAM_PgSQL_PURGE_SQL="${DSPAM_CONFIGDIR}/config/pgsql_purge.sql" @@ -202,16 +165,14 @@ if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then then echo "Can not run PostgreSQL purge script:" echo " No pgsql_purge SQL script found" - run_dspam_clean - exit 1 + return 1 fi - if [ ! -f "/usr/bin/psql" ] + if [ ! -e "/usr/bin/psql" ] then echo "Can not run PostgreSQL purge script:" echo " /usr/bin/psql does not exist" - run_dspam_clean - exit 1 + return 1 fi # Get DSPAM PostgreSQL username and password @@ -222,19 +183,65 @@ if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then DSPAM_PgSQL_DB=$(sed "5q;d" "${DSPAM_CONFIGDIR}/pgsql.data") # Run the PostgreSQL purge script - PGUSER="${DSPAM_PgSQL_USER}" PGPASSWORD="${DSPAM_PgSQL_PWD}" /usr/bin/psql -q -U "${DSPAM_PgSQL_USER}" -d "${DSPAM_PgSQL_DB}" -p "${DSPAM_PgSQL_PORT}" -h "${DSPAM_PgSQL_HOST}" -f "${DSPAM_PgSQL_PURGE_SQL}" + PGUSER="${DSPAM_PgSQL_USER}" PGPASSWORD="${DSPAM_PgSQL_PWD}" /usr/bin/psql -q -U "${DSPAM_PgSQL_USER}" -d "${DSPAM_PgSQL_DB}" -p "${DSPAM_PgSQL_PORT}" -h "${DSPAM_PgSQL_HOST}" -f "${DSPAM_PgSQL_PURGE_SQL}" >/dev/null 2>&1 + _RC=$? + if [ ${_RC} != 0 ] + then + echo "PostgreSQL purge script returned error code ${_RC}" + fi - # Run the dspam_clean command - run_dspam_clean + # Optimize the PostgreSQL tables for DSPAM + for foo in dspam_preferences dspam_signature_data dspam_stats dspam_token_data dspam_virtual_uids + do + PGUSER="${DSPAM_PgSQL_USER}" PGPASSWORD="${DSPAM_PgSQL_PWD}" /usr/bin/vacuumdb -q -U "${DSPAM_PgSQL_USER}" -d "${DSPAM_PgSQL_DB}" -p "${DSPAM_PgSQL_PORT}" -h "${DSPAM_PgSQL_HOST}" -f -t "${foo}" >/dev/null 2>&1 + _RC=$? + if [ ${_RC} != 0 ] + then + echo "PostgreSQL vacuumdb script for table \"public.${foo}\" returned error code ${_RC}" + fi + done - exit 0 + return 0 + fi + +} +# +# Function to clean DSPAM Hash data +# +clean_hash_drv() { # - # SQLite3 + # Hash # - elif ( grep -q "^[[:space:]]*StorageDriver[[:space:]]*.*libsqlite3_drv" "${DSPAM_CONFIGDIR}/dspam.conf" ) + if [ -d "${DSPAM_HOMEDIR}/data" ] then + find ${DSPAM_HOMEDIR}/data/ -maxdepth 4 -mindepth 1 -type f -name "*.css" | while read name + do + /usr/bin/csscompress "${name}" 1>/dev/null 2>&1 + /usr/bin/cssclean "${name}" 1>/dev/null 2>&1 + # chown dspam:dspam "${name}" + done + find ${DSPAM_HOMEDIR}/data/ -maxdepth 4 -mindepth 1 -type d -name "*.sig" | while read name + do + find "${name}" -maxdepth 1 -mindepth 1 -type f -mtime +${SIGNATURE_AGE} -name "*.sig" -exec /bin/rm "{}" ";" + done + return 0 + else + return 1 + fi +} + + +# +# Function to clean DSPAM SQLite3 data +# +clean_sqlite3_drv() { + # + # SQLite3 + # + # if ( grep -q "^[[:space:]]*StorageDriver[[:space:]]*.*libsqlite3_drv" "${DSPAM_CONFIGDIR}/dspam.conf" ) + # then DSPAM_SQLite3_PURGE_SQL="" [ -f "${DSPAM_CONFIGDIR}/config/sqlite3_purge.sql" ] && DSPAM_SQLite3_PURGE_SQL="${DSPAM_CONFIGDIR}/config/sqlite3_purge.sql" [ -f "${DSPAM_CONFIGDIR}/sqlite3_purge.sql" ] && DSPAM_SQLite3_PURGE_SQL="${DSPAM_CONFIGDIR}/sqlite3_purge.sql" @@ -243,41 +250,38 @@ if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then then echo "Can not run SQLite3 purge script:" echo " No sqlite_purge SQL script found" - run_dspam_clean - exit 1 + return 1 fi - if [ ! -f "/usr/bin/sqlite3" ] + if [ ! -e "/usr/bin/sqlite3" ] then echo "Can not run SQLite3 purge script:" echo " /usr/bin/sqlite3 does not exist" - run_dspam_clean - exit 1 + return 1 fi - # Run the SQLite3 purge script + # Run the SQLite3 purge script and optimize database find "${DSPAM_HOMEDIR}" -name "*.sdb" -print | while read name - do - /usr/bin/sqlite3 "$name" < "${DSPAM_SQLite3_PURGE_SQL}" - done 1>/dev/null 2>&1 + do + /usr/bin/sqlite3 "$name" < "${DSPAM_SQLite3_PURGE_SQL}" + /usr/bin/sqlite3 "$name" vacuum + done 1>/dev/null 2>&1 - # Run the dspam_clean command - run_dspam_clean + return 0 + # fi - # Optimize the SQLite tables for DSPAM - find "${DSPAM_HOMEDIR}" -name "*.sdb" -print | while read name - do - echo 'vacuum;' | /usr/bin/sqlite3 "$name" - done +} - exit 0 - +# +# Function to clean DSPAM SQLite data +# +clean_sqlite_drv() { # # SQLite # - elif ( grep -q "^[[:space:]]*StorageDriver[[:space:]]*.*libsqlite_drv" "${DSPAM_CONFIGDIR}/dspam.conf" ) - then + # if ( grep -q "^[[:space:]]*StorageDriver[[:space:]]*.*libsqlite_drv" "${DSPAM_CONFIGDIR}/dspam.conf" ) + # then DSPAM_SQLite_PURGE_SQL="" [ -f "${DSPAM_CONFIGDIR}/config/sqlite_purge.sql" ] && DSPAM_SQLite_PURGE_SQL="${DSPAM_CONFIGDIR}/config/sqlite_purge.sql" [ -f "${DSPAM_CONFIGDIR}/sqlite_purge.sql" ] && DSPAM_SQLite_PURGE_SQL="${DSPAM_CONFIGDIR}/sqlite_purge.sql" @@ -286,48 +290,130 @@ if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then then echo "Can not run SQLite purge script:" echo " No sqlite_purge SQL script found" - run_dspam_clean - exit 1 + return 1 fi - if [ ! -f "/usr/bin/sqlite" ] + if [ ! -e "/usr/bin/sqlite" ] then echo "Can not run SQLite purge script:" echo " /usr/bin/sqlite does not exist" - run_dspam_clean - exit 1 + return 1 fi - # Run the SQLite purge script + # Run the SQLite purge script and optimize database find "${DSPAM_HOMEDIR}" -name "*.sdb" -print | while read name - do - /usr/bin/sqlite "$name" < "${DSPAM_SQLite_PURGE_SQL}" - done 1>/dev/null 2>&1 + do + /usr/bin/sqlite "$name" < "${DSPAM_SQLite_PURGE_SQL}" + /usr/bin/sqlite "$name" vacuum + done 1>/dev/null 2>&1 - # Run the dspam_clean command - run_dspam_clean + return 0 + # fi +} - # Optimize the SQLite tables for DSPAM - find "${DSPAM_HOMEDIR}" -name "*.sdb" -print | while read name - do - echo 'vacuum;' | /usr/bin/sqlite "$name" - done - exit 0 - - +# +# Acquire lock file and start processing +# +DSPAM_CRON_LOCKFILE="/var/run/$(basename $0 .sh).pid" +if ( set -o noclobber; echo "$$" > "${DSPAM_CRON_LOCKFILE}") 2> /dev/null; then + + trap 'rm -f "${DSPAM_CRON_LOCKFILE}"; exit $?' INT TERM EXIT + # - # Generic + # Check for needed tools # - else + if ! check_for_tools + then + # We have not all needed tools installed. Run just the dspam_clean part. run_dspam_clean exit $? fi + # + # Try to get DSPAM config directory + # + DSPAM_CONFIGDIR=$(getent passwd dspam | awk -F : '{print $6}') + if [ ! -f "${DSPAM_CONFIGDIR}/dspam.conf" ] + then + # Something is wrong in passwd! Check if /etc/mail/dspam exists instead. + if [ -f /etc/mail/dspam/dspam.conf ] + then + DSPAM_CONFIGDIR="/etc/mail/dspam" + fi + fi + if [ ! -d "${DSPAM_CONFIGDIR}" ] + then + echo "Configuration directory not found!" + exit 2 + fi + + # + # Try to get DSPAM data home directory + # + DSPAM_HOMEDIR=$(awk 'tolower($1) ~ /^home$/ {print $2}' "${DSPAM_CONFIGDIR}/dspam.conf") + if [ ! -d "${DSPAM_HOMEDIR}" ] + then + # Something is wrong in dspam.conf! Check if /var/spool/dspam exists instead. + if [ -d /var/spool/dspam ] + then + DSPAM_HOMEDIR="/var/spool/dspam" + fi + fi + if [ ! -d "${DSPAM_HOMEDIR}" ] + then + echo "Home directory not found! Please fix your dspam.conf." + exit 2 + fi + + # + # User log purging + # + if [ -d "${DSPAM_CONFIGDIR}/data" ] + then + dspam_logrotate -a ${LOGROTATE_AGE} -d "${DSPAM_CONFIGDIR}/data" >/dev/null # 2>&1 + fi + + if [ ! -e "/usr/bin/dspam" ] + then + echo "Can not run DSPAM application:" + echo " /usr/bin/dspam does not exist" + return 1 + fi + + # + # Process all available storage drivers + # + for foo in $(/usr/bin/dspam --version 2>&1 | sed -n "s:,: :g;s:^.*\-\-with\-storage\-driver=\([^\'\]*\).*:\1:gIp") + do + case "${foo}" in + hash_drv) + clean_hash_drv + ;; + mysql_drv) + clean_mysql_drv + ;; + pgsql_drv) + clean_pgsql_drv + ;; + sqlite3_drv) + clean_sqlite3_drv + ;; + sqlite_drv) + clean_sqlite_drv + ;; + esac + done + + # + # Run the dspam_clean command + # + run_dspam_clean + # # Release lock # - rm -f "${DSPAM_CRON_LOCKFILE}" + /bin/rm -f "${DSPAM_CRON_LOCKFILE}" trap - INT TERM EXIT fi |