2021-02-23 19:03:01 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
|
|
|
function start_misc
|
|
|
|
{
|
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
|
|
|
|
lib/amavis
|
|
|
|
lib/clamav
|
|
|
|
lib/spamassassin
|
|
|
|
lib/fail2ban
|
|
|
|
lib/postgrey
|
|
|
|
lib/dovecot
|
|
|
|
)
|
|
|
|
|
|
|
|
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'
|
2021-02-23 19:03:01 +00:00
|
|
|
chown -R clamav /var/mail-state/lib-clamav
|
|
|
|
chown -R postfix /var/mail-state/lib-postfix
|
|
|
|
chown -R postgrey /var/mail-state/lib-postgrey
|
|
|
|
chown -R debian-spamd /var/mail-state/lib-spamassassin
|
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
|
|
|
|
}
|