mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
c881facbd2
* splitting start-mailserver.sh * refactoring part 2 * refactored setup-stack.sh * stzarted adjusting target/bin/*.sh to use new usage format * corrected lowercase-uppercase test error * better handling of .bashrc variable export * linting tests and fix for default assignements * last stylistic changes and rebase
34 lines
833 B
Bash
Executable file
34 lines
833 B
Bash
Executable file
#! /bin/bash
|
|
|
|
# shellcheck source=../scripts/helper-functions.sh
|
|
. /usr/local/bin/helper-functions.sh
|
|
|
|
DATABASE=${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 ; 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
|