support comments in .cf files

This commit is contained in:
youtous 2020-05-06 19:26:47 +02:00
parent b6bc3bc073
commit d0f7257333
No known key found for this signature in database
GPG Key ID: 592173AE8CD254A5
9 changed files with 27 additions and 19 deletions

View File

@ -23,6 +23,8 @@ backup:
generate-accounts:
docker run --rm -e MAIL_USER=user1@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' > test/config/postfix-accounts.cf
docker run --rm -e MAIL_USER=user2@otherdomain.tld -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
echo "# this is a test comment, please don't delete me :'(" >> test/config/postfix-accounts.cf
echo " # this is also a test comment, :O" >> test/config/postfix-accounts.cf
run:
# Run containers

View File

@ -7,23 +7,23 @@ keysize=${1:-2048}
# Getting domains from mail accounts
if [ -f /tmp/docker-mailserver/postfix-accounts.cf ]; then
while IFS=$'|' read login pass
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-accounts.cf || true) | while IFS=$'|' read login pass
do
domain=$(echo ${login} | cut -d @ -f2)
echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-accounts.cf
done
fi
# Getting domains from mail aliases
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
while read from to
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true) | while read from to
do
# Setting variables for better readability
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"
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf
done
fi
# Keeping unique entries

View File

@ -10,4 +10,4 @@ errex() {
[ -f $DATABASE ] || errex "No postfix-virtual.cf file"
[ -s $DATABASE ] || errex "Empty postfix-virtual.cf - no aliases have been added"
cat $DATABASE
(grep -v "^\s*$\|^\s*\#" $DATABASE || true)

View File

@ -13,6 +13,6 @@ errex() {
# Lock database even though we are only reading
(
flock -e 200
awk -F '|' '{ print $1; }' $DATABASE
(grep -v "^\s*$\|^\s*\#" "$DATABASE" || true) | awk -F '|' '{ print $1; }'
) 200<$DATABASE

View File

@ -91,11 +91,11 @@ if [[ $chksum == *"FAIL"* ]]; then
fi
# add domain-specific auth from config file
if [ -f /tmp/docker-mailserver/postfix-sasl-password.cf ]; then
while read line; do
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-sasl-password.cf || true) | while read line; do
if ! echo "$line" | grep -q -e "\s*#"; then
echo "$line" >> /etc/postfix/sasl_passwd
fi
done < /tmp/docker-mailserver/postfix-sasl-password.cf
done
fi
# add default relay
if [ ! -z "$RELAY_USER" ] && [ ! -z "$RELAY_PASSWORD" ]; then
@ -103,11 +103,11 @@ if [[ $chksum == *"FAIL"* ]]; then
fi
# add relay maps from file
if [ -f /tmp/docker-mailserver/postfix-relaymap.cf ]; then
while read line; do
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-relaymap.cf || true) | while read line; do
if ! echo "$line" | grep -q -e "\s*#"; then
echo "$line" >> /etc/postfix/relayhost_map
fi
done < /tmp/docker-mailserver/postfix-relaymap.cf
done
fi
fi
@ -165,14 +165,14 @@ if [[ $chksum == *"FAIL"* ]]; then
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
# Copying virtual file
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
while read from to
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true) | while read from to
do
# Setting variables for better readability
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"
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf
done
fi
if [ -f /tmp/docker-mailserver/postfix-regexp.cf ]; then
# Copying regexp alias file
@ -183,23 +183,23 @@ if [[ $chksum == *"FAIL"* ]]; then
}' /etc/postfix/main.cf
fi
fi
# Set vhost
# Set vhost
if [ -f /tmp/vhost.tmp ]; then
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
fi
# Set right new if needed
if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then
chown -R 5000:5000 /var/mail
fi
# Restart of the postfix
supervisorctl restart postfix
# Prevent restart of dovecot when smtp_only=1
if [ ! $SMTP_ONLY = 1 ]; then
supervisorctl restart dovecot
fi
fi
echo "${log_date} Update checksum"
sha512sum ${cf_files[@]/#/--tag } >$CHKSUM_FILE

View File

@ -940,14 +940,14 @@ function _setup_postfix_aliases() {
[[ $(grep ",$" /tmp/docker-mailserver/postfix-virtual.cf) ]] && sed -i -e "s/, /,/g" -e "s/,$//g" /tmp/docker-mailserver/postfix-virtual.cf
# Copying virtual file
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual
while read from to
(grep -v "^\s*$\|^\s*\#" /tmp/docker-mailserver/postfix-virtual.cf || true) | while read from to
do
# Setting variables for better readability
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"
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf
done
else
notify 'inf' "Warning 'config/postfix-virtual.cf' is not provided. No mail alias/forward created."
fi

View File

@ -1 +1,3 @@
submission/inet/smtpd_sasl_security_options=noanonymous
# this is a test comment, please don't delete me :'(
# this is also a test comment, :O

View File

@ -1,4 +1,6 @@
/^test[0-9][0-9]*@localhost.localdomain/ user1@localhost.localdomain
# this is a test comment, please don't delete me :'(
# this is also a test comment, :O
/^bounce.*@.*/ external1@otherdomain.tld
/^postmaster@/ user1@localhost.localdomain

View File

@ -1,3 +1,5 @@
alias1@localhost.localdomain user1@localhost.localdomain
# this is a test comment, please don't delete me :'(
# this is also a test comment, :O
alias2@localhost.localdomain external1@otherdomain.tld
@localdomain2.com user1@localhost.localdomain