mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-04 01:55:29 +02:00
chore(housekeeping): Normalize how config files filter out unwanted lines (#2619)
* chore(`aliases.sh`): Filepath to local var `DATABASE_VIRTUAL` * chore(`accounts.sh`): Filepath to local var `DATABASE_ACCOUNTS` * chore(`accounts.sh`): Filepath to local var `DATABASE_VIRTUAL` * chore(`accounts.sh`): Filepath to local var `DATABASE_DOVECOT_MASTERS` * chore(`bin/open-dkim`): Filepaths to local vars (accounts,virtual,vhost) * chore(`relay.sh`): Filepath to local var `DATABASE_SASL_PASSWD` * chore: Rename method Prior PR feedback suggested a better helper method name. * chore: Normalize filtering config lines as input for iterating * chore: Remove `_is_comment` helper method No longer serving a purpose with more appropriate filter method for pre-processing the entire config file.
This commit is contained in:
parent
fa8bfdc22a
commit
54904aa02c
9 changed files with 51 additions and 60 deletions
|
@ -8,5 +8,5 @@ DATABASE='/tmp/docker-mailserver/postfix-virtual.cf'
|
|||
[[ -f ${DATABASE} ]] || _exit_with_error "No 'postfix-virtual.cf' file"
|
||||
[[ -s ${DATABASE} ]] || _exit_with_error "Empty 'postfix-virtual.cf' - no aliases have been added"
|
||||
|
||||
grep -v "^\s*$\|^\s*\#" "${DATABASE}"
|
||||
_get_valid_lines_from_file "${DATABASE}"
|
||||
exit 0
|
||||
|
|
|
@ -16,6 +16,6 @@ while read -r LINE
|
|||
do
|
||||
USER=$(echo "${LINE}" | cut -d'|' -f1)
|
||||
echo "* ${USER}"
|
||||
done < "${DATABASE}"
|
||||
done < <(_get_valid_lines_from_file "${DATABASE}")
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -47,7 +47,7 @@ do
|
|||
else
|
||||
echo
|
||||
fi
|
||||
done < <(_filter_to_valid_lines "${DATABASE}")
|
||||
done < <(_get_valid_lines_from_file "${DATABASE}")
|
||||
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -98,23 +98,26 @@ do
|
|||
esac
|
||||
done
|
||||
|
||||
touch /tmp/vhost.dkim.tmp
|
||||
|
||||
DATABASE_ACCOUNTS='/tmp/docker-mailserver/postfix-accounts.cf'
|
||||
DATABASE_VIRTUAL='/tmp/docker-mailserver/postfix-virtual.cf'
|
||||
DATABASE_VHOST='/tmp/vhost'
|
||||
TMP_VHOST='/tmp/vhost.dkim.tmp'
|
||||
touch "${TMP_VHOST}"
|
||||
if [[ -z ${DOMAINS} ]]
|
||||
then
|
||||
# getting domains FROM mail accounts
|
||||
if [[ -f /tmp/docker-mailserver/postfix-accounts.cf ]]
|
||||
if [[ -f ${DATABASE_ACCOUNTS} ]]
|
||||
then
|
||||
# shellcheck disable=SC2034
|
||||
while IFS=$'|' read -r LOGIN PASS
|
||||
do
|
||||
DOMAIN=$(echo "${LOGIN}" | cut -d @ -f2)
|
||||
echo "${DOMAIN}" >>/tmp/vhost.dkim.tmp
|
||||
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf || true)
|
||||
echo "${DOMAIN}" >>"${TMP_VHOST}"
|
||||
done < <(_get_valid_lines_from_file "${DATABASE_ACCOUNTS}")
|
||||
fi
|
||||
|
||||
# getting domains FROM mail aliases
|
||||
if [[ -f /tmp/docker-mailserver/postfix-virtual.cf ]]
|
||||
if [[ -f ${DATABASE_VIRTUAL} ]]
|
||||
then
|
||||
# shellcheck disable=SC2034
|
||||
while read -r FROM TO
|
||||
|
@ -122,17 +125,17 @@ then
|
|||
UNAME=$(echo "${FROM}" | cut -d @ -f1)
|
||||
DOMAIN=$(echo "${FROM}" | cut -d @ -f2)
|
||||
|
||||
[[ ${UNAME} != "${DOMAIN}" ]] && echo "${DOMAIN}" >>/tmp/vhost.dkim.tmp
|
||||
done < <(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true)
|
||||
[[ ${UNAME} != "${DOMAIN}" ]] && echo "${DOMAIN}" >>"${TMP_VHOST}"
|
||||
done < <(_get_valid_lines_from_file "${DATABASE_VIRTUAL}")
|
||||
fi
|
||||
else
|
||||
tr ',' '\n' <<< "${DOMAINS}" >/tmp/vhost.dkim.tmp
|
||||
tr ',' '\n' <<< "${DOMAINS}" >"${TMP_VHOST}"
|
||||
fi
|
||||
|
||||
sort < /tmp/vhost.dkim.tmp | uniq >/tmp/vhost
|
||||
rm /tmp/vhost.dkim.tmp
|
||||
sort < "${TMP_VHOST}" | uniq >"${DATABASE_VHOST}"
|
||||
rm "${TMP_VHOST}"
|
||||
|
||||
if [[ ! -s /tmp/vhost ]]
|
||||
if [[ ! -s ${DATABASE_VHOST} ]]
|
||||
then
|
||||
_log 'warn' 'No entries found, no keys to make'
|
||||
exit 0
|
||||
|
@ -179,7 +182,7 @@ do
|
|||
echo "${SIGNINGTABLEENTRY}" >>/tmp/docker-mailserver/opendkim/SigningTable
|
||||
fi
|
||||
fi
|
||||
done < <(grep -vE '^(\s*$|#)' /tmp/vhost)
|
||||
done < <(_get_valid_lines_from_file "${DATABASE_VHOST}")
|
||||
|
||||
# create TrustedHosts if missing
|
||||
if [[ -d /tmp/docker-mailserver/opendkim ]] && [[ ! -f /tmp/docker-mailserver/opendkim/TrustedHosts ]]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue