pmb-pf/run.sh

39 lines
1.4 KiB
Bash
Raw Normal View History

2015-04-19 22:30:41 +00:00
#!/bin/bash
[ "${DEBUG}" == "yes" ] && set -x
2015-04-19 22:30:41 +00:00
[ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER 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
2018-03-06 06:18:30 +00:00
[ -z "${SERVER_HOSTNAME}" ] && echo "SERVER_HOSTNAME is not set" && exit 1
2015-04-19 22:30:41 +00:00
SMTP_PORT="${SMTP_PORT-587}"
2015-05-23 04:45:58 +00:00
#Get the domain from the server host name
DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^.//'`
2015-05-23 04:45:58 +00:00
# Set needed config options
postconf -e "myhostname = ${SERVER_HOSTNAME}"
postconf -e "mydomain = ${DOMAIN}"
postconf -e "mydestination = $myhostname"
postconf -e "myorigin = \$mydomain"
postconf -e "relayhost = [${SMTP_SERVER}]:${SMTP_PORT}"
postconf -e "smtp_use_tls = yes"
postconf -e "smtp_sasl_auth_enable = yes"
postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd"
postconf -e "smtp_sasl_security_options = noanonymous"
postconf -e "smtp_sasl_tls_security_options = noanonymous"
# Create sasl_passwd file with auth credentials
if [ ! -f /etc/postfix/sasl_passwd ]; then
grep -q "${SMTP_SERVER}" /etc/postfix/sasl_passwd > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo "Adding SASL authentication configuration"
echo "[${SMTP_SERVER}]:${SMTP_PORT} ${SMTP_USERNAME}:${SMTP_PASSWORD}" >> /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
fi
fi
2015-04-19 22:30:41 +00:00
#Start services
supervisord