1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-06-29 04:31:23 +02:00
docker-mailserver/target/bin/addsaslpassword
Brennan Kinney 182b71d33f
chore: Drop setup.sh DATABASE fallback ENV (#2556)
* chore: Remove `DATABASE` fallback ENV

This was introduced without any mention or need, thus removing until a real use-case requires it.

* chore: Remove `USER_DATABASE` fallback ENV

Likewise, nothing requires this to be customizable.

* chore: Consistently use single quote strings
2022-04-20 12:29:28 +12:00

34 lines
854 B
Bash
Executable File

#! /bin/bash
# shellcheck source=../scripts/helpers/index.sh
source /usr/local/bin/helpers/index.sh
DATABASE='/tmp/docker-mailserver/postfix-sasl-password.cf'
function __usage { echo "Usage: addsaslpassword <domain> <username> <password>" ; }
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
DOMAIN="${1}"
USER="${2}"
PASSWD="${3}"
[[ -z ${DOMAIN} ]] && { __usage ; _exit_with_error 'No domain specified' ; }
[[ -z ${USER} ]] && { __usage ; _exit_with_error 'No username specified' ; }
if [[ -z ${PASSWD} ]]
then
read -r -s -p "Enter Password: " PASSWD
echo
[[ -z ${PASSWD} ]] && _exit_with_error '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