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
|
|
|
|
2021-02-23 19:03:01 +00:00
|
|
|
function __usage { echo "Usage: addsaslpassword <domain> <username> <password>" ; }
|
|
|
|
|
|
|
|
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DOMAIN="${1}"
|
|
|
|
USER="${2}"
|
|
|
|
PASSWD="${3}"
|
2018-04-02 08:45:58 +00:00
|
|
|
|
2021-02-23 19:03:01 +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
|
2021-02-23 19:03:01 +00:00
|
|
|
[[ -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
|
2021-02-23 19:03:01 +00:00
|
|
|
sed -i \
|
|
|
|
"s|^@${DOMAIN}.*|@${DOMAIN}\t\t${USER}:${PASSWD}|" \
|
|
|
|
"${DATABASE}"
|
2018-04-02 08:45:58 +00:00
|
|
|
else
|
2021-02-23 19:03:01 +00:00
|
|
|
echo -e "@${DOMAIN}\t\t${USER}:${PASSWD}" >>"${DATABASE}"
|
2018-04-02 08:45:58 +00:00
|
|
|
fi
|