mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
chore(check-for-changes.sh
): Drop redundant guards (#2623)
* chore: Remove requirement for `postfix-accounts.cf` This is an old requirement from when the change detector service was first introduced. It's no longer relevant. * chore: Do not needlessly create `postfix-aliases.cf` The config was created regardless to workaround early change detection support. No longer necessary to require the file to exist. * chore: Drop guards requiring `/tmp/docker-mailserver` to exist Legacy guards when this was the only location change detection location supported. There does not appear to be any need for changing into this directory at the start of `check-for-changes.sh` as we use absolute filepaths (originally monitored files were checked with relative paths to this config dir). * chore: Revise inline docs * chore: Add change detection monitoring for extra configs These are also handled at run-time in the current change detection support, so it makes sense to allows these config updates to also trigger change events.
This commit is contained in:
parent
0a722276a8
commit
c314c9c471
|
@ -22,17 +22,6 @@ _log_with_date 'debug' 'Starting changedetector'
|
||||||
# to be properly set.
|
# to be properly set.
|
||||||
_obtain_hostname_and_domainname
|
_obtain_hostname_and_domainname
|
||||||
|
|
||||||
if ! cd /tmp/docker-mailserver &>/dev/null
|
|
||||||
then
|
|
||||||
_exit_with_error "Could not change into '/tmp/docker-mailserver/' directory" 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check postfix-accounts.cf exist else break
|
|
||||||
if [[ ! -f postfix-accounts.cf ]]
|
|
||||||
then
|
|
||||||
_exit_with_error "'/tmp/docker-mailserver/postfix-accounts.cf' is missing" 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# verify checksum file exists; must be prepared by start-mailserver.sh
|
# verify checksum file exists; must be prepared by start-mailserver.sh
|
||||||
if [[ ! -f ${CHKSUM_FILE} ]]
|
if [[ ! -f ${CHKSUM_FILE} ]]
|
||||||
then
|
then
|
||||||
|
|
|
@ -61,13 +61,8 @@ function _handle_postfix_aliases_config
|
||||||
|
|
||||||
echo "root: ${POSTMASTER_ADDRESS}" >/etc/aliases
|
echo "root: ${POSTMASTER_ADDRESS}" >/etc/aliases
|
||||||
|
|
||||||
if [[ -f /tmp/docker-mailserver/postfix-aliases.cf ]]
|
local DATABASE_ALIASES='/tmp/docker-mailserver/postfix-aliases.cf'
|
||||||
then
|
[[ -f ${DATABASE_ALIASES} ]] && cat "${DATABASE_ALIASES}" >>/etc/aliases
|
||||||
cat /tmp/docker-mailserver/postfix-aliases.cf >>/etc/aliases
|
|
||||||
else
|
|
||||||
_log 'trace' "'/tmp/docker-mailserver/postfix-aliases.cf' is not provided, it will be auto created."
|
|
||||||
: >/tmp/docker-mailserver/postfix-aliases.cf
|
|
||||||
fi
|
|
||||||
|
|
||||||
postalias /etc/aliases
|
postalias /etc/aliases
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
# - check-for-changes.sh
|
# - check-for-changes.sh
|
||||||
# - test/test_helper/common.bash:wait_for_changes_to_be_detected_in_container()
|
# - test/test_helper/common.bash:wait_for_changes_to_be_detected_in_container()
|
||||||
# - test/test_helper.bats
|
# - test/test_helper.bats
|
||||||
# - start-mailserver.sh --> setup-stack.sh (to initialize the CHKSUM_FILE state)
|
# - 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:
|
# Global checksum file used to track when monitored files have changed in content:
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
@ -16,38 +16,36 @@ function _prepare_for_change_detection
|
||||||
{
|
{
|
||||||
_log 'debug' 'Setting up configuration checksum file'
|
_log 'debug' 'Setting up configuration checksum file'
|
||||||
|
|
||||||
if [[ -d /tmp/docker-mailserver ]]
|
_log 'trace' "Creating '${CHKSUM_FILE}'"
|
||||||
then
|
_monitored_files_checksums >"${CHKSUM_FILE}"
|
||||||
_log 'trace' "Creating '${CHKSUM_FILE}'"
|
|
||||||
_monitored_files_checksums >"${CHKSUM_FILE}"
|
|
||||||
else
|
|
||||||
# We could just skip the file, but perhaps config can be added later?
|
|
||||||
# If so it must be processed by the check for changes script
|
|
||||||
_log 'trace' "Creating empty '${CHKSUM_FILE}' (no config)"
|
|
||||||
touch "${CHKSUM_FILE}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Returns a list of changed files, each line is a value pair of:
|
# Returns a list of changed files, each line is a value pair of:
|
||||||
# <SHA-512 content hash> <changed file path>
|
# <SHA-512 content hash> <changed file path>
|
||||||
function _monitored_files_checksums
|
function _monitored_files_checksums
|
||||||
{
|
{
|
||||||
local DMS_DIR=/tmp/docker-mailserver
|
|
||||||
[[ -d ${DMS_DIR} ]] || return 1
|
|
||||||
|
|
||||||
# If a wildcard path pattern (or an empty ENV) would yield an invalid path
|
# 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.
|
# or no results, `shopt -s nullglob` prevents it from being added.
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
declare -a STAGING_FILES CHANGED_FILES
|
declare -a STAGING_FILES CHANGED_FILES
|
||||||
|
|
||||||
STAGING_FILES=(
|
# Supported user provided configs:
|
||||||
"${DMS_DIR}/postfix-accounts.cf"
|
local DMS_DIR=/tmp/docker-mailserver
|
||||||
"${DMS_DIR}/postfix-virtual.cf"
|
if [[ -d ${DMS_DIR} ]]
|
||||||
"${DMS_DIR}/postfix-aliases.cf"
|
then
|
||||||
"${DMS_DIR}/dovecot-quotas.cf"
|
STAGING_FILES+=(
|
||||||
"${DMS_DIR}/dovecot-masters.cf"
|
"${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"
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# SSL certs:
|
||||||
if [[ ${SSL_TYPE:-} == 'manual' ]]
|
if [[ ${SSL_TYPE:-} == 'manual' ]]
|
||||||
then
|
then
|
||||||
# When using "manual" as the SSL type,
|
# When using "manual" as the SSL type,
|
||||||
|
@ -69,10 +67,11 @@ function _monitored_files_checksums
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If the file actually exists, add to CHANGED_FILES
|
||||||
|
# and generate a content hash entry:
|
||||||
for FILE in "${STAGING_FILES[@]}"
|
for FILE in "${STAGING_FILES[@]}"
|
||||||
do
|
do
|
||||||
[[ -f "${FILE}" ]] && CHANGED_FILES+=("${FILE}")
|
[[ -f "${FILE}" ]] && CHANGED_FILES+=("${FILE}")
|
||||||
done
|
done
|
||||||
|
|
||||||
sha512sum -- "${CHANGED_FILES[@]}"
|
sha512sum -- "${CHANGED_FILES[@]}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue