mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-03 09:34:33 +02:00
refactoring: split helper functions into smaller scripts (#2420)
This commit is contained in:
parent
2927cc47c7
commit
b61dfe1e24
41 changed files with 389 additions and 396 deletions
|
@ -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}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue