Replace add_config_value with native postconf

This project saved me a lot of time. With the basic service running in docker I was able to add TLS and authentication for external clients. I am hoping I can help in some small way.
This commit is contained in:
turboaaa 2019-01-08 18:12:45 -05:00 committed by GitHub
parent d5fb194c00
commit 22f46669db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

32
run.sh
View file

@ -2,19 +2,6 @@
[ "${DEBUG}" == "yes" ] && set -x [ "${DEBUG}" == "yes" ] && set -x
function add_config_value() {
local key=${1}
local value=${2}
local config_file=${3:-/etc/postfix/main.cf}
[ "${key}" == "" ] && echo "ERROR: No key set !!" && exit 1
[ "${value}" == "" ] && echo "ERROR: No value set !!" && exit 1
echo "Setting configuration option ${key} with value: ${value}"
sed -i -e "/^#\?\(\s*${key}\s*=\s*\).*/{s//\1${value}/;:a;n;:ba;q}" \
-e "\$a${key}=${value}" \
${config_file}
}
[ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1 [ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1
[ -z "${SMTP_USERNAME}" ] && echo "SMTP_USERNAME is not set" && exit 1 [ -z "${SMTP_USERNAME}" ] && echo "SMTP_USERNAME is not set" && exit 1
[ -z "${SMTP_PASSWORD}" ] && echo "SMTP_PASSWORD is not set" && exit 1 [ -z "${SMTP_PASSWORD}" ] && echo "SMTP_PASSWORD is not set" && exit 1
@ -26,15 +13,16 @@ SMTP_PORT="${SMTP_PORT-587}"
DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^.//'` DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^.//'`
# Set needed config options # Set needed config options
add_config_value "myhostname" ${SERVER_HOSTNAME} postconf -e "myhostname = ${SERVER_HOSTNAME}"
add_config_value "mydomain" ${DOMAIN} postconf -e "mydomain = ${DOMAIN}"
add_config_value "mydestination" '$myhostname' postconf -e "mydestination = $myhostname"
add_config_value "myorigin" '$mydomain' postconf -e "myorigin = \$mydomain"
add_config_value "relayhost" "[${SMTP_SERVER}]:${SMTP_PORT}" postconf -e "relayhost = [${SMTP_SERVER}]:${SMTP_PORT}"
add_config_value "smtp_use_tls" "yes" postconf -e "smtp_use_tls = yes"
add_config_value "smtp_sasl_auth_enable" "yes" postconf -e "smtp_sasl_auth_enable = yes"
add_config_value "smtp_sasl_password_maps" "hash:\/etc\/postfix\/sasl_passwd" postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd"
add_config_value "smtp_sasl_security_options" "noanonymous" postconf -e "smtp_sasl_security_options = noanonymous"
postconf -e "smtp_sasl_tls_security_options = noanonymous"
# Create sasl_passwd file with auth credentials # Create sasl_passwd file with auth credentials
if [ ! -f /etc/postfix/sasl_passwd ]; then if [ ! -f /etc/postfix/sasl_passwd ]; then