refactoring: split helper functions into smaller scripts (#2420)

This commit is contained in:
Georg Lauterbach 2022-02-21 11:56:57 +01:00 committed by GitHub
parent 2927cc47c7
commit b61dfe1e24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 389 additions and 396 deletions

View file

@ -2,8 +2,8 @@
# shellcheck disable=SC2094
# shellcheck source=../scripts/helper-functions.sh
. /usr/local/bin/helper-functions.sh
# shellcheck source=../scripts/helpers/index.sh
source /usr/local/bin/helpers/index.sh
DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf}
@ -39,12 +39,12 @@ FULL_EMAIL="${1}"
shift
PASSWD="${*}"
[[ -z ${FULL_EMAIL} ]] && { __usage ; errex 'No username specified' ; }
[[ ${FULL_EMAIL} =~ .*\@.* ]] || { __usage ; errex 'Username must include the domain' ; }
[[ -z ${FULL_EMAIL} ]] && { __usage ; _errex 'No username specified' ; }
[[ ${FULL_EMAIL} =~ .*\@.* ]] || { __usage ; _errex 'Username must include the domain' ; }
touch "${DATABASE}"
create_lock # Protect config file with lock to avoid race conditions
if grep -qi "^$(escape "${FULL_EMAIL}")|" "${DATABASE}"
_create_lock # Protect config file with lock to avoid race conditions
if grep -qi "^$(_escape "${FULL_EMAIL}")|" "${DATABASE}"
then
echo "User '${FULL_EMAIL}' already exists."
exit 1
@ -54,7 +54,7 @@ if [[ -z ${PASSWD} ]]
then
read -r -s -p "Enter Password: " PASSWD
echo
[[ -z ${PASSWD} ]] && errex "Password must not be empty"
[[ -z ${PASSWD} ]] && _errex "Password must not be empty"
fi
HASH="$(doveadm pw -s SHA512-CRYPT -u "${FULL_EMAIL}" -p "${PASSWD}")"