mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
34 lines
589 B
Plaintext
34 lines
589 B
Plaintext
|
#! /bin/bash
|
||
|
|
||
|
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-relaymap.cf}
|
||
|
|
||
|
DOMAIN="$1"
|
||
|
HOST="$2"
|
||
|
PORT="$3"
|
||
|
|
||
|
usage() {
|
||
|
echo "Usage: addrelayhost <domain> <host> [<port>]"
|
||
|
}
|
||
|
|
||
|
errex() {
|
||
|
echo "$@" 1>&2
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
escape() {
|
||
|
echo "${1//./\\.}"
|
||
|
}
|
||
|
|
||
|
[ -z "$DOMAIN" ] && { usage; errex "no domain specified"; }
|
||
|
[ -z "$HOST" ] && { usage; errex "no relay host specified"; }
|
||
|
|
||
|
if [ -z "$PORT" ]; then
|
||
|
PORT=25
|
||
|
fi
|
||
|
|
||
|
if grep -qi "^@$DOMAIN" $DATABASE 2>/dev/null; then
|
||
|
sed -i "s ^@"$DOMAIN".* "@$DOMAIN"\t\t["$HOST"]:"$PORT" " $DATABASE
|
||
|
else
|
||
|
echo -e "@$DOMAIN\t\t[$HOST]:$PORT" >> $DATABASE
|
||
|
fi
|