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: 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=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 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:
# Run containers # Run containers

View file

@ -7,23 +7,23 @@ keysize=${1:-2048}
# Getting domains from mail accounts # Getting domains from mail accounts
if [ -f /tmp/docker-mailserver/postfix-accounts.cf ]; then 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 do
domain=$(echo ${login} | cut -d @ -f2) domain=$(echo ${login} | cut -d @ -f2)
echo ${domain} >> /tmp/vhost.tmp echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-accounts.cf done
fi fi
# Getting domains from mail aliases # Getting domains from mail aliases
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then 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 do
# Setting variables for better readability # Setting variables for better readability
uname=$(echo ${from} | cut -d @ -f1) uname=$(echo ${from} | cut -d @ -f1)
domain=$(echo ${from} | cut -d @ -f2) domain=$(echo ${from} | cut -d @ -f2)
# if they are equal it means the line looks like: "user1 other@domain.tld" # if they are equal it means the line looks like: "user1 other@domain.tld"
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf done
fi fi
# Keeping unique entries # Keeping unique entries

View file

@ -10,4 +10,4 @@ errex() {
[ -f $DATABASE ] || errex "No postfix-virtual.cf file" [ -f $DATABASE ] || errex "No postfix-virtual.cf file"
[ -s $DATABASE ] || errex "Empty postfix-virtual.cf - no aliases have been added" [ -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 # Lock database even though we are only reading
( (
flock -e 200 flock -e 200
awk -F '|' '{ print $1; }' $DATABASE (grep -v "^\s*$\|^\s*\#" "$DATABASE" || true) | awk -F '|' '{ print $1; }'
) 200<$DATABASE ) 200<$DATABASE

View file

@ -91,11 +91,11 @@ if [[ $chksum == *"FAIL"* ]]; then
fi fi
# add domain-specific auth from config file # add domain-specific auth from config file
if [ -f /tmp/docker-mailserver/postfix-sasl-password.cf ]; then 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 if ! echo "$line" | grep -q -e "\s*#"; then
echo "$line" >> /etc/postfix/sasl_passwd echo "$line" >> /etc/postfix/sasl_passwd
fi fi
done < /tmp/docker-mailserver/postfix-sasl-password.cf done
fi fi
# add default relay # add default relay
if [ ! -z "$RELAY_USER" ] && [ ! -z "$RELAY_PASSWORD" ]; then if [ ! -z "$RELAY_USER" ] && [ ! -z "$RELAY_PASSWORD" ]; then
@ -103,11 +103,11 @@ if [[ $chksum == *"FAIL"* ]]; then
fi fi
# add relay maps from file # add relay maps from file
if [ -f /tmp/docker-mailserver/postfix-relaymap.cf ]; then 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 if ! echo "$line" | grep -q -e "\s*#"; then
echo "$line" >> /etc/postfix/relayhost_map echo "$line" >> /etc/postfix/relayhost_map
fi fi
done < /tmp/docker-mailserver/postfix-relaymap.cf done
fi fi
fi fi
@ -165,14 +165,14 @@ if [[ $chksum == *"FAIL"* ]]; then
if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
# Copying virtual file # Copying virtual file
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual 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 do
# Setting variables for better readability # Setting variables for better readability
uname=$(echo ${from} | cut -d @ -f1) uname=$(echo ${from} | cut -d @ -f1)
domain=$(echo ${from} | cut -d @ -f2) domain=$(echo ${from} | cut -d @ -f2)
# if they are equal it means the line looks like: "user1 other@domain.tld" # if they are equal it means the line looks like: "user1 other@domain.tld"
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf done
fi fi
if [ -f /tmp/docker-mailserver/postfix-regexp.cf ]; then if [ -f /tmp/docker-mailserver/postfix-regexp.cf ]; then
# Copying regexp alias file # Copying regexp alias file
@ -183,23 +183,23 @@ if [[ $chksum == *"FAIL"* ]]; then
}' /etc/postfix/main.cf }' /etc/postfix/main.cf
fi fi
fi fi
# Set vhost # Set vhost
if [ -f /tmp/vhost.tmp ]; then if [ -f /tmp/vhost.tmp ]; then
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
fi fi
# Set right new if needed # Set right new if needed
if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then
chown -R 5000:5000 /var/mail chown -R 5000:5000 /var/mail
fi fi
# Restart of the postfix # Restart of the postfix
supervisorctl restart postfix supervisorctl restart postfix
# Prevent restart of dovecot when smtp_only=1 # Prevent restart of dovecot when smtp_only=1
if [ ! $SMTP_ONLY = 1 ]; then if [ ! $SMTP_ONLY = 1 ]; then
supervisorctl restart dovecot supervisorctl restart dovecot
fi fi
echo "${log_date} Update checksum" echo "${log_date} Update checksum"
sha512sum ${cf_files[@]/#/--tag } >$CHKSUM_FILE 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 [[ $(grep ",$" /tmp/docker-mailserver/postfix-virtual.cf) ]] && sed -i -e "s/, /,/g" -e "s/,$//g" /tmp/docker-mailserver/postfix-virtual.cf
# Copying virtual file # Copying virtual file
cp -f /tmp/docker-mailserver/postfix-virtual.cf /etc/postfix/virtual 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 do
# Setting variables for better readability # Setting variables for better readability
uname=$(echo ${from} | cut -d @ -f1) uname=$(echo ${from} | cut -d @ -f1)
domain=$(echo ${from} | cut -d @ -f2) domain=$(echo ${from} | cut -d @ -f2)
# if they are equal it means the line looks like: "user1 other@domain.tld" # if they are equal it means the line looks like: "user1 other@domain.tld"
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf done
else else
notify 'inf' "Warning 'config/postfix-virtual.cf' is not provided. No mail alias/forward created." notify 'inf' "Warning 'config/postfix-virtual.cf' is not provided. No mail alias/forward created."
fi fi

View file

@ -1 +1,3 @@
submission/inet/smtpd_sasl_security_options=noanonymous 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 /^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 /^bounce.*@.*/ external1@otherdomain.tld
/^postmaster@/ user1@localhost.localdomain /^postmaster@/ user1@localhost.localdomain

View file

@ -1,3 +1,5 @@
alias1@localhost.localdomain user1@localhost.localdomain 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 alias2@localhost.localdomain external1@otherdomain.tld
@localdomain2.com user1@localhost.localdomain @localdomain2.com user1@localhost.localdomain