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-sasl-password.cf}
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DOMAIN="${1}"
|
|
|
|
USER="${2}"
|
|
|
|
PASSWD="${3}"
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
function usage { echo "Usage: addsaslpassword <domain> <username> <password>" ; }
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
[[ -z ${DOMAIN} ]] && { usage ; errex "no domain specified" ; }
|
|
|
|
[[ -z ${USER} ]] && { usage ; errex "no username specified" ; }
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if [[ -z ${PASSWD} ]]
|
|
|
|
then
|
|
|
|
read -r -s -p "Enter Password: " PASSWD
|
|
|
|
echo
|
|
|
|
[[ -z ${PASSWD} ]] && errex "Password must not be empty"
|
2018-04-02 08:45:58 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if grep -qi "^@${DOMAIN}" "${DATABASE}" 2>/dev/null
|
|
|
|
then
|
|
|
|
sed -i "s ^@""${DOMAIN}"".* ""@""${DOMAIN}""\t\t""${USER}"":""${PASSWD}"" " "${DATABASE}"
|
2018-04-02 08:45:58 +00:00
|
|
|
else
|
2020-10-21 16:16:32 +00:00
|
|
|
echo -e "@${DOMAIN}\t\t${USER}:${PASSWD}" >> "${DATABASE}"
|
2018-04-02 08:45:58 +00:00
|
|
|
fi
|