diff --git a/Dockerfile b/Dockerfile index 400e35c1..1397332b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -252,7 +252,6 @@ COPY \ target/bin/* \ target/scripts/*.sh \ target/scripts/startup/*.sh \ - target/scripts/wrapper/*.sh \ /usr/local/bin/ RUN chmod +x /usr/local/bin/* diff --git a/target/scripts/startup/setup.d/postfix.sh b/target/scripts/startup/setup.d/postfix.sh index 0f1c7c58..4d1bbf6f 100644 --- a/target/scripts/startup/setup.d/postfix.sh +++ b/target/scripts/startup/setup.d/postfix.sh @@ -142,6 +142,51 @@ function _setup_SRS postconf "sender_canonical_classes = ${SRS_SENDER_CLASSES}" postconf 'recipient_canonical_maps = tcp:localhost:10002' postconf 'recipient_canonical_classes = envelope_recipient,header_recipient' + + function __generate_secret + { + ( + umask 0077 + dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 >"${1}" + ) + } + + local POSTSRSD_SECRET_FILE POSTSRSD_STATE_DIR POSTSRSD_STATE_SECRET_FILE + + sed -i "s/localdomain/${SRS_DOMAINNAME}/g" /etc/default/postsrsd + + POSTSRSD_SECRET_FILE='/etc/postsrsd.secret' + POSTSRSD_STATE_DIR='/var/mail-state/etc-postsrsd' + POSTSRSD_STATE_SECRET_FILE="${POSTSRSD_STATE_DIR}/postsrsd.secret" + + if [[ -n ${SRS_SECRET} ]] + then + ( + umask 0077 + echo "${SRS_SECRET}" | tr ',' '\n' >"${POSTSRSD_SECRET_FILE}" + ) + else + if [[ ${ONE_DIR} -eq 1 ]] + then + if [[ ! -f ${POSTSRSD_STATE_SECRET_FILE} ]] + then + install -d -m 0775 "${POSTSRSD_STATE_DIR}" + __generate_secret "${POSTSRSD_STATE_SECRET_FILE}" + fi + + install -m 0400 "${POSTSRSD_STATE_SECRET_FILE}" "${POSTSRSD_SECRET_FILE}" + elif [[ ! -f ${POSTSRSD_SECRET_FILE} ]] + then + __generate_secret "${POSTSRSD_SECRET_FILE}" + fi + fi + + if [[ -n ${SRS_EXCLUDE_DOMAINS} ]] + then + sed -i \ + "s/^#\?(SRS_EXCLUDE_DOMAINS=).*$/\1=${SRS_EXCLUDE_DOMAINS}/g" \ + /etc/default/postsrsd + fi } function _setup_postfix_hostname diff --git a/target/scripts/startup/variables-stack.sh b/target/scripts/startup/variables-stack.sh index 66e98a5a..d149a38f 100644 --- a/target/scripts/startup/variables-stack.sh +++ b/target/scripts/startup/variables-stack.sh @@ -107,6 +107,13 @@ function __environment_variables_general_setup VARS[POSTFIX_MESSAGE_SIZE_LIMIT]="${POSTFIX_MESSAGE_SIZE_LIMIT:=10240000}" # ~10 MB VARS[POSTFIX_DAGENT]="${POSTFIX_DAGENT:=}" + _log 'trace' 'Setting SRS specific environment variables' + + VARS[SRS_DOMAINNAME]="${SRS_DOMAINNAME:=${DOMAINNAME}}" + VARS[SRS_EXCLUDE_DOMAINS]="${SRS_EXCLUDE_DOMAINS:=}" + VARS[SRS_SECRET]="${SRS_SECRET:=}" + VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}" + _log 'trace' 'Setting miscellaneous environment variables' VARS[ACCOUNT_PROVISIONER]="${ACCOUNT_PROVISIONER:=FILE}" @@ -123,7 +130,6 @@ function __environment_variables_general_setup VARS[PFLOGSUMM_SENDER]="${PFLOGSUMM_SENDER:=${REPORT_SENDER}}" VARS[PFLOGSUMM_TRIGGER]="${PFLOGSUMM_TRIGGER:=none}" VARS[SMTP_ONLY]="${SMTP_ONLY:=0}" - VARS[SRS_SENDER_CLASSES]="${SRS_SENDER_CLASSES:=envelope_sender}" VARS[SUPERVISOR_LOGLEVEL]="${SUPERVISOR_LOGLEVEL:=warn}" VARS[TZ]="${TZ:=}" VARS[UPDATE_CHECK_INTERVAL]="${UPDATE_CHECK_INTERVAL:=1d}" diff --git a/target/scripts/wrapper/postsrsd-wrapper.sh b/target/scripts/wrapper/postsrsd-wrapper.sh deleted file mode 100755 index 0e249e5f..00000000 --- a/target/scripts/wrapper/postsrsd-wrapper.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# shellcheck source=../helpers/index.sh -source /usr/local/bin/helpers/index.sh - -function _generate_secret { ( umask 0077 ; dd if=/dev/urandom bs=24 count=1 2>/dev/null | base64 -w0 > "${1}" ; ) ; } - -_obtain_hostname_and_domainname - -if [[ -n "${SRS_DOMAINNAME}" ]] -then - NEW_DOMAIN_NAME="${SRS_DOMAINNAME}" -else - NEW_DOMAIN_NAME="${DOMAINNAME}" -fi - -sed -i -e "s/localdomain/${NEW_DOMAIN_NAME}/g" /etc/default/postsrsd - -POSTSRSD_SECRET_FILE='/etc/postsrsd.secret' -POSTSRSD_STATE_DIR='/var/mail-state/etc-postsrsd' -POSTSRSD_STATE_SECRET_FILE="${POSTSRSD_STATE_DIR}/postsrsd.secret" - -if [[ -n ${SRS_SECRET} ]] -then - ( umask 0077 ; echo "${SRS_SECRET}" | tr ',' '\n' > "${POSTSRSD_SECRET_FILE}" ; ) -else - if [[ ${ONE_DIR} -eq 1 ]] - then - if [[ ! -f ${POSTSRSD_STATE_SECRET_FILE} ]] - then - install -d -m 0775 "${POSTSRSD_STATE_DIR}" - _generate_secret "${POSTSRSD_STATE_SECRET_FILE}" - fi - - install -m 0400 "${POSTSRSD_STATE_SECRET_FILE}" "${POSTSRSD_SECRET_FILE}" - elif [[ ! -f ${POSTSRSD_SECRET_FILE} ]] - then - _generate_secret "${POSTSRSD_SECRET_FILE}" - fi -fi - -if [[ -n ${SRS_EXCLUDE_DOMAINS} ]] -then - sed -i -e "s/^#\?SRS_EXCLUDE_DOMAINS=.*$/SRS_EXCLUDE_DOMAINS=${SRS_EXCLUDE_DOMAINS}/g" /etc/default/postsrsd -fi - -/etc/init.d/postsrsd start diff --git a/target/supervisor/conf.d/supervisor-app.conf b/target/supervisor/conf.d/supervisor-app.conf index aed64b15..4b4e9a6a 100644 --- a/target/supervisor/conf.d/supervisor-app.conf +++ b/target/supervisor/conf.d/supervisor-app.conf @@ -148,7 +148,7 @@ autostart=false autorestart=true stdout_logfile=/var/log/supervisor/%(program_name)s.log stderr_logfile=/var/log/supervisor/%(program_name)s.log -command=/usr/local/bin/postsrsd-wrapper.sh +command=/etc/init.d/postsrsd start [program:update-check] startsecs=0