2018-04-02 08:45:58 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-01-16 09:16:05 +00:00
|
|
|
# shellcheck source=../scripts/helper-functions.sh
|
|
|
|
. /usr/local/bin/helper-functions.sh
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-relaymap.cf}
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DOMAIN="${1}"
|
|
|
|
HOST="${2}"
|
|
|
|
PORT="${3}"
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
function usage { echo "Usage: addrelayhost <domain> <host> [<port>]" ; }
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -z ${DOMAIN} ]] && { usage ; errex "no domain specified" ; }
|
|
|
|
[[ -z ${HOST} ]] && { usage ; errex "no relay host specified" ; }
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -z ${PORT} ]] && PORT=25
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if grep -qi "^@${DOMAIN}" "${DATABASE}" 2>/dev/null
|
|
|
|
then
|
|
|
|
# TODO check if fixed
|
|
|
|
# sed -i "s ^@${DOMAIN}.* @${DOMAIN}\t\t[${HOST}]:${PORT}" "${DATABASE}"
|
|
|
|
sed -i "s ^@""${DOMAIN}"".* ""@""${DOMAIN}""\t\t[""${HOST}""]:""${PORT}"" " "${DATABASE}"
|
2018-04-02 08:45:58 +00:00
|
|
|
else
|
2020-10-21 16:16:32 +00:00
|
|
|
echo -e "@${DOMAIN}\t\t[${HOST}]:${PORT}" >> "${DATABASE}"
|
2018-04-02 08:45:58 +00:00
|
|
|
fi
|