2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2021-02-23 19:03:01 +00:00
|
|
|
|
2022-05-15 21:37:21 +00:00
|
|
|
function _start_misc
|
2021-02-23 19:03:01 +00:00
|
|
|
{
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'info' 'Starting miscellaneous tasks'
|
2021-02-23 19:03:01 +00:00
|
|
|
for FUNC in "${FUNCS_MISC[@]}"
|
|
|
|
do
|
2021-09-23 17:49:07 +00:00
|
|
|
${FUNC}
|
2021-02-23 19:03:01 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# consolidate all states into a single directory
|
|
|
|
# (/var/mail-state) to allow persistence using docker volumes
|
|
|
|
function _misc_save_states
|
|
|
|
{
|
|
|
|
local STATEDIR FILE FILES
|
|
|
|
|
|
|
|
STATEDIR='/var/mail-state'
|
|
|
|
|
|
|
|
if [[ ${ONE_DIR} -eq 1 ]] && [[ -d ${STATEDIR} ]]
|
|
|
|
then
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'debug' "Consolidating all state onto ${STATEDIR}"
|
2021-02-23 19:03:01 +00:00
|
|
|
|
|
|
|
FILES=(
|
|
|
|
spool/postfix
|
|
|
|
lib/postfix
|
|
|
|
)
|
|
|
|
|
2022-06-05 00:02:25 +00:00
|
|
|
# Only consolidate state for services that are enabled
|
|
|
|
# Notably avoids copying over 200MB for the ClamAV database
|
|
|
|
[[ ${ENABLE_AMAVIS} -eq 1 ]] && FILES+=('lib/amavis')
|
|
|
|
[[ ${ENABLE_CLAMAV} -eq 1 ]] && FILES+=('lib/clamav')
|
|
|
|
[[ ${ENABLE_FAIL2BAN} -eq 1 ]] && FILES+=('lib/fail2ban')
|
2022-10-23 01:12:27 +00:00
|
|
|
[[ ${ENABLE_FETCHMAIL} -eq 1 ]] && FILES+=('lib/fetchmail')
|
2022-06-05 00:02:25 +00:00
|
|
|
[[ ${ENABLE_POSTGREY} -eq 1 ]] && FILES+=('lib/postgrey')
|
2023-01-05 07:39:00 +00:00
|
|
|
[[ ${ENABLE_RSPAMD} -ne 1 ]] && FILES+=('lib/rspamd')
|
|
|
|
# [[ ${ENABLE_RSPAMD} -ne 1 ]] && FILES+=('lib/redis')
|
2022-10-23 01:12:27 +00:00
|
|
|
[[ ${ENABLE_SPAMASSASSIN} -eq 1 ]] && FILES+=('lib/spamassassin')
|
2022-06-05 00:02:25 +00:00
|
|
|
[[ ${SMTP_ONLY} -ne 1 ]] && FILES+=('lib/dovecot')
|
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
for FILE in "${FILES[@]}"
|
|
|
|
do
|
|
|
|
DEST="${STATEDIR}/${FILE//\//-}"
|
|
|
|
FILE="/var/${FILE}"
|
|
|
|
|
|
|
|
if [[ -d ${DEST} ]]
|
|
|
|
then
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "Destination ${DEST} exists, linking ${FILE} to it"
|
2021-02-23 19:03:01 +00:00
|
|
|
rm -rf "${FILE}"
|
|
|
|
ln -s "${DEST}" "${FILE}"
|
|
|
|
elif [[ -d ${FILE} ]]
|
|
|
|
then
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "Moving contents of ${FILE} to ${DEST}"
|
2021-02-23 19:03:01 +00:00
|
|
|
mv "${FILE}" "${DEST}"
|
|
|
|
ln -s "${DEST}" "${FILE}"
|
|
|
|
else
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' "Linking ${FILE} to ${DEST}"
|
2021-02-23 19:03:01 +00:00
|
|
|
mkdir -p "${DEST}"
|
|
|
|
ln -s "${DEST}" "${FILE}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-03-21 06:07:52 +00:00
|
|
|
_log 'trace' 'Fixing /var/mail-state/* permissions'
|
2022-06-05 00:02:25 +00:00
|
|
|
[[ ${ENABLE_CLAMAV} -eq 1 ]] && chown -R clamav /var/mail-state/lib-clamav
|
|
|
|
[[ ${ENABLE_SPAMASSASSIN} -eq 1 ]] && chown -R debian-spamd /var/mail-state/lib-spamassassin
|
|
|
|
[[ ${ENABLE_POSTGREY} -eq 1 ]] && chown -R postgrey /var/mail-state/lib-postgrey
|
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
chown -R postfix /var/mail-state/lib-postfix
|
2021-10-31 21:23:00 +00:00
|
|
|
|
|
|
|
# UID = postfix(101): active, bounce, corrupt, defer, deferred, flush, hold, incoming, maildrop, private, public, saved, trace
|
|
|
|
# UID = root(0): dev, etc, lib, pid, usr
|
|
|
|
# GID = postdrop(103): maildrop, public
|
|
|
|
# GID for all other directories is root(0)
|
|
|
|
# Set most common ownership:
|
|
|
|
chown -R postfix:root /var/mail-state/spool-postfix
|
|
|
|
# These two require the postdrop(103) group:
|
|
|
|
chgrp -R postdrop /var/mail-state/spool-postfix/maildrop
|
|
|
|
chgrp -R postdrop /var/mail-state/spool-postfix/public
|
|
|
|
# These all have root ownership at the src location:
|
|
|
|
chown -R root /var/mail-state/spool-postfix/dev
|
|
|
|
chown -R root /var/mail-state/spool-postfix/etc
|
|
|
|
chown -R root /var/mail-state/spool-postfix/lib
|
|
|
|
chown -R root /var/mail-state/spool-postfix/pid
|
|
|
|
chown -R root /var/mail-state/spool-postfix/usr
|
2021-02-23 19:03:01 +00:00
|
|
|
fi
|
|
|
|
}
|