chore: `check-for-change.sh` - Support VHOST change visibility

- Moves the "handle changes" logic into it's own scoped function, out of the main change detection loop logic.
- This will be benefit a future commit change that will rely on `VHOST_UPDATED=1`.
This commit is contained in:
polarathene 2024-01-28 16:32:26 +13:00
parent 33a911d6cf
commit 9eabef9102
1 changed files with 27 additions and 22 deletions

View File

@ -49,8 +49,28 @@ function _check_for_changes() {
local CHANGED local CHANGED
CHANGED=$(_get_changed_files "${CHKSUM_FILE}" "${CHKSUM_FILE}.new") CHANGED=$(_get_changed_files "${CHKSUM_FILE}" "${CHKSUM_FILE}.new")
_handle_changes
_remove_lock
_log_with_date 'debug' 'Completed handling of detected change'
# mark changes as applied
mv "${CHKSUM_FILE}.new" "${CHKSUM_FILE}"
fi
}
function _handle_changes() {
# Variable to identify any config updates dependent upon vhost changes.
local VHOST_UPDATED=0
# These two configs are the source for /etc/postfix/vhost (managed mail domains)
if [[ ${CHANGED} =~ ${DMS_DIR}/postfix-(accounts|virtual).cf ]]; then
_log_with_date 'trace' 'Regenerating vhosts (Postfix)'
# Regenerate via `helpers/postfix.sh`:
_create_postfix_vhost
VHOST_UPDATED=1
fi
# Handle any changes
_ssl_changes _ssl_changes
_postfix_dovecot_changes _postfix_dovecot_changes
_rspamd_changes _rspamd_changes
@ -60,13 +80,6 @@ function _check_for_changes() {
[[ ${ENABLE_AMAVIS} -eq 1 ]] && _reload_amavis [[ ${ENABLE_AMAVIS} -eq 1 ]] && _reload_amavis
_reload_postfix _reload_postfix
[[ ${SMTP_ONLY} -ne 1 ]] && dovecot reload [[ ${SMTP_ONLY} -ne 1 ]] && dovecot reload
_remove_lock
_log_with_date 'debug' 'Completed handling of detected change'
# mark changes as applied
mv "${CHKSUM_FILE}.new" "${CHKSUM_FILE}"
fi
} }
function _get_changed_files() { function _get_changed_files() {
@ -85,9 +98,9 @@ function _get_changed_files() {
} }
function _reload_amavis() { function _reload_amavis() {
if [[ ${CHANGED} =~ ${DMS_DIR}/postfix-accounts.cf ]] || [[ ${CHANGED} =~ ${DMS_DIR}/postfix-virtual.cf ]]; then
# /etc/postfix/vhost was updated, amavis must refresh it's config by # /etc/postfix/vhost was updated, amavis must refresh it's config by
# reading this file again in case of new domains, otherwise they will be ignored. # reading this file again in case of new domains, otherwise they will be ignored.
if [[ ${VHOST_UPDATED} -eq 1 ]]; then
amavisd reload amavisd reload
fi fi
} }
@ -129,14 +142,6 @@ function _postfix_dovecot_changes() {
[[ ${CHANGED} =~ ${DMS_DIR}/postfix-regexp.cf ]] && _handle_postfix_regexp_config [[ ${CHANGED} =~ ${DMS_DIR}/postfix-regexp.cf ]] && _handle_postfix_regexp_config
[[ ${CHANGED} =~ ${DMS_DIR}/postfix-aliases.cf ]] && _handle_postfix_aliases_config [[ ${CHANGED} =~ ${DMS_DIR}/postfix-aliases.cf ]] && _handle_postfix_aliases_config
# Regenerate `/etc/postfix/vhost` (managed mail domains) via `helpers/postfix.sh`:
if [[ ${CHANGED} =~ ${DMS_DIR}/postfix-accounts.cf ]] \
|| [[ ${CHANGED} =~ ${DMS_DIR}/postfix-virtual.cf ]]
then
_log_with_date 'trace' 'Regenerating vhosts (Postfix)'
_create_postfix_vhost
fi
# Legacy workaround handled here, only seems necessary for _create_accounts: # Legacy workaround handled here, only seems necessary for _create_accounts:
# - `helpers/accounts.sh` logic creates folders/files with wrong ownership. # - `helpers/accounts.sh` logic creates folders/files with wrong ownership.
_chown_var_mail_if_necessary _chown_var_mail_if_necessary