From dbf65789f2bd35d725217048d8aa9b8cc49b6090 Mon Sep 17 00:00:00 2001 From: alinmear Date: Mon, 10 Jul 2017 00:11:00 +0200 Subject: [PATCH] Integrate docker-configomat for configuration parts of start-mailserver.sh #648 (#650) * Add submodule docker-configomat * Add configomat.sh to Dockerfile * Replaced override_config with configomat.sh --- .gitmodules | 3 +++ Dockerfile | 2 +- target/docker-configomat | 1 + target/start-mailserver.sh | 51 +++----------------------------------- 4 files changed, 9 insertions(+), 48 deletions(-) create mode 160000 target/docker-configomat diff --git a/.gitmodules b/.gitmodules index 0ed2caff..bc127a9e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "test/test_helper/bats-assert"] path = test/test_helper/bats-assert url = https://github.com/ztombol/bats-assert +[submodule "target/docker-configomat"] + path = target/docker-configomat + url = https://github.com/alinmear/docker-configomat diff --git a/Dockerfile b/Dockerfile index 5eb466e1..677394a1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -144,7 +144,7 @@ RUN curl -s https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > /et COPY ./target/bin /usr/local/bin # Start-mailserver script -COPY ./target/start-mailserver.sh /usr/local/bin/ +COPY ./target/start-mailserver.sh ./target/docker-configomat/configomat.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/* EXPOSE 25 587 143 993 110 995 4190 diff --git a/target/docker-configomat b/target/docker-configomat new file mode 160000 index 00000000..e3e84ded --- /dev/null +++ b/target/docker-configomat @@ -0,0 +1 @@ +Subproject commit e3e84ded29d88b2945c0782dbb43237c561a54a9 diff --git a/target/start-mailserver.sh b/target/start-mailserver.sh index 1f5438d0..e2c4d5e3 100644 --- a/target/start-mailserver.sh +++ b/target/start-mailserver.sh @@ -316,50 +316,6 @@ function display_startup_daemon() { return $res } -function override_config() { - notify "task" "Starting do do overrides" - - declare -A config_overrides - - _env_variable_prefix=$1 - [ -z ${_env_variable_prefix} ] && return 1 - - - IFS=" " read -r -a _config_files <<< $2 - - # dispatch env variables - for env_variable in $(printenv | grep $_env_variable_prefix);do - # get key - # IFS not working because values like ldap_query_filter or search base consists of several '=' - # IFS="=" read -r -a __values <<< $env_variable - # key="${__values[0]}" - # value="${__values[1]}" - key=$(echo $env_variable | cut -d "=" -f1) - key=${key#"${_env_variable_prefix}"} - # make key lowercase - key=${key,,} - # get value - value=$(echo $env_variable | cut -d "=" -f2-) - - config_overrides[$key]=$value - done - - for f in "${_config_files[@]}" - do - if [ ! -f "${f}" ];then - echo "Can not find ${f}. Skipping override" - else - for key in ${!config_overrides[@]} - do - [ -z $key ] && echo -e "\t no key provided" && return 1 - - sed -i -e "s|^${key}[[:space:]]\+.*|${key} = ${config_overrides[$key]//&/\\&}|g" \ - ${f} - done - fi - done -} - # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # ! CARE --> DON'T CHANGE, except you know exactly what you are doing # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -579,7 +535,7 @@ function _setup_ldap() { [[ $f =~ ldap-user ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_USER}" [[ $f =~ ldap-group ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_GROUP}" [[ $f =~ ldap-aliases ]] && export LDAP_QUERY_FILTER="${LDAP_QUERY_FILTER_ALIAS}" - override_config "LDAP_" "${f}" + configomat.sh "LDAP_" "${f}" done notify 'inf' "Configuring dovecot LDAP" @@ -598,7 +554,7 @@ function _setup_ldap() { export $var=${_dovecot_ldap_mapping[$var]} done - override_config "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext" + configomat.sh "DOVECOT_" "/etc/dovecot/dovecot-ldap.conf.ext" # Add domainname to vhost. echo $DOMAINNAME >> /tmp/vhost.tmp @@ -763,7 +719,8 @@ function _setup_ssl() { case $SSL_TYPE in "letsencrypt" ) # letsencrypt folders and files mounted in /etc/letsencrypt - if [ -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 KEY="privkey"