docker-mailserver/target/bin/addsaslpassword

30 lines
765 B
Plaintext
Raw Normal View History

#! /bin/bash
# shellcheck source=../bin-helper.sh
. /usr/local/bin/bin-helper.sh
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-sasl-password.cf}
DOMAIN="${1}"
USER="${2}"
PASSWD="${3}"
function usage { echo "Usage: addsaslpassword <domain> <username> <password>" ; }
[[ -z ${DOMAIN} ]] && { usage ; errex "no domain specified" ; }
[[ -z ${USER} ]] && { usage ; errex "no username specified" ; }
if [[ -z ${PASSWD} ]]
then
read -r -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