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

@ -5,8 +5,8 @@
# ? being used below. (This disables the message file-wide.)
# 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/dovecot-quotas.cf}
USER_DATABASE=${USER_DATABASE:-/tmp/docker-mailserver/postfix-accounts.cf}
@ -17,36 +17,36 @@ QUOTA="${*}"
function usage { echo "Usage: setquota <user@domain> [<quota>]" ; }
[[ -z ${USER} ]] && { usage ; errex "no username specified" ; }
[[ ${USER} =~ .*\@.* ]] || { usage ; errex "username must include the domain" ; }
[[ -z ${USER} ]] && { usage ; _errex "no username specified" ; }
[[ ${USER} =~ .*\@.* ]] || { usage ; _errex "username must include the domain" ; }
if ! grep -qE "^${USER}\|" "${USER_DATABASE}"
then
usage; errex "user ${USER} does not exist"
usage; _errex "user ${USER} does not exist"
fi
# check quota
if [[ -n ${QUOTA} ]] && ! echo "${QUOTA}" | grep -qE "^([0-9]+(B|k|M|G|T)|0)\$"
then
usage
errex "invalid quota format. e.g. 302M (B (byte), k (kilobyte), M (megabyte), G (gigabyte) or T (terabyte))"
_errex "invalid quota format. e.g. 302M (B (byte), k (kilobyte), M (megabyte), G (gigabyte) or T (terabyte))"
fi
create_lock # Protect config file with lock to avoid race conditions
_create_lock # Protect config file with lock to avoid race conditions
touch "${DATABASE}"
if [[ -z ${QUOTA} ]]
then
read -r -s "Enter quota (e.g. 10M): " QUOTA
echo
[[ -z "${QUOTA}" ]] && errex "Quota must not be empty. Use 0 for unlimited quota"
[[ -z "${QUOTA}" ]] && _errex "Quota must not be empty. Use 0 for unlimited quota"
fi
# check quota
if [[ -n ${QUOTA} ]] && ! echo "${QUOTA}" | grep -qE "^([0-9]+(B|k|M|G|T)|0)\$"
then
usage
errex "invalid quota format. e.g. 302M (B (byte), k (kilobyte), M (megabyte), G (gigabyte) or T (terabyte))"
_errex "invalid quota format. e.g. 302M (B (byte), k (kilobyte), M (megabyte), G (gigabyte) or T (terabyte))"
fi
delquota "${USER}"