Reorganise cronjob creation.

This commit is contained in:
Christoph 2017-10-24 18:27:52 +02:00
parent c661291fd3
commit 309df07e84
2 changed files with 405 additions and 211 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ postfixadmin-*
/dcc*
*.log
*.tar.Z
crontab-root*
# - Dovecot
dovecot*

View File

@ -75,6 +75,9 @@ echo ""
script_dir="$(realpath $(dirname $0))"
conf_file="${script_dir}/conf/install_amavis.conf"
backup_date="$(date +%Y-%m-%d-%H%M)"
crontab_backup_file="${script_dir}/crontab-root-${backup_date}.install_amavis.lst"
if [[ -f "$conf_file" ]]; then
source $conf_file
fi
@ -793,6 +796,35 @@ if ! $installation_failed ; then
echo_ok
fi
## - Temporarily disable crontab for user root
## -
echononl " Backup crontab"
crontab -u root -l > $crontab_backup_file 2> $tmp_err_msg
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
echononl " Disable crontab for user root"
echo "" >> ${logdir}/main.log
echo "crontab -r -u root" > $tmp_err_msg
crontab -r -u root > $tmp_err_msg 2>&1
if [[ "$?" = "0" ]]; then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
echo
echo -e "\033[37m\033[1mInstall AMaViS..\033[m"
echo
## - Install package amavisd-new NOW, because we need at least the existence
## - of the AmaViS user (amavis) befor finally installation and configuration
## - of AmaViS itself.
@ -934,8 +966,6 @@ echo -e " \033[37m\033[1mConfigure Razor2..\033[m"
info "Open firewall outgoing port 2703 for Razor2"
_date="$(date +%Y-%m-%d-%H%M)"
## - This next section gets Razor2 up and running and copies its files where
## - both root and amavis expect to find them.
## -
@ -973,7 +1003,7 @@ fi
echononl " Backup directory \"/root/.razor.\""
if [[ -d /root/.razor ]] ; then
mv /root/.razor /root/.razor."${_date}" > $tmp_err_msg 2>&1
mv /root/.razor /root/.razor."${backup_date}" > $tmp_err_msg 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -1035,7 +1065,7 @@ fi
_home_amavais=$(realpath ~amavis)
echononl " Backup directory \"${_home_amavais}/.razor\""
if [[ -d "${_home_amavais}/.razor" ]] ; then
mv ${_home_amavais}/.razor ${_home_amavais}/.razor."${_date}"
mv ${_home_amavais}/.razor ${_home_amavais}/.razor."${backup_date}"
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -1062,9 +1092,9 @@ if [[ "$?" -ne 0 ]] ; then
fi
if ! $installation_failed ; then
echo_ok
if [[ -d "${_home_amavais}/.razor.${_date}" ]] ; then
echononl " Delete previous created backup \"${_home_amavais}/.razor.${_date}\""
rm -r "${_home_amavais}/.razor.${_date}" > /dev/null 2>&1
if [[ -d "${_home_amavais}/.razor.${backup_date}" ]] ; then
echononl " Delete previous created backup \"${_home_amavais}/.razor.${backup_date}\""
rm -r "${_home_amavais}/.razor.${backup_date}" > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -1072,9 +1102,9 @@ if ! $installation_failed ; then
error "$(cat $tmp_err_msg)"
fi
fi
if [[ -d "/root/.razor.${_date}" ]] ; then
echononl " Delete previous created backup \"/root/.razor.${_date}\""
rm -r "/root/.razor.${_date}" > /dev/null 2>&1
if [[ -d "/root/.razor.${backup_date}" ]] ; then
echononl " Delete previous created backup \"/root/.razor.${backup_date}\""
rm -r "/root/.razor.${backup_date}" > /dev/null 2>&1
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -1088,40 +1118,59 @@ fi
## - Aadd a cronjob for razor2 updates
## -
## -
echononl " add a cronjob for razor2 updates"
if ! grep -i -E "/usr/bin/razor-admin\s+-discover" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
echononl " Add a cronjob for razor2 updates"
if [[ -f "$crontab_backup_file" ]]; then
if ! grep -i -E "/usr/bin/razor-admin\s+-discover" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Update razor2
# -
33 0 * * * su amavis -lc '/usr/bin/razor-admin -discover'
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "/usr/bin/razor-admin\s+-discover" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Update razor2
# -
33 0 * * * su amavis -lc '/usr/bin/razor-admin -discover'
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
@ -1271,40 +1320,62 @@ fi
## -
## -
echononl " Add a cronjob for updating and cleaning up dcc"
if ! grep -i -E "/var/dcc/libexec/cron-dccd" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if [[ -f "$crontab_backup_file" ]]; then
cat << EOF >> /tmp/tmp_crontab
if ! grep -i -E "/var/dcc/libexec/cron-dccd" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Cleaning up dcc (Distributed Checksum Clearinghouses)
# -
13 1 * * * /var/dcc/libexec/cron-dccd
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "/var/dcc/libexec/cron-dccd" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Cleaning up dcc (Distributed Checksum Clearinghouses)
# -
13 1 * * * /var/dcc/libexec/cron-dccd
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
_config_file=/var/dcc/dcc_conf
@ -1382,7 +1453,6 @@ echo -e " \033[37m\033[1mConfigure Spamassassin..\033[m"
## - Backup existing SpamAssassin's main configuration file /etc/spamassassin/local.cf
## -
_config_file=/etc/spamassassin/local.cf
_date="$(date +%Y-%m-%d-%H%M)"
if [[ ! -f "${_config_file}.ORIG" ]]; then
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
cp -a "$_config_file" "${_config_file}.ORIG" > /dev/null 2> $tmp_err_msg
@ -1394,7 +1464,7 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
fi
else
echononl " Backup $_config_file"
cp -a "$_config_file" "${_config_file}.${_date}" 2> $tmp_err_msg
cp -a "$_config_file" "${_config_file}.${backup_date}" 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -1644,10 +1714,10 @@ if ! $installation_failed ; then
echo_ok
fi
if [[ -f "${_config_file}.${_date}" ]]; then
if diff "${_config_file}" "${_config_file}.${_date}" ; then
if [[ -f "${_config_file}.${backup_date}" ]]; then
if diff "${_config_file}" "${_config_file}.${backup_date}" > /dev/null 2>&1 ; then
info "${_config_file} has not changed.\n\t Removing previos created backup.."
rm "${_config_file}.${_date}"
rm "${_config_file}.${backup_date}"
fi
fi
@ -1655,7 +1725,6 @@ fi
# - Adjust /etc/spamassassin/v310.pre
# -
_config_file=/etc/spamassassin/v310.pre
_date="$(date +%Y-%m-%d-%H%M)"
_backup_file=""
if [[ ! -f "${_config_file}.ORIG" ]]; then
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
@ -1669,14 +1738,14 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
_backup_file="${_config_file}.ORIG"
else
echononl " Backup $_config_file"
cp -a "$_config_file" "${_config_file}.${_date}" 2> $tmp_err_msg
cp -a "$_config_file" "${_config_file}.${backup_date}" 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
_backup_file="${_config_file}.${_date}"
_backup_file="${_config_file}.${backup_date}"
fi
installation_failed=false
@ -1722,7 +1791,6 @@ fi
# - Adjust /etc/spamassassin/v312.pre
# -
_config_file=/etc/spamassassin/v312.pre
_date="$(date +%Y-%m-%d-%H%M)"
_backup_file=""
if [[ ! -f "${_config_file}.ORIG" ]]; then
echononl " Save installation version of ${_config_file} (Suffix \".ORIG\")"
@ -1736,10 +1804,10 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
fi
else
echononl " Backup $_config_file"
cp -a "$_config_file" "${_config_file}.${_date}" 2> $tmp_err_msg
cp -a "$_config_file" "${_config_file}.${backup_date}" 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
_backup_file=${_config_file}.${_date}
_backup_file=${_config_file}.${backup_date}
else
echo_failed
error "$(cat $tmp_err_msg)"
@ -1771,7 +1839,6 @@ fi
# - Adjust /etc/spamassassin/v320.pre
# -
_config_file=/etc/spamassassin/v320.pre
_date="$(date +%Y-%m-%d-%H%M)"
_backup_file=""
if [[ ! -f "${_config_file}.ORIG" ]]; then
echononl " Save installation version of ${_config_file} (Suffix \".ORIG\")"
@ -1785,14 +1852,14 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
_backup_file="${_config_file}.ORIG"
else
echononl " Backup $_config_file"
cp -a "$_config_file" "${_config_file}.${_date}" 2> $tmp_err_msg
cp -a "$_config_file" "${_config_file}.${backup_date}" 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
else
echo_failed
error "$(cat $tmp_err_msg)"
fi
_backup_file="${_config_file}.${_date}"
_backup_file="${_config_file}.${backup_date}"
fi
installation_failed=false
@ -1839,41 +1906,62 @@ fi
# - Add a cronjob for cleaning up bayes
# -
echononl " Add a cronjob for updating clamav (and freshclam) packages"
if ! grep -i -E "/usr/bin/sa-learn\s+--sync" /var/spool/cron/crontabs/root > /dev/null 2> $tmp_err_msg ; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
echononl " Add a cronjob for cleaning up bayes"
if [[ -f "$crontab_backup_file" ]]; then
if ! grep -i -E "/usr/bin/sa-learn\s+--sync" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Cleanup sa bayes for espired entries
# -
33 3 * * * su amavis -lc "/usr/bin/sa-learn --sync >/dev/null" ; su amavis -lc "/usr/bin/sa-learn --sync --force-expire >/dev/null"
EOF
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
cat << EOF >> /tmp/tmp_crontab
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "/usr/bin/sa-learn\s+--sync" /var/spool/cron/crontabs/root > /dev/null 2> $tmp_err_msg ; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Cleanup sa bayes for espired entries
# -
33 3 * * * su amavis -lc "/usr/bin/sa-learn --sync >/dev/null" ; su amavis -lc "/usr/bin/sa-learn --sync --force-expire >/dev/null"
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
# - !! Notice !!
@ -2154,40 +2242,62 @@ fi
# - Add a cronjob for spamassassin updates
# -
echononl " Add a cronjob for spamassassin updates"
if ! grep -i -E "/root/bin/sa-update.sh" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if [[ -f "$crontab_backup_file" ]]; then
cat << EOF >> /tmp/tmp_crontab
if ! grep -i -E "/root/bin/sa-update.sh" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Update spamassassin rules
# -
33 1 * * * /root/bin/sa-update.sh
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "/root/bin/sa-update.sh" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Update spamassassin rules
# -
33 1 * * * /root/bin/sa-update.sh
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
@ -2257,40 +2367,62 @@ fi
# - Add a cronjob for compiling rules
# -
echononl " Add a cronjob for compiling rules"
if ! grep -i -E "/root/bin/sa-compile.sh" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if [[ -f "$crontab_backup_file" ]]; then
cat << EOF >> /tmp/tmp_crontab
if ! grep -i -E "/root/bin/sa-compile.sh" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Compiling rules (SpamAssassin)
# -
53 0 * * * /root/bin/sa-compile.sh
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "/root/bin/sa-compile.sh" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Compiling rules (SpamAssassin)
# -
53 0 * * * /root/bin/sa-compile.sh
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
echononl " Restart spamassassin"
@ -2457,40 +2589,62 @@ fi
## -
## -
echononl " Add a cronjob for updating clamav (and freshclam) packages"
if ! grep -i -E "/usr/bin/apt-get\s+.*clamav-daemon" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if [[ -f "$crontab_backup_file" ]]; then
cat << EOF >> /tmp/tmp_crontab
if ! grep -i -E "/usr/bin/apt-get\s+.*clamav-daemon" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Update clamav (and freshclam) software packages
# -
03 0 * * * /usr/bin/apt-get update > /dev/null ; PATH=/bin:/sbin:/usr/bin:/usr/sbin /usr/bin/apt-get -y install -t stable-updates clamav clamav-base clamav-docs clamav-daemon clamav-freshclam > /dev/null
03 0 * * * /usr/bin/apt-get update > /dev/null ; PATH=/bin:/sbin:/usr/bin:/usr/sbin /usr/bin/apt-get -y install clamav clamav-base clamav-docs clamav-daemon clamav-freshclam > /dev/null
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "/usr/bin/apt-get\s+.*clamav-daemon" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Update clamav (and freshclam) software packages
# -
03 0 * * * /usr/bin/apt-get update > /dev/null ; PATH=/bin:/sbin:/usr/bin:/usr/sbin /usr/bin/apt-get -y install clamav clamav-base clamav-docs clamav-daemon clamav-freshclam > /dev/null
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
@ -2953,7 +3107,6 @@ fi
## -
_config_file=/etc/amavis/conf.d/50-user
_date="$(date +%Y-%m-%d-%H%M)"
if [[ ! -f "/etc/amavis/$(basename ${_config_file}).ORIG" ]]; then
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
cp -a "$_config_file" "/etc/amavis/$(basename ${_config_file}).ORIG" > /dev/null 2> $tmp_err_msg
@ -2965,7 +3118,7 @@ if [[ ! -f "/etc/amavis/$(basename ${_config_file}).ORIG" ]]; then
fi
else
echononl " Backup $_config_file"
cp -a "$_config_file" "/etc/amavis/$(basename ${_config_file}).${_date}" 2> $tmp_err_msg
cp -a "$_config_file" "/etc/amavis/$(basename ${_config_file}).${backup_date}" 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -3307,10 +3460,10 @@ if ! $installation_failed ; then
echo_ok
fi
if [[ -f "/etc/amavis/$(basename ${_config_file}).${_date}" ]]; then
if diff "${_config_file}" "/etc/amavis/$(basename ${_config_file}).${_date}" > /dev/null 2>&1 ; then
if [[ -f "/etc/amavis/$(basename ${_config_file}).${backup_date}" ]]; then
if diff "${_config_file}" "/etc/amavis/$(basename ${_config_file}).${backup_date}" > /dev/null 2>&1 ; then
info "${_config_file} has not changed.\n\t Removing previos created backup.."
rm "/etc/amavis/$(basename ${_config_file}).${_date}"
rm "/etc/amavis/$(basename ${_config_file}).${backup_date}"
fi
fi
@ -3388,15 +3541,10 @@ fi
## - Add a crontab to cleanup the quarantine folder
## -
echononl " Add a cronjob to cleanup the quarantine folder"
if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if [[ -f "$crontab_backup_file" ]]; then
cat << EOF >> /tmp/tmp_crontab
if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" "$crontab_backup_file" > /dev/null 2>&1; then
cat << EOF >> $crontab_backup_file
# - Remove old quarantined messages (>30 days).
# -
@ -3411,25 +3559,60 @@ if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" /var/spool/cron/c
# - Bad headers
0 3 * * * find ${QUARANTINE_DIR}/bad-headers -type f -name "badh-*" -mtime +30 -exec rm {} \;
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
if [[ "$?" -ne 0 ]] ; then
echo_failed
else
echo_ok
fi
else
echo_skipped
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
elif [[ -f "/var/spool/cron/crontabs/root" ]] ; then
if ! grep -i -E "find\s+${QUARANTINE_DIR}/spam\s+-type\s+f\s+" /var/spool/cron/crontabs/root > /dev/null 2>&1; then
installation_failed=false
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
cat << EOF >> /tmp/tmp_crontab
# - Remove old quarantined messages (>30 days).
# -
# - Spam
0 3 * * * find ${QUARANTINE_DIR}/spam -type f -name "spam-*" -mtime +30 -exec rm {} \;
# - Spammy
0 3 * * * find ${QUARANTINE_DIR}/spammy -type f -name "spammy-*" -mtime +30 -exec rm {} \;
# - Virus
0 3 * * * find ${QUARANTINE_DIR}/virus -type f -name "virus-*" -mtime +30 -exec rm {} \;
# - Banned files
0 3 * * * find ${QUARANTINE_DIR}/banned -type f -name "banned-*" -mtime +30 -exec rm {} \;
# - Bad headers
0 3 * * * find ${QUARANTINE_DIR}/bad-headers -type f -name "badh-*" -mtime +30 -exec rm {} \;
EOF
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
crontab /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
rm /tmp/tmp_crontab > /dev/null 2> $tmp_err_msg
if [[ "$?" -ne 0 ]] ; then
installation_failed=true
error "$(cat $tmp_err_msg)"
fi
if ! $installation_failed ; then
echo_ok
fi
else
echo_skipped
fi
@ -3488,10 +3671,9 @@ fi
## - -o receive_override_options=no_unknown_recipient_checks
## -
postfix_master_cf="/etc/postfix/master.cf"
_date=$(date +%Y-%m-%d-%H%M)
echo ""
echononl " Backup file \"${postfix_master_cf}\""
cp -a $postfix_master_cf "${postfix_master_cf}.$_date" > /dev/null 2> $tmp_err_msg
cp -a $postfix_master_cf "${postfix_master_cf}.$backup_date" > /dev/null 2> $tmp_err_msg
if [[ $? -eq 0 ]] ; then
echo_ok
else
@ -3684,12 +3866,23 @@ EOF
_found=false
echo "$_line" >> $postfix_master_cf
done < "${postfix_master_cf}.$_date"
done < "${postfix_master_cf}.$backup_date"
echo_done
warn "Please check file \"$postfix_master_cf\" !"
echononl " Reenable previously saved crontab from '$crontab_backup_file'.."
crontab $crontab_backup_file > $tmp_err_msg 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
# ---
# --- Restart Services
# ---