Reorganise cronjob creation.
This commit is contained in:
parent
c661291fd3
commit
309df07e84
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ postfixadmin-*
|
|||||||
/dcc*
|
/dcc*
|
||||||
*.log
|
*.log
|
||||||
*.tar.Z
|
*.tar.Z
|
||||||
|
crontab-root*
|
||||||
|
|
||||||
# - Dovecot
|
# - Dovecot
|
||||||
dovecot*
|
dovecot*
|
||||||
|
@ -75,6 +75,9 @@ echo ""
|
|||||||
script_dir="$(realpath $(dirname $0))"
|
script_dir="$(realpath $(dirname $0))"
|
||||||
conf_file="${script_dir}/conf/install_amavis.conf"
|
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
|
if [[ -f "$conf_file" ]]; then
|
||||||
source $conf_file
|
source $conf_file
|
||||||
fi
|
fi
|
||||||
@ -793,6 +796,35 @@ if ! $installation_failed ; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
fi
|
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
|
## - Install package amavisd-new NOW, because we need at least the existence
|
||||||
## - of the AmaViS user (amavis) befor finally installation and configuration
|
## - of the AmaViS user (amavis) befor finally installation and configuration
|
||||||
## - of AmaViS itself.
|
## - of AmaViS itself.
|
||||||
@ -934,8 +966,6 @@ echo -e " \033[37m\033[1mConfigure Razor2..\033[m"
|
|||||||
|
|
||||||
info "Open firewall outgoing port 2703 for Razor2"
|
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
|
## - This next section gets Razor2 up and running and copies its files where
|
||||||
## - both root and amavis expect to find them.
|
## - both root and amavis expect to find them.
|
||||||
## -
|
## -
|
||||||
@ -973,7 +1003,7 @@ fi
|
|||||||
|
|
||||||
echononl " Backup directory \"/root/.razor.\""
|
echononl " Backup directory \"/root/.razor.\""
|
||||||
if [[ -d /root/.razor ]] ; then
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -1035,7 +1065,7 @@ fi
|
|||||||
_home_amavais=$(realpath ~amavis)
|
_home_amavais=$(realpath ~amavis)
|
||||||
echononl " Backup directory \"${_home_amavais}/.razor\""
|
echononl " Backup directory \"${_home_amavais}/.razor\""
|
||||||
if [[ -d "${_home_amavais}/.razor" ]] ; then
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -1062,9 +1092,9 @@ if [[ "$?" -ne 0 ]] ; then
|
|||||||
fi
|
fi
|
||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
if [[ -d "${_home_amavais}/.razor.${_date}" ]] ; then
|
if [[ -d "${_home_amavais}/.razor.${backup_date}" ]] ; then
|
||||||
echononl " Delete previous created backup \"${_home_amavais}/.razor.${_date}\""
|
echononl " Delete previous created backup \"${_home_amavais}/.razor.${backup_date}\""
|
||||||
rm -r "${_home_amavais}/.razor.${_date}" > /dev/null 2>&1
|
rm -r "${_home_amavais}/.razor.${backup_date}" > /dev/null 2>&1
|
||||||
if [[ $? -eq 0 ]] ; then
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -1072,9 +1102,9 @@ if ! $installation_failed ; then
|
|||||||
error "$(cat $tmp_err_msg)"
|
error "$(cat $tmp_err_msg)"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ -d "/root/.razor.${_date}" ]] ; then
|
if [[ -d "/root/.razor.${backup_date}" ]] ; then
|
||||||
echononl " Delete previous created backup \"/root/.razor.${_date}\""
|
echononl " Delete previous created backup \"/root/.razor.${backup_date}\""
|
||||||
rm -r "/root/.razor.${_date}" > /dev/null 2>&1
|
rm -r "/root/.razor.${backup_date}" > /dev/null 2>&1
|
||||||
if [[ $? -eq 0 ]] ; then
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -1088,8 +1118,26 @@ fi
|
|||||||
## - Aadd a cronjob for razor2 updates
|
## - Aadd a cronjob for razor2 updates
|
||||||
## -
|
## -
|
||||||
## -
|
## -
|
||||||
echononl " add 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
|
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
|
||||||
|
echo_failed
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
fi
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -1120,8 +1168,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -1271,7 +1320,28 @@ fi
|
|||||||
## -
|
## -
|
||||||
## -
|
## -
|
||||||
echononl " Add a cronjob for updating and cleaning up dcc"
|
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
|
if [[ -f "$crontab_backup_file" ]]; then
|
||||||
|
|
||||||
|
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
|
||||||
|
echo_failed
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -1303,8 +1373,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_config_file=/var/dcc/dcc_conf
|
_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
|
## - Backup existing SpamAssassin's main configuration file /etc/spamassassin/local.cf
|
||||||
## -
|
## -
|
||||||
_config_file=/etc/spamassassin/local.cf
|
_config_file=/etc/spamassassin/local.cf
|
||||||
_date="$(date +%Y-%m-%d-%H%M)"
|
|
||||||
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
||||||
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
|
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
|
||||||
cp -a "$_config_file" "${_config_file}.ORIG" > /dev/null 2> $tmp_err_msg
|
cp -a "$_config_file" "${_config_file}.ORIG" > /dev/null 2> $tmp_err_msg
|
||||||
@ -1394,7 +1464,7 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echononl " Backup $_config_file"
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -1644,10 +1714,10 @@ if ! $installation_failed ; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "${_config_file}.${_date}" ]]; then
|
if [[ -f "${_config_file}.${backup_date}" ]]; then
|
||||||
if diff "${_config_file}" "${_config_file}.${_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.."
|
info "${_config_file} has not changed.\n\t Removing previos created backup.."
|
||||||
rm "${_config_file}.${_date}"
|
rm "${_config_file}.${backup_date}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -1655,7 +1725,6 @@ fi
|
|||||||
# - Adjust /etc/spamassassin/v310.pre
|
# - Adjust /etc/spamassassin/v310.pre
|
||||||
# -
|
# -
|
||||||
_config_file=/etc/spamassassin/v310.pre
|
_config_file=/etc/spamassassin/v310.pre
|
||||||
_date="$(date +%Y-%m-%d-%H%M)"
|
|
||||||
_backup_file=""
|
_backup_file=""
|
||||||
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
||||||
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
|
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
|
||||||
@ -1669,14 +1738,14 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
|
|||||||
_backup_file="${_config_file}.ORIG"
|
_backup_file="${_config_file}.ORIG"
|
||||||
else
|
else
|
||||||
echononl " Backup $_config_file"
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_failed
|
||||||
error "$(cat $tmp_err_msg)"
|
error "$(cat $tmp_err_msg)"
|
||||||
fi
|
fi
|
||||||
_backup_file="${_config_file}.${_date}"
|
_backup_file="${_config_file}.${backup_date}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
installation_failed=false
|
installation_failed=false
|
||||||
@ -1722,7 +1791,6 @@ fi
|
|||||||
# - Adjust /etc/spamassassin/v312.pre
|
# - Adjust /etc/spamassassin/v312.pre
|
||||||
# -
|
# -
|
||||||
_config_file=/etc/spamassassin/v312.pre
|
_config_file=/etc/spamassassin/v312.pre
|
||||||
_date="$(date +%Y-%m-%d-%H%M)"
|
|
||||||
_backup_file=""
|
_backup_file=""
|
||||||
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
||||||
echononl " Save installation version of ${_config_file} (Suffix \".ORIG\")"
|
echononl " Save installation version of ${_config_file} (Suffix \".ORIG\")"
|
||||||
@ -1736,10 +1804,10 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echononl " Backup $_config_file"
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
_backup_file=${_config_file}.${_date}
|
_backup_file=${_config_file}.${backup_date}
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_failed
|
||||||
error "$(cat $tmp_err_msg)"
|
error "$(cat $tmp_err_msg)"
|
||||||
@ -1771,7 +1839,6 @@ fi
|
|||||||
# - Adjust /etc/spamassassin/v320.pre
|
# - Adjust /etc/spamassassin/v320.pre
|
||||||
# -
|
# -
|
||||||
_config_file=/etc/spamassassin/v320.pre
|
_config_file=/etc/spamassassin/v320.pre
|
||||||
_date="$(date +%Y-%m-%d-%H%M)"
|
|
||||||
_backup_file=""
|
_backup_file=""
|
||||||
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
if [[ ! -f "${_config_file}.ORIG" ]]; then
|
||||||
echononl " Save installation version of ${_config_file} (Suffix \".ORIG\")"
|
echononl " Save installation version of ${_config_file} (Suffix \".ORIG\")"
|
||||||
@ -1785,14 +1852,14 @@ if [[ ! -f "${_config_file}.ORIG" ]]; then
|
|||||||
_backup_file="${_config_file}.ORIG"
|
_backup_file="${_config_file}.ORIG"
|
||||||
else
|
else
|
||||||
echononl " Backup $_config_file"
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
echo_failed
|
echo_failed
|
||||||
error "$(cat $tmp_err_msg)"
|
error "$(cat $tmp_err_msg)"
|
||||||
fi
|
fi
|
||||||
_backup_file="${_config_file}.${_date}"
|
_backup_file="${_config_file}.${backup_date}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
installation_failed=false
|
installation_failed=false
|
||||||
@ -1839,8 +1906,28 @@ fi
|
|||||||
|
|
||||||
# - Add a cronjob for cleaning up bayes
|
# - Add a cronjob for cleaning up bayes
|
||||||
# -
|
# -
|
||||||
echononl " Add a cronjob for updating clamav (and freshclam) packages"
|
echononl " Add a cronjob for cleaning up bayes"
|
||||||
if ! grep -i -E "/usr/bin/sa-learn\s+--sync" /var/spool/cron/crontabs/root > /dev/null 2> $tmp_err_msg ; then
|
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
|
||||||
|
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -1872,8 +1959,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# - !! Notice !!
|
# - !! Notice !!
|
||||||
@ -2154,7 +2242,28 @@ fi
|
|||||||
# - Add a cronjob for spamassassin updates
|
# - Add a cronjob for spamassassin updates
|
||||||
# -
|
# -
|
||||||
echononl " 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
|
if [[ -f "$crontab_backup_file" ]]; then
|
||||||
|
|
||||||
|
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
|
||||||
|
echo_failed
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -2186,8 +2295,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -2257,7 +2367,28 @@ fi
|
|||||||
# - Add a cronjob for compiling rules
|
# - Add a cronjob for compiling rules
|
||||||
# -
|
# -
|
||||||
echononl " 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
|
if [[ -f "$crontab_backup_file" ]]; then
|
||||||
|
|
||||||
|
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
|
||||||
|
echo_failed
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -2289,8 +2420,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echononl " Restart spamassassin"
|
echononl " Restart spamassassin"
|
||||||
@ -2457,7 +2589,28 @@ fi
|
|||||||
## -
|
## -
|
||||||
## -
|
## -
|
||||||
echononl " Add a cronjob for updating clamav (and freshclam) packages"
|
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
|
if [[ -f "$crontab_backup_file" ]]; then
|
||||||
|
|
||||||
|
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 clamav clamav-base clamav-docs clamav-daemon clamav-freshclam > /dev/null
|
||||||
|
|
||||||
|
EOF
|
||||||
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
|
echo_failed
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -2469,7 +2622,7 @@ if ! grep -i -E "/usr/bin/apt-get\s+.*clamav-daemon" /var/spool/cron/crontabs/ro
|
|||||||
|
|
||||||
# - Update clamav (and freshclam) software packages
|
# - 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
|
EOF
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -2489,8 +2642,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -2953,7 +3107,6 @@ fi
|
|||||||
## -
|
## -
|
||||||
|
|
||||||
_config_file=/etc/amavis/conf.d/50-user
|
_config_file=/etc/amavis/conf.d/50-user
|
||||||
_date="$(date +%Y-%m-%d-%H%M)"
|
|
||||||
if [[ ! -f "/etc/amavis/$(basename ${_config_file}).ORIG" ]]; then
|
if [[ ! -f "/etc/amavis/$(basename ${_config_file}).ORIG" ]]; then
|
||||||
echononl " Save installation version of ${_config_file} (Suffix \".ORIF\")"
|
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
|
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
|
fi
|
||||||
else
|
else
|
||||||
echononl " Backup $_config_file"
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -3307,10 +3460,10 @@ if ! $installation_failed ; then
|
|||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "/etc/amavis/$(basename ${_config_file}).${_date}" ]]; then
|
if [[ -f "/etc/amavis/$(basename ${_config_file}).${backup_date}" ]]; then
|
||||||
if diff "${_config_file}" "/etc/amavis/$(basename ${_config_file}).${_date}" > /dev/null 2>&1 ; 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.."
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -3388,7 +3541,36 @@ fi
|
|||||||
## - Add a crontab to cleanup the quarantine folder
|
## - Add a crontab to cleanup the quarantine folder
|
||||||
## -
|
## -
|
||||||
echononl " Add a cronjob 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
|
if [[ -f "$crontab_backup_file" ]]; then
|
||||||
|
|
||||||
|
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).
|
||||||
|
# -
|
||||||
|
# - 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
|
||||||
|
echo_failed
|
||||||
|
else
|
||||||
|
echo_ok
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo_skipped
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
installation_failed=false
|
||||||
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
crontab -l > /tmp/tmp_crontab 2> $tmp_err_msg
|
||||||
if [[ "$?" -ne 0 ]] ; then
|
if [[ "$?" -ne 0 ]] ; then
|
||||||
@ -3428,8 +3610,9 @@ EOF
|
|||||||
if ! $installation_failed ; then
|
if ! $installation_failed ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo_skipped
|
echo_skipped
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -3488,10 +3671,9 @@ fi
|
|||||||
## - -o receive_override_options=no_unknown_recipient_checks
|
## - -o receive_override_options=no_unknown_recipient_checks
|
||||||
## -
|
## -
|
||||||
postfix_master_cf="/etc/postfix/master.cf"
|
postfix_master_cf="/etc/postfix/master.cf"
|
||||||
_date=$(date +%Y-%m-%d-%H%M)
|
|
||||||
echo ""
|
echo ""
|
||||||
echononl " Backup file \"${postfix_master_cf}\""
|
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
|
if [[ $? -eq 0 ]] ; then
|
||||||
echo_ok
|
echo_ok
|
||||||
else
|
else
|
||||||
@ -3684,12 +3866,23 @@ EOF
|
|||||||
_found=false
|
_found=false
|
||||||
|
|
||||||
echo "$_line" >> $postfix_master_cf
|
echo "$_line" >> $postfix_master_cf
|
||||||
done < "${postfix_master_cf}.$_date"
|
done < "${postfix_master_cf}.$backup_date"
|
||||||
|
|
||||||
echo_done
|
echo_done
|
||||||
warn "Please check file \"$postfix_master_cf\" !"
|
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
|
# --- Restart Services
|
||||||
# ---
|
# ---
|
||||||
|
Loading…
Reference in New Issue
Block a user