chore: reduce nesting and improve readability in `mail_state.sh`

Signed-off-by: georglauterbach <44545919+georglauterbach@users.noreply.github.com>
This commit is contained in:
georglauterbach 2025-01-19 12:02:42 +01:00
parent a6fe9f5bcc
commit 65f419d741
No known key found for this signature in database
GPG Key ID: F367F7C43C118578
1 changed files with 107 additions and 107 deletions

View File

@ -3,17 +3,17 @@
# Consolidate all states into a single directory
# (/var/mail-state) to allow persistence using docker volumes
function _setup_save_states() {
local DEST DESTDIR SERVICEDIR SERVICEDIRS SERVICEFILE SERVICEFILES
if [[ ! -d ${DMS_STATE_DIR:?DMS_STATE_DIR is not set} ]]; then
_log 'debug' "'${DMS_STATE_DIR}' is not present - not consolidating state"
return 0
fi
if [[ -d ${DMS_STATE_DIR} ]]; then
_log 'debug' "Consolidating all state onto ${DMS_STATE_DIR}"
local DEST DESTDIR SERVICEDIR SERVICEDIRS SERVICEFILE SERVICEFILES
# Always enabled features:
SERVICEDIRS=(
lib/logrotate
lib/postfix
spool/postfix
)
SERVICEDIRS=( 'lib/logrotate' 'lib/postfix' 'spool/postfix' )
# Only consolidate state for services that are enabled
# Notably avoids copying over 200MB for the ClamAV database
@ -81,13 +81,14 @@ function _setup_save_states() {
# sourced from assocaiated path in /var/mail-state/ ($DEST):
ln -s "${DEST}" "${SERVICEDIR}"
done
else
_log 'debug' "'${DMS_STATE_DIR}' is not present; Not consolidating state"
fi
}
function _setup_adjust_state_permissions() {
if [[ -d ${DMS_STATE_DIR} ]]; then
if [[ ! -d ${DMS_STATE_DIR:?DMS_STATE_DIR is not set} ]]; then
_log 'debug' "'${DMS_STATE_DIR}' is not present - not adjusting state permissions"
return 0
fi
# This ensures the user and group of the files from the external mount have their
# numeric ID values in sync. New releases where the installed packages order changes
# can change the values in the Docker image, causing an ownership mismatch.
@ -123,5 +124,4 @@ function _setup_adjust_state_permissions() {
# Ref: https://github.com/docker-mailserver/docker-mailserver/pull/3625
chmod 730 "${DMS_STATE_DIR}/spool-postfix/maildrop"
chmod 710 "${DMS_STATE_DIR}/spool-postfix/public"
fi
}