mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
36 lines
696 B
Plaintext
36 lines
696 B
Plaintext
|
#! /bin/bash
|
||
|
|
||
|
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-sasl-password.cf}
|
||
|
|
||
|
DOMAIN="$1"
|
||
|
USER="$2"
|
||
|
PASSWD="$3"
|
||
|
|
||
|
usage() {
|
||
|
echo "Usage: addsaslpassword <domain> <username> <password>"
|
||
|
}
|
||
|
|
||
|
errex() {
|
||
|
echo "$@" 1>&2
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
escape() {
|
||
|
echo "${1//./\\.}"
|
||
|
}
|
||
|
|
||
|
[ -z "$DOMAIN" ] && { usage; errex "no domain specified"; }
|
||
|
[ -z "$USER" ] && { usage; errex "no username specified"; }
|
||
|
|
||
|
if [ -z "$PASSWD" ]; then
|
||
|
read -s -p "Enter Password: " PASSWD
|
||
|
echo
|
||
|
[ -z "$PASSWD" ] && errex "Password must not be empty"
|
||
|
fi
|
||
|
|
||
|
if grep -qi "^@$DOMAIN" $DATABASE 2>/dev/null; then
|
||
|
sed -i "s ^@"$DOMAIN".* "@$DOMAIN"\t\t"$USER":"$PASSWD" " $DATABASE
|
||
|
else
|
||
|
echo -e "@$DOMAIN\t\t$USER:$PASSWD" >> $DATABASE
|
||
|
fi
|