mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
5254f7c658
Removes duplicate logic from `check-for-changes.sh` that is used/maintained elsewhere to avoid risk of problems, as this code is already starting to diverge / rot. --- Previously the change detection support has had code added for rebuilding config upon change detection which is the same as code run during startup scripts. Unfortunately over time this has fallen out of sync. Mostly the startup scripts would get maintenance and the contributor and reviewers may not have been aware of the duplicate code handled by `check-for-changes.sh`. That code was starting to diverge in addition to some changes in structure (_eg: relay host logic seems interleaved here vs separated out in startup scripts_). I wanted to address this before it risks becoming a much bigger headache. Rather than bloat `helper-functions.sh` further, I've added a `helpers/` folder extracting relevant common logic between startup scripts and `changedetector`. If you want to follow that process I've kept scoped commits to make those diffs easier. Some minor changes/improvements were added but nothing significant. --- - chore: Extract relay host logic to new `relay.sh` helper - chore: Extract `/etc/postfix/sasl_passwd` logic to new `sasl.sh` helper - chore: Extract `postfix-accounts.cf` logic to new `accounts.sh` helper - chore: Extract `/etc/aliases` logic to new `aliases.sh` helper - chore: Extract `/etc/postfix/vhost` logic to new `postfix.sh` helper - chore: Add inline docs for Postfix configs > These are possibly more verbose than needed and can be reduced at a later stage. > They are helpful during this refactor process while investigating that everything is handled correctly. `accounts.sh`: - Add note regarding potential bug for bare domain setups with `/etc/postfix/vhost` and `mydestination` sharing same domain value. `relay.sh`: - Remove the tabs for a single space delimiter, revised associated comment. - Add PR reference for original `_populate_relayhost_map` implementation which has some useful details. Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> Co-authored-by: Casper <casperklein@users.noreply.github.com>
76 lines
2.5 KiB
Bash
Executable file
76 lines
2.5 KiB
Bash
Executable file
#! /bin/bash
|
|
# Support for Postfix aliases
|
|
|
|
# NOTE: LDAP doesn't appear to use this, but the docs page: "Use Cases | Forward-Only Mail-Server with LDAP"
|
|
# does have an example where /etc/postfix/virtual is referenced in addition to ldap config for Postfix `main.cf:virtual_alias_maps`.
|
|
# `setup-stack.sh:_setup_ldap` does not seem to configure for `/etc/postfix/virtual however.`
|
|
|
|
# NOTE: `accounts.sh` and `relay.sh:_populate_relayhost_map` also process on `postfix-virtual.cf`.
|
|
function _handle_postfix_virtual_config
|
|
{
|
|
: >/etc/postfix/virtual
|
|
: >/etc/postfix/regexp
|
|
|
|
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
|
then
|
|
# fixing old virtual user file
|
|
if grep -q ",$" /tmp/docker-mailserver/postfix-virtual.cf
|
|
then
|
|
sed -i -e "s|, |,|g" -e "s|,$||g" /tmp/docker-mailserver/postfix-virtual.cf
|
|
fi
|
|
|
|
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
|
|
|
|
# the `to` is important, don't delete it
|
|
# shellcheck disable=SC2034
|
|
while read -r FROM TO
|
|
do
|
|
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
|
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
|
|
|
# if they are equal it means the line looks like: "user1 other@domain.tld"
|
|
[[ ${UNAME} != "${DOMAIN}" ]] && echo "${DOMAIN}" >>/tmp/vhost.tmp
|
|
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true)
|
|
else
|
|
_notify 'inf' "Warning '/tmp/docker-mailserver/postfix-virtual.cf' is not provided. No mail alias/forward created."
|
|
fi
|
|
}
|
|
|
|
function _handle_postfix_regexp_config
|
|
{
|
|
if [[ -f /tmp/docker-mailserver/postfix-regexp.cf ]]
|
|
then
|
|
_notify 'inf' "Adding regexp alias file postfix-regexp.cf"
|
|
|
|
cp -f /tmp/docker-mailserver/postfix-regexp.cf /etc/postfix/regexp
|
|
sed -i -E \
|
|
's|virtual_alias_maps(.*)|virtual_alias_maps\1 pcre:/etc/postfix/regexp|g' \
|
|
/etc/postfix/main.cf
|
|
fi
|
|
}
|
|
|
|
function _handle_postfix_aliases_config
|
|
{
|
|
_notify 'inf' 'Configuring root alias'
|
|
|
|
echo "root: ${POSTMASTER_ADDRESS}" > /etc/aliases
|
|
|
|
if [[ -f /tmp/docker-mailserver/postfix-aliases.cf ]]
|
|
then
|
|
cat /tmp/docker-mailserver/postfix-aliases.cf >>/etc/aliases
|
|
else
|
|
_notify 'inf' "'/tmp/docker-mailserver/postfix-aliases.cf' is not provided, it will be auto created."
|
|
: >/tmp/docker-mailserver/postfix-aliases.cf
|
|
fi
|
|
|
|
postalias /etc/aliases
|
|
}
|
|
|
|
# Other scripts should call this method, rather than the ones above:
|
|
function _create_aliases
|
|
{
|
|
_handle_postfix_virtual_config
|
|
_handle_postfix_regexp_config
|
|
_handle_postfix_aliases_config
|
|
}
|