From e70949f6ecc25220f057579bb636d117c61145c4 Mon Sep 17 00:00:00 2001 From: Christoph Date: Tue, 7 May 2024 13:41:32 +0200 Subject: [PATCH] Add suport for sender domain rewriting. --- install_postfix_base.sh | 54 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/install_postfix_base.sh b/install_postfix_base.sh index 1334e2b..2db2531 100755 --- a/install_postfix_base.sh +++ b/install_postfix_base.sh @@ -84,6 +84,14 @@ blank_line() { fi } +trim() { + local var="$*" + var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters + var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters + echo -n "$var" +} + + detect_os_1 () { if $(which lsb_release > /dev/null 2>&1) ; then @@ -122,6 +130,7 @@ detect_os_1 () { DEFAULT_ADMIN_EMAIL="argus@oopen.de" DEFAULT_RELAY_HOST="b.mx.oopen.de" DEFAULT_SASL_AUTH=false +DEFAULT_REWRITE_SENDER_DOMAIN=None # - Is this a systemd system? @@ -338,6 +347,9 @@ if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then [[ -z "$_RELAY_HOST" ]] && _RELAY_HOST="$DEFAULT_RELAY_HOST" fi +if [[ -z ${_REWRITE_SENDER_DOMAIN} ]] ; then + _REWRITE_SENDER_DOMAIN="${DEFAULT_REWRITE_SENDER_DOMAIN}" +fi if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then @@ -403,12 +415,37 @@ if [[ "$SASL_AUTH" = "yes" ]] || $SASL_AUTH ; then done fi - - else SASL_AUTH=false fi +REWRITE_SENDER_DOMAIN= +echo "" +echo "" +echo -e "\033[33m** \033[32m-- \033[33m**\033[m" +echo "" +echo "Change the sender domain" +echo "" +echo -e "\t'\033[33mNone\033[m' if no change is desired" +echo "" +if [[ -n "${_REWRITE_SENDER_DOMAIN}" ]] ; then + echononl "New sender domain [${_REWRITE_SENDER_DOMAIN}]: " + read REWRITE_SENDER_DOMAIN + if [[ "X${REWRITE_SENDER_DOMAIN}" = "X" ]]; then + REWRITE_SENDER_DOMAIN="${_REWRITE_SENDER_DOMAIN}" + fi +else + while [[ "X${IPV6}" = "X" ]]; do + echononl "New sender domain: " + read REWRITE_SENDER_DOMAIN + if [[ "X${REWRITE_SENDER_DOMAIN}" = "X" ]]; then + REWRITE_SENDER_DOMAIN="None" + fi + done +fi + +echo "" +echo -e "\033[33m** \033[32m-- \033[33m**\033[m" echo "" echo "" @@ -419,6 +456,12 @@ echo -e "\tIPv4 address.............: $IPV4" echo -e "\tIPv6 address.............: $IPV6" echo -e "\tAdmin e-mail.............: $ADMIN_EMAIL" echo "" +if [[ "$(trim ${REWRITE_SENDER_DOMAIN,,})" = 'none' ]] ; then + echo -e "\trewrite sender domain....: \033[33mNone\033[m" +else + echo -e "\trewrite sender domain....: $REWRITE_SENDER_DOMAIN" +fi +echo "" echo -e "\tRelay using sasl auth....: $SASL_AUTH" if $SASL_AUTH ; then echo -e "\t sasl user.............: $SASL_USER" @@ -455,6 +498,7 @@ _SASL_AUTH=$SASL_AUTH _SASL_USER=$SASL_USER _SASL_PASS=$SASL_PASS _RELAY_HOST=$RELAY_HOST +_REWRITE_SENDER_DOMAIN=$REWRITE_SENDER_DOMAIN EOF if [[ $? -eq 0 ]] ; then echo_ok @@ -1231,9 +1275,11 @@ else fi echononl " Create file \"generic\"" -if [[ ! -f /etc/postfix/generic ]]; then +if [[ "$(trim ${REWRITE_SENDER_DOMAIN,,})" = 'none' ]] ; then + touch /etc/postfix/generic +else cat < /etc/postfix/generic -@localhost @$(hostname -f) +@$(cat cat /etc/mailname) $(hostname)@$(trim ${REWRITE_SENDER_DOMAIN,,}) EOF fi postmap btree:/etc/postfix/generic