diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index bbe739a1..7898a9c4 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() { @@ -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 =