diff --git a/Makefile b/Makefile index f01a1c63..6e63ec81 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,7 @@ run: sleep 15 docker run -d --name ldap_for_mail \ -e LDAP_DOMAIN="localhost.localdomain" \ - -h mail.my-domain.com -t ldap + -h ldap.my-domain.com -t ldap sleep 15 docker run -d --name mail_with_ldap \ -v "`pwd`/test/config":/tmp/docker-mailserver \ diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 43556b5b..f0373eb9 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -22,6 +22,19 @@ DEFAULT_VARS["DMS_DEBUG"]="${DMS_DEBUG:="0"}" # << DEFAULT VARS ########################################################################## +########################################################################## +# >> GLOBAL VARS +# +# add your global script variables here. +# +# Example: KEY="VALUE" +########################################################################## +HOSTNAME="$(hostname -f)" +DOMAINNAME="$(hostname -d)" +########################################################################## +# << GLOBAL VARS +########################################################################## + ########################################################################## # >> REGISTER FUNCTIONS @@ -300,11 +313,11 @@ function check() { function _check_hostname() { notify "task" "Check that hostname/domainname is provided (no default docker hostname) [$FUNCNAME]" - if ( ! echo $(hostname) | grep -E '^(\S+[.]\S+)$' > /dev/null ); then + if ( ! echo $HOSTNAME | grep -E '^(\S+[.]\S+)$' > /dev/null ); then notify 'err' "Setting hostname/domainname is required" return 1 else - notify 'inf' "Hostname has been set to $(hostname)" + notify 'inf' "Hostname has been set to $HOSTNAME" return 0 fi } @@ -344,7 +357,7 @@ function _setup_mailname() { notify 'task' 'Setting up Mailname' notify 'inf' "Creating /etc/mailname" - echo $(hostname -d) > /etc/mailname + echo $DOMAINNAME > /etc/mailname } function _setup_dovecot() { @@ -429,7 +442,7 @@ function _setup_ldap() { /etc/postfix/ldap-${i}.cf done - notify 'inf' "Configuring dovecot LDAP authentification" + notify 'inf' "Configuring dovecot LDAP authentification" sed -i -e 's|^hosts.*|hosts = '${LDAP_SERVER_HOST:="mail.domain.com"}'|g' \ -e 's|^base.*|base = '${LDAP_SEARCH_BASE:="ou=people,dc=domain,dc=com"}'|g' \ -e 's|^dn\s*=.*|dn = '${LDAP_BIND_DN:="cn=admin,dc=domain,dc=com"}'|g' \ @@ -437,7 +450,7 @@ function _setup_ldap() { /etc/dovecot/dovecot-ldap.conf.ext # Add domainname to vhost. - echo $(hostname -d) >> /tmp/vhost.tmp + echo $DOMAINNAME >> /tmp/vhost.tmp notify 'inf' "Enabling dovecot LDAP authentification" sed -i -e '/\!include auth-ldap\.conf\.ext/s/^#//' /etc/dovecot/conf.d/10-auth.conf @@ -571,24 +584,24 @@ function _setup_ssl() { case $SSL_TYPE in "letsencrypt" ) # letsencrypt folders and files mounted in /etc/letsencrypt - if [ -e "/etc/letsencrypt/live/$(hostname)/cert.pem" ] \ - && [ -e "/etc/letsencrypt/live/$(hostname)/fullchain.pem" ]; then + if [ -e "/etc/letsencrypt/live/$HOSTNAME/cert.pem" ] \ + && [ -e "/etc/letsencrypt/live/$HOSTNAME/fullchain.pem" ]; then KEY="" - if [ -e "/etc/letsencrypt/live/$(hostname)/privkey.pem" ]; then + if [ -e "/etc/letsencrypt/live/$HOSTNAME/privkey.pem" ]; then KEY="privkey" - elif [ -e "/etc/letsencrypt/live/$(hostname)/key.pem" ]; then + elif [ -e "/etc/letsencrypt/live/$HOSTNAME/key.pem" ]; then KEY="key" fi if [ -n "$KEY" ]; then - notify 'inf' "Adding $(hostname) SSL certificate" + notify 'inf' "Adding $HOSTNAME SSL certificate" # Postfix configuration - sed -i -r 's~smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem~smtpd_tls_cert_file=/etc/letsencrypt/live/'$(hostname)'/fullchain.pem~g' /etc/postfix/main.cf - sed -i -r 's~smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key~smtpd_tls_key_file=/etc/letsencrypt/live/'$(hostname)'/'"$KEY"'\.pem~g' /etc/postfix/main.cf + sed -i -r 's~smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem~smtpd_tls_cert_file=/etc/letsencrypt/live/'$HOSTNAME'/fullchain.pem~g' /etc/postfix/main.cf + sed -i -r 's~smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key~smtpd_tls_key_file=/etc/letsencrypt/live/'$HOSTNAME'/'"$KEY"'\.pem~g' /etc/postfix/main.cf # Dovecot configuration - sed -i -e 's~ssl_cert =