|
|
# | # |
# Check for needed tools | # Check for needed tools |
# | # |
check_for_tools |
if ! check_for_tools |
if [ "$?" -ne "0" ] |
|
then | then |
# We have not all needed tools installed. Run just the dspam_clean part. | # We have not all needed tools installed. Run just the dspam_clean part. |
run_dspam_clean | run_dspam_clean |
|
|
# | # |
# Try to get DSPAM home directory | # Try to get DSPAM home directory |
# | # |
DSPAM_HOMEDIR="$(grep ^dspam /etc/passwd|awk -F : '{print $6}')" |
DSPAM_HOMEDIR="$(awk -F : '$1 ~ /^dspam$/ {print $6}' /etc/passwd)" |
if [ ! -f ${DSPAM_HOMEDIR}/dspam.conf ] |
if [ ! -f "${DSPAM_HOMEDIR}/dspam.conf" ] |
then | then |
# Something is wrong in passwd! Check if /etc/mail/dspam exists instead. | # Something is wrong in passwd! Check if /etc/mail/dspam exists instead. |
if [ -f /etc/mail/dspam/dspam.conf ] | if [ -f /etc/mail/dspam/dspam.conf ] |
|
|
DSPAM_HOMEDIR="/etc/mail/dspam" | DSPAM_HOMEDIR="/etc/mail/dspam" |
fi | fi |
fi | fi |
[ ! -d ${DSPAM_HOMEDIR} ] && exit 2 |
[ ! -d "${DSPAM_HOMEDIR}" ] && exit 2 |
| |
| |
# | # |
# Try to get DSPAM data home directory | # Try to get DSPAM data home directory |
# | # |
DSPAM_DATAHOMEDIR="$(grep ^Home ${DSPAM_HOMEDIR}/dspam.conf|awk '{print $2}')" |
DSPAM_DATAHOMEDIR="$(awk '$1 ~ /^Home$/ {print $2}' "${DSPAM_HOMEDIR}/dspam.conf")" |
if [ ! -d ${DSPAM_DATAHOMEDIR} ] |
if [ ! -d "${DSPAM_DATAHOMEDIR}" ] |
then | then |
# Something is wrong in dspam.conf! Check if /var/spool/dspam exists instead. | # Something is wrong in dspam.conf! Check if /var/spool/dspam exists instead. |
if [ -d /var/spool/dspam ] | if [ -d /var/spool/dspam ] |
|
|
DSPAM_DATAHOMEDIR="/var/spool/dspam" | DSPAM_DATAHOMEDIR="/var/spool/dspam" |
fi | fi |
fi | fi |
[ ! -d ${DSPAM_DATAHOMEDIR} ] && exit 2 |
[ ! -d "${DSPAM_DATAHOMEDIR}" ] && exit 2 |
| |
| |
| |
|
|
# | # |
if [ -d "${DSPAM_HOMEDIR}/data" ] | if [ -d "${DSPAM_HOMEDIR}/data" ] |
then | then |
dspam_logrotate -a 30 -d ${DSPAM_HOMEDIR}/data >/dev/null 2>&1 |
dspam_logrotate -a 30 -d "${DSPAM_HOMEDIR}/data" >/dev/null 2>&1 |
fi | fi |
| |
| |
|
|
DSPAM_MySQL_MAJOR="$(echo "${DSPAM_MySQL_VER}" | cut -d. -f1)" | DSPAM_MySQL_MAJOR="$(echo "${DSPAM_MySQL_VER}" | cut -d. -f1)" |
DSPAM_MySQL_MINOR="$(echo "${DSPAM_MySQL_VER}" | cut -d. -f2)" | DSPAM_MySQL_MINOR="$(echo "${DSPAM_MySQL_VER}" | cut -d. -f2)" |
DSPAM_MySQL_MICRO="$(echo "${DSPAM_MySQL_VER}" | cut -d. -f3)" | DSPAM_MySQL_MICRO="$(echo "${DSPAM_MySQL_VER}" | cut -d. -f3)" |
DSPAM_MySQL_INT="$((DSPAM_MySQL_MAJOR * 65536 + DSPAM_MySQL_MINOR * 256 + DSPAM_MySQL_MICRO))" |
DSPAM_MySQL_INT="$(($DSPAM_MySQL_MAJOR * 65536 + $DSPAM_MySQL_MINOR * 256 + $DSPAM_MySQL_MICRO))" |
| |
# For MySQL >= 4.1 use the new purge script | # For MySQL >= 4.1 use the new purge script |
if [ "${DSPAM_MySQL_INT}" -ge "262400" ] | if [ "${DSPAM_MySQL_INT}" -ge "262400" ] |
|
|
[ -f "${DSPAM_HOMEDIR}/mysql_purge.sql" ] && DSPAM_MySQL_PURGE_SQL="${DSPAM_HOMEDIR}/mysql_purge.sql" | [ -f "${DSPAM_HOMEDIR}/mysql_purge.sql" ] && DSPAM_MySQL_PURGE_SQL="${DSPAM_HOMEDIR}/mysql_purge.sql" |
fi | fi |
| |
if [ "${DSPAM_MySQL_PURGE_SQL}" == "" ] |
if [ -z "${DSPAM_MySQL_PURGE_SQL}" ] |
then | then |
echo "Can not run MySQL purge script:" | echo "Can not run MySQL purge script:" |
echo " No mysql_purge SQL script found" | echo " No mysql_purge SQL script found" |
|
|
fi | fi |
| |
# Get DSPAM MySQL username and password | # Get DSPAM MySQL username and password |
DSPAM_MySQL_HOST="$(cat ${DSPAM_HOMEDIR}/mysql.data|head -n 1|tail -n 1)" |
DSPAM_MySQL_HOST="$(head -n 1 "${DSPAM_HOMEDIR}/mysql.data")" |
DSPAM_MySQL_PORT="$(cat ${DSPAM_HOMEDIR}/mysql.data|head -n 2|tail -n 1)" |
DSPAM_MySQL_PORT="$(head -n 2 "${DSPAM_HOMEDIR}/mysql.data"|tail -n 1)" |
DSPAM_MySQL_USER="$(cat ${DSPAM_HOMEDIR}/mysql.data|head -n 3|tail -n 1)" |
DSPAM_MySQL_USER="$(head -n 3 "${DSPAM_HOMEDIR}/mysql.data"|tail -n 1)" |
DSPAM_MySQL_PWD="$(cat ${DSPAM_HOMEDIR}/mysql.data|head -n 4|tail -n 1)" |
DSPAM_MySQL_PWD="$(head -n 4 "${DSPAM_HOMEDIR}/mysql.data"|tail -n 1)" |
DSPAM_MySQL_DB="$(cat ${DSPAM_HOMEDIR}/mysql.data|head -n 5|tail -n 1)" |
DSPAM_MySQL_DB="$(head -n 5 "${DSPAM_HOMEDIR}/mysql.data"|tail -n 1)" |
| |
# Check if MySQL is remote or using a socket | # Check if MySQL is remote or using a socket |
if [ -S "${DSPAM_MySQL_HOST}" ] | if [ -S "${DSPAM_MySQL_HOST}" ] |
|
|
[ -f "${DSPAM_HOMEDIR}/config/pgsql_purge.sql" ] && DSPAM_PgSQL_PURGE_SQL="${DSPAM_HOMEDIR}/config/pgsql_purge.sql" | [ -f "${DSPAM_HOMEDIR}/config/pgsql_purge.sql" ] && DSPAM_PgSQL_PURGE_SQL="${DSPAM_HOMEDIR}/config/pgsql_purge.sql" |
[ -f "${DSPAM_HOMEDIR}/pgsql_purge.sql" ] && DSPAM_PgSQL_PURGE_SQL="${DSPAM_HOMEDIR}/pgsql_purge.sql" | [ -f "${DSPAM_HOMEDIR}/pgsql_purge.sql" ] && DSPAM_PgSQL_PURGE_SQL="${DSPAM_HOMEDIR}/pgsql_purge.sql" |
| |
if [ "${DSPAM_PgSQL_PURGE_SQL}" == "" ] |
if [ -z "${DSPAM_PgSQL_PURGE_SQL}" ] |
then | then |
echo "Can not run PostgreSQL purge script:" | echo "Can not run PostgreSQL purge script:" |
echo " No pgsql_purge SQL script found" | echo " No pgsql_purge SQL script found" |
|
|
fi | fi |
| |
# Get DSPAM PostgreSQL username and password | # Get DSPAM PostgreSQL username and password |
DSPAM_PgSQL_HOST="$(cat ${DSPAM_HOMEDIR}/pgsql.data|head -n 1|tail -n 1)" |
DSPAM_PgSQL_HOST="$(head -n 1 "${DSPAM_HOMEDIR}/pgsql.data")" |
DSPAM_PgSQL_PORT="$(cat ${DSPAM_HOMEDIR}/pgsql.data|head -n 2|tail -n 1)" |
DSPAM_PgSQL_PORT="$(head -n 2 "${DSPAM_HOMEDIR}/pgsql.data"|tail -n 1)" |
DSPAM_PgSQL_USER="$(cat ${DSPAM_HOMEDIR}/pgsql.data|head -n 3|tail -n 1)" |
DSPAM_PgSQL_USER="$(head -n 3 "${DSPAM_HOMEDIR}/pgsql.data"|tail -n 1)" |
DSPAM_PgSQL_PWD="$(cat ${DSPAM_HOMEDIR}/pgsql.data|head -n 4|tail -n 1)" |
DSPAM_PgSQL_PWD="$(head -n 4 "${DSPAM_HOMEDIR}/pgsql.data"|tail -n 1)" |
DSPAM_PgSQL_DB="$(cat ${DSPAM_HOMEDIR}/pgsql.data|head -n 5|tail -n 1)" |
DSPAM_PgSQL_DB="$(head -n 5 "${DSPAM_HOMEDIR}/pgsql.data"|tail -n 1)" |
| |
# Run the PostgreSQL purge script | # Run the PostgreSQL purge script |
PGUSER=${DSPAM_PgSQL_USER} PGPASSWORD=${DSPAM_PgSQL_PWD} /usr/bin/psql -U ${DSPAM_PgSQL_USER} -d ${DSPAM_PgSQL_DB} -p ${DSPAM_PgSQL_PORT} -h ${DSPAM_PgSQL_HOST} -f ${DSPAM_PgSQL_PURGE_SQL} 1>/dev/null 2>&1 |
PGUSER="${DSPAM_PgSQL_USER}" PGPASSWORD="${DSPAM_PgSQL_PWD}" /usr/bin/psql -U "${DSPAM_PgSQL_USER}" -d "${DSPAM_PgSQL_DB}" -p "${DSPAM_PgSQL_PORT}" -h "${DSPAM_PgSQL_HOST}" -f "${DSPAM_PgSQL_PURGE_SQL}" 1>/dev/null 2>&1 |
| |
# Run the dspam_clean command | # Run the dspam_clean command |
run_dspam_clean | run_dspam_clean |
|
|
# | # |
# SQLite3 | # SQLite3 |
# | # |
elif ( grep -q "^[\t ]*StorageDriver[\t ]*.*libsqlite3_drv" ${DSPAM_HOMEDIR}/dspam.conf ) |
elif ( grep -q "^[\t ]*StorageDriver[\t ]*.*libsqlite3_drv" "${DSPAM_HOMEDIR}/dspam.conf" ) |
then | then |
DSPAM_SQLite3_PURGE_SQL="" | DSPAM_SQLite3_PURGE_SQL="" |
[ -f "${DSPAM_HOMEDIR}/config/sqlite3_purge.sql" ] && DSPAM_SQLite3_PURGE_SQL="${DSPAM_HOMEDIR}/config/sqlite3_purge.sql" | [ -f "${DSPAM_HOMEDIR}/config/sqlite3_purge.sql" ] && DSPAM_SQLite3_PURGE_SQL="${DSPAM_HOMEDIR}/config/sqlite3_purge.sql" |
[ -f "${DSPAM_HOMEDIR}/sqlite3_purge.sql" ] && DSPAM_SQLite3_PURGE_SQL="${DSPAM_HOMEDIR}/sqlite3_purge.sql" | [ -f "${DSPAM_HOMEDIR}/sqlite3_purge.sql" ] && DSPAM_SQLite3_PURGE_SQL="${DSPAM_HOMEDIR}/sqlite3_purge.sql" |
| |
if [ "${DSPAM_SQLite3_PURGE_SQL}" == "" ] |
if [ -z "${DSPAM_SQLite3_PURGE_SQL}" ] |
then | then |
echo "Can not run SQLite3 purge script:" | echo "Can not run SQLite3 purge script:" |
echo " No sqlite_purge SQL script found" | echo " No sqlite_purge SQL script found" |
|
|
fi | fi |
| |
# Run the SQLite3 purge script | # Run the SQLite3 purge script |
find ${DSPAM_DATAHOMEDIR} -name "*.sdb" -exec /usr/bin/sqlite3 "{}" < ${DSPAM_SQLite3_PURGE_SQL} \; 1>/dev/null 2>&1 |
find "${DSPAM_DATAHOMEDIR}" -name "*.sdb" -exec /usr/bin/sqlite3 "{}" < "${DSPAM_SQLite3_PURGE_SQL}" \; 1>/dev/null 2>&1 |
| |
# Run the dspam_clean command | # Run the dspam_clean command |
run_dspam_clean | run_dspam_clean |
| |
# Optimize the SQLite tables for DSPAM | # Optimize the SQLite tables for DSPAM |
find ${DSPAM_DATAHOMEDIR} -name "*.sdb" -exec echo 'vacuum;' \| /usr/bin/sqlite3 "{}" \; |
find "${DSPAM_DATAHOMEDIR}" -name "*.sdb" -exec echo 'vacuum;' \| /usr/bin/sqlite3 "{}" \; |
| |
exit 0 | exit 0 |
| |
|
|
# | # |
# SQLite | # SQLite |
# | # |
elif ( grep -q "^[\t ]*StorageDriver[\t ]*.*libsqlite_drv" ${DSPAM_HOMEDIR}/dspam.conf ) |
elif ( grep -q "^[\t ]*StorageDriver[\t ]*.*libsqlite_drv" "${DSPAM_HOMEDIR}/dspam.conf" ) |
then | then |
DSPAM_SQLite_PURGE_SQL="" | DSPAM_SQLite_PURGE_SQL="" |
[ -f "${DSPAM_HOMEDIR}/config/sqlite_purge.sql" ] && DSPAM_SQLite_PURGE_SQL="${DSPAM_HOMEDIR}/config/sqlite_purge.sql" | [ -f "${DSPAM_HOMEDIR}/config/sqlite_purge.sql" ] && DSPAM_SQLite_PURGE_SQL="${DSPAM_HOMEDIR}/config/sqlite_purge.sql" |
[ -f "${DSPAM_HOMEDIR}/sqlite_purge.sql" ] && DSPAM_SQLite_PURGE_SQL="${DSPAM_HOMEDIR}/sqlite_purge.sql" | [ -f "${DSPAM_HOMEDIR}/sqlite_purge.sql" ] && DSPAM_SQLite_PURGE_SQL="${DSPAM_HOMEDIR}/sqlite_purge.sql" |
| |
if [ "${DSPAM_SQLite_PURGE_SQL}" == "" ] |
if [ -z "${DSPAM_SQLite_PURGE_SQL}" ] |
then | then |
echo "Can not run SQLite purge script:" | echo "Can not run SQLite purge script:" |
echo " No sqlite_purge SQL script found" | echo " No sqlite_purge SQL script found" |
|
|
fi | fi |
| |
# Run the SQLite purge script | # Run the SQLite purge script |
find ${DSPAM_DATAHOMEDIR} -name "*.sdb" -exec /usr/bin/sqlite "{}" < ${DSPAM_SQLite_PURGE_SQL} \; 1>/dev/null 2>&1 |
find "${DSPAM_DATAHOMEDIR}" -name "*.sdb" -exec /usr/bin/sqlite "{}" < "${DSPAM_SQLite_PURGE_SQL}" \; 1>/dev/null 2>&1 |
| |
# Run the dspam_clean command | # Run the dspam_clean command |
run_dspam_clean | run_dspam_clean |