docker-mailserver/target/scripts/helpers/change-detection.sh
Georg Lauterbach f674232f71
misc: final Rspamd adjustments for v13 (#3599)
* outsource Rspamd ENVs into explicit helper

This will allow us to uniformly source the helper and get the values
from everywhere consistently. This is more than desirable since we will
be using these values not only for the Rspamd setup, but also for DKIM
management and during change-detection.

* integrate Rspamd into changedetection

We outsource one more function to reside in the helper script for Rspamd
so that we can call this function from the Rspamd setup and from the
changedetection functionality too.

* realize deprecation of old commands file for Rspamd

THIS IS A BREAKING CHANGE!

This change realizes the log message: "Using old file location now
(deprecated) - this will prevent startup in v13.0.0" Startup will now
fail.

* added '--force' option to Rspamd DKIM script

* use new helper to get ENVs for Rspamd in DKIM script

* remove the need for linking directories

This was unnecessary, as explained in
https://github.com/docker-mailserver/docker-mailserver/pull/3597#discussion_r1369413599

* Apply suggestions from code review

review by @polarathene

* apply more review feedback from @polarathene

- <https://github.com/docker-mailserver/docker-mailserver/pull/3599#discussion_r1370885519>
- <https://github.com/docker-mailserver/docker-mailserver/pull/3599#discussion_r1370904201>

* update documentation

---------

Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2023-10-30 10:20:37 +01:00

81 lines
2.7 KiB
Bash

#!/bin/bash
# This helper supports the changedetector service. Used by:
# - check-for-changes.sh
# - test/test_helper/common.bash:wait_for_changes_to_be_detected_in_container()
# - test/test_helper.bats
# - start-mailserver.sh --> setup-stack.sh:_setup (to initialize the CHKSUM_FILE state)
# Global checksum file used to track when monitored files have changed in content:
# shellcheck disable=SC2034
CHKSUM_FILE=/tmp/docker-mailserver-config-chksum
# Once container startup scripts complete, take a snapshot of
# the config state via storing a list of files content hashes.
function _prepare_for_change_detection() {
_log 'debug' 'Setting up configuration checksum file'
_log 'trace' "Creating '${CHKSUM_FILE}'"
_monitored_files_checksums >"${CHKSUM_FILE}"
}
# Returns a list of changed files, each line is a value pair of:
# <SHA-512 content hash> <changed file path>
function _monitored_files_checksums() {
# If a wildcard path pattern (or an empty ENV) would yield an invalid path
# or no results, `shopt -s nullglob` prevents it from being added.
shopt -s nullglob
declare -a STAGING_FILES CHANGED_FILES
# Supported user provided configs:
local DMS_DIR=/tmp/docker-mailserver
if [[ -d ${DMS_DIR} ]]; then
STAGING_FILES+=(
"${DMS_DIR}/postfix-accounts.cf"
"${DMS_DIR}/postfix-virtual.cf"
"${DMS_DIR}/postfix-regexp.cf"
"${DMS_DIR}/postfix-aliases.cf"
"${DMS_DIR}/postfix-relaymap.cf"
"${DMS_DIR}/postfix-sasl-password.cf"
"${DMS_DIR}/dovecot-quotas.cf"
"${DMS_DIR}/dovecot-masters.cf"
)
# Check whether Rspamd is used and if so, monitor it's changes as well
if [[ ${ENABLE_RSPAMD} -eq 1 ]] && [[ -d ${RSPAMD_DMS_D} ]]; then
readarray -d '' STAGING_FILES_RSPAMD < <(find "${RSPAMD_DMS_D}" -type f -name "*.sh" -print0)
STAGING_FILES+=("${STAGING_FILES_RSPAMD[@]}")
fi
fi
# SSL certs:
if [[ ${SSL_TYPE:-} == 'manual' ]]; then
# When using "manual" as the SSL type,
# the following variables may contain the certificate files
STAGING_FILES+=(
"${SSL_CERT_PATH:-}"
"${SSL_KEY_PATH:-}"
"${SSL_ALT_CERT_PATH:-}"
"${SSL_ALT_KEY_PATH:-}"
)
elif [[ ${SSL_TYPE:-} == 'letsencrypt' ]]; then
# React to any cert changes within the following LetsEncrypt locations:
STAGING_FILES+=(
/etc/letsencrypt/acme.json
/etc/letsencrypt/live/"${SSL_DOMAIN}"/*.pem
/etc/letsencrypt/live/"${HOSTNAME}"/*.pem
/etc/letsencrypt/live/"${DOMAINNAME}"/*.pem
)
fi
# If the file actually exists, add to CHANGED_FILES
# and generate a content hash entry:
for FILE in "${STAGING_FILES[@]}"; do
[[ -f "${FILE}" ]] && CHANGED_FILES+=("${FILE}")
done
if [[ -n ${CHANGED_FILES:-} ]]; then
sha512sum -- "${CHANGED_FILES[@]}"
fi
}