From b7bf40ac217884ba16b13396e1ebbd2918180453 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:01:07 +0100 Subject: [PATCH] renamed function `_errex` -> `_exit_with_error` (#2497) --- target/bin/addalias | 6 +++--- target/bin/addmailuser | 6 +++--- target/bin/addrelayhost | 4 ++-- target/bin/addsaslpassword | 6 +++--- target/bin/delalias | 4 ++-- target/bin/delmailuser | 6 +++--- target/bin/delquota | 6 +++--- target/bin/excluderelaydomain | 2 +- target/bin/fail2ban | 2 +- target/bin/listalias | 4 ++-- target/bin/listmailuser | 4 ++-- target/bin/postfix-summary | 2 +- target/bin/report-pflogsumm-yesterday | 2 +- target/bin/restrict-access | 12 ++++++------ target/bin/setquota | 12 ++++++------ target/bin/updatemailuser | 6 +++--- target/scripts/helpers/error.sh | 4 ++-- target/scripts/helpers/lock.sh | 2 +- 18 files changed, 45 insertions(+), 45 deletions(-) diff --git a/target/bin/addalias b/target/bin/addalias index 42cb5297..b8d2d61c 100755 --- a/target/bin/addalias +++ b/target/bin/addalias @@ -36,12 +36,12 @@ function __usage EMAIL="${1}" RECIPIENT="${2}" -[[ -z ${EMAIL} ]] && { __usage ; _errex 'No alias specified' ; } -[[ -z ${RECIPIENT} ]] && { __usage ; _errex 'No recipient specified' ; } +[[ -z ${EMAIL} ]] && { __usage ; _exit_with_error 'No alias specified' ; } +[[ -z ${RECIPIENT} ]] && { __usage ; _exit_with_error 'No recipient specified' ; } grep \ -qi "^$(_escape "${EMAIL}")[a-zA-Z@.\ ]*$(_escape "${RECIPIENT}")" \ - "${DATABASE}" 2>/dev/null && _errex "Alias \"${EMAIL} ${RECIPIENT}\" already exists" + "${DATABASE}" 2>/dev/null && _exit_with_error "Alias \"${EMAIL} ${RECIPIENT}\" already exists" if grep -qi "^$(_escape "${EMAIL}")" "${DATABASE}" 2>/dev/null then diff --git a/target/bin/addmailuser b/target/bin/addmailuser index 3ae82390..ef708b4e 100755 --- a/target/bin/addmailuser +++ b/target/bin/addmailuser @@ -39,8 +39,8 @@ 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 ; _exit_with_error 'No username specified' ; } +[[ ${FULL_EMAIL} =~ .*\@.* ]] || { __usage ; _exit_with_error 'Username must include the domain' ; } touch "${DATABASE}" _create_lock # Protect config file with lock to avoid race conditions @@ -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} ]] && _exit_with_error "Password must not be empty" fi HASH="$(doveadm pw -s SHA512-CRYPT -u "${FULL_EMAIL}" -p "${PASSWD}")" diff --git a/target/bin/addrelayhost b/target/bin/addrelayhost index 807e9a0e..8ed8eb03 100755 --- a/target/bin/addrelayhost +++ b/target/bin/addrelayhost @@ -32,8 +32,8 @@ DOMAIN="${1}" HOST="${2}" PORT="${3}" -[[ -z ${DOMAIN} ]] && { __usage ; _errex 'No domain specified' ; } -[[ -z ${HOST} ]] && { __usage ; _errex 'No relay host specified' ; } +[[ -z ${DOMAIN} ]] && { __usage ; _exit_with_error 'No domain specified' ; } +[[ -z ${HOST} ]] && { __usage ; _exit_with_error 'No relay host specified' ; } [[ -z ${PORT} ]] && PORT=25 if grep -qi "^@${DOMAIN}" "${DATABASE}" 2>/dev/null diff --git a/target/bin/addsaslpassword b/target/bin/addsaslpassword index d38f5aed..76d29b95 100755 --- a/target/bin/addsaslpassword +++ b/target/bin/addsaslpassword @@ -13,14 +13,14 @@ DOMAIN="${1}" USER="${2}" PASSWD="${3}" -[[ -z ${DOMAIN} ]] && { __usage ; _errex 'No domain specified' ; } -[[ -z ${USER} ]] && { __usage ; _errex 'No username specified' ; } +[[ -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} ]] && _errex 'Password must not be empty' + [[ -z ${PASSWD} ]] && _exit_with_error 'Password must not be empty' fi if grep -qi "^@${DOMAIN}" "${DATABASE}" 2>/dev/null diff --git a/target/bin/delalias b/target/bin/delalias index 3f276474..0a0ecbf2 100755 --- a/target/bin/delalias +++ b/target/bin/delalias @@ -12,8 +12,8 @@ function __usage { echo "Usage: delalias " ; } [[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; } -[[ -z ${EMAIL} ]] && { __usage ; _errex "Error: No alias specified" ; } -[[ -z ${RECIPIENT} ]] && { __usage ; _errex "Error: No recipient specified" ; } +[[ -z ${EMAIL} ]] && { __usage ; _exit_with_error "Error: No alias specified" ; } +[[ -z ${RECIPIENT} ]] && { __usage ; _exit_with_error "Error: No recipient specified" ; } [[ -s ${DATABASE} ]] || exit 0 sed -i \ diff --git a/target/bin/delmailuser b/target/bin/delmailuser index 9addd1e9..8c5ad727 100755 --- a/target/bin/delmailuser +++ b/target/bin/delmailuser @@ -67,14 +67,14 @@ do * ) __usage - _errex "The option ${OPT} is unknown." + _exit_with_error "The option ${OPT} is unknown." ;; esac done shift $((OPTIND-1)) -[[ -z ${*} ]] && { __usage ; _errex "No user specifed" ; } +[[ -z ${*} ]] && { __usage ; _exit_with_error "No user specifed" ; } [[ -s ${DATABASE} ]] || exit 0 if ! ${MAILDEL} @@ -155,6 +155,6 @@ use 'sudo docker exec mailserver rm -R /var/mail/${DOMAIN}/${USER}'" ERROR=true fi - ${ERROR} && _errex 'See the messages above.' + ${ERROR} && _exit_with_error 'See the messages above.' done exit 0 diff --git a/target/bin/delquota b/target/bin/delquota index 6cd38464..388c9c9f 100755 --- a/target/bin/delquota +++ b/target/bin/delquota @@ -12,13 +12,13 @@ function __usage { echo "Usage: delquota " ; } USER="${1}" -[[ -z ${USER} ]] && { __usage ; _errex "No username specified" ; } -[[ ${USER} =~ .*\@.* ]] || { __usage ; _errex "Username must include the domain"; } +[[ -z ${USER} ]] && { __usage ; _exit_with_error "No username specified" ; } +[[ ${USER} =~ .*\@.* ]] || { __usage ; _exit_with_error "Username must include the domain"; } if ! grep -qE "^${USER}\|" "${USER_DATABASE}" then __usage - _errex "user ${USER} does not exist" + _exit_with_error "user ${USER} does not exist" fi [[ -s ${DATABASE} ]] || exit 0 diff --git a/target/bin/excluderelaydomain b/target/bin/excluderelaydomain index 4d5a1305..f86c6c8c 100755 --- a/target/bin/excluderelaydomain +++ b/target/bin/excluderelaydomain @@ -9,7 +9,7 @@ DOMAIN="${1}" function usage { echo "Usage: excluderelayhost " ; } -[[ -z ${DOMAIN} ]] && { usage ; _errex "no domain specified" ; } +[[ -z ${DOMAIN} ]] && { usage ; _exit_with_error "no domain specified" ; } if grep -qi "^@${DOMAIN}" "${DATABASE}" 2>/dev/null then diff --git a/target/bin/fail2ban b/target/bin/fail2ban index a89433f0..58f2b6a7 100755 --- a/target/bin/fail2ban +++ b/target/bin/fail2ban @@ -75,7 +75,7 @@ else *) usage - _errex "unknown command: ${1}" + _exit_with_error "unknown command: ${1}" ;; esac diff --git a/target/bin/listalias b/target/bin/listalias index ebaebc63..cc4b371a 100755 --- a/target/bin/listalias +++ b/target/bin/listalias @@ -5,8 +5,8 @@ source /usr/local/bin/helpers/index.sh DATABASE=${DATABASE:-/tmp/docker-mailserver/postfix-virtual.cf} -[[ -f ${DATABASE} ]] || _errex "Error: No postfix-virtual.cf file" -[[ -s ${DATABASE} ]] || _errex "Error: Empty postfix-virtual.cf - no aliases have been added" +[[ -f ${DATABASE} ]] || _exit_with_error "Error: No postfix-virtual.cf file" +[[ -s ${DATABASE} ]] || _exit_with_error "Error: Empty postfix-virtual.cf - no aliases have been added" grep -v "^\s*$\|^\s*\#" "${DATABASE}" exit 0 diff --git a/target/bin/listmailuser b/target/bin/listmailuser index ac2005c9..46a59730 100755 --- a/target/bin/listmailuser +++ b/target/bin/listmailuser @@ -23,8 +23,8 @@ function dovecot_quota_to_hr() DATABASE="/tmp/docker-mailserver/postfix-accounts.cf" ALIASES="/tmp/docker-mailserver/postfix-virtual.cf" -[[ -f ${DATABASE} ]] || _errex "Error: No postfix-accounts.cf file" -[[ -s ${DATABASE} ]] || _errex "Error: Empty postfix-accounts.cf - no accounts have been added" +[[ -f ${DATABASE} ]] || _exit_with_error "Error: No postfix-accounts.cf file" +[[ -s ${DATABASE} ]] || _exit_with_error "Error: Empty postfix-accounts.cf - no accounts have been added" while read -r LINE do diff --git a/target/bin/postfix-summary b/target/bin/postfix-summary index 015e2d1d..b049a00c 100755 --- a/target/bin/postfix-summary +++ b/target/bin/postfix-summary @@ -7,7 +7,7 @@ HOSTNAME=${1} RECIPIENT=${2} SENDER=${3} -[[ -x /usr/sbin/pflogsumm ]] || _errex "Critical: /usr/sbin/pflogsumm not found" +[[ -x /usr/sbin/pflogsumm ]] || _exit_with_error "Critical: /usr/sbin/pflogsumm not found" # The case that the mail.log.1 file isn't readable shouldn't # actually be possible with logrotate not rotating empty files.. diff --git a/target/bin/report-pflogsumm-yesterday b/target/bin/report-pflogsumm-yesterday index 31fcf7d8..cb7b6818 100755 --- a/target/bin/report-pflogsumm-yesterday +++ b/target/bin/report-pflogsumm-yesterday @@ -11,7 +11,7 @@ HOSTNAME=${1} RECIPIENT=${2} SENDER=${3} -[[ -x /usr/sbin/pflogsumm ]] || _errex "Critical: /usr/sbin/pflogsumm not found" +[[ -x /usr/sbin/pflogsumm ]] || _exit_with_error "Critical: /usr/sbin/pflogsumm not found" # shellcheck disable=SC2046 BODY=$(gzip -cdfq $(ls -tr /var/log/mail/mail.log*) | /usr/sbin/pflogsumm --problems_first -d yesterday) diff --git a/target/bin/restrict-access b/target/bin/restrict-access index 65d30859..c7fbaa8c 100755 --- a/target/bin/restrict-access +++ b/target/bin/restrict-access @@ -8,7 +8,7 @@ USER="${3}" function usage { echo "Usage: ${0} []" ; } -[[ -z ${MODE} ]] && _errex "missing parameters: []" +[[ -z ${MODE} ]] && _exit_with_error "missing parameters: []" case ${2} in send) @@ -19,7 +19,7 @@ case ${2} in ;; *) usage - _errex "missing parameters. Specify \"send\" or \"receive\"" + _exit_with_error "missing parameters. Specify \"send\" or \"receive\"" ;; esac @@ -27,12 +27,12 @@ if [[ -z ${USER} ]] && [[ ${MODE} != list ]] then read -r -p "User(user@domain.com): " USER echo - [[ -z ${USER} ]] && _errex "User must not be empty" + [[ -z ${USER} ]] && _exit_with_error "User must not be empty" fi case ${MODE} in add) - grep -qi "^$(_escape "${USER}")" "${DATABASE}" 2>/dev/null && _errex "User \"${USER}\" already denied to ${2} mails" + grep -qi "^$(_escape "${USER}")" "${DATABASE}" 2>/dev/null && _exit_with_error "User \"${USER}\" already denied to ${2} mails" if [[ ! -f ${DATABASE} ]] then @@ -48,7 +48,7 @@ case ${MODE} in ;; del) - sed -ie "/^$(_escape "${USER}")/d" "${DATABASE}" 2>/dev/null || _errex "User \"${USER}\" not found." + sed -ie "/^$(_escape "${USER}")/d" "${DATABASE}" 2>/dev/null || _exit_with_error "User \"${USER}\" not found." ;; list) @@ -56,7 +56,7 @@ case ${MODE} in ;; *) usage - _errex "missing mode. Specify \"add\", \"del\" or \"list\"" + _exit_with_error "missing mode. Specify \"add\", \"del\" or \"list\"" ;; esac diff --git a/target/bin/setquota b/target/bin/setquota index 2e85dec2..9fd6ee5e 100755 --- a/target/bin/setquota +++ b/target/bin/setquota @@ -17,19 +17,19 @@ QUOTA="${*}" function usage { echo "Usage: setquota []" ; } -[[ -z ${USER} ]] && { usage ; _errex "no username specified" ; } -[[ ${USER} =~ .*\@.* ]] || { usage ; _errex "username must include the domain" ; } +[[ -z ${USER} ]] && { usage ; _exit_with_error "no username specified" ; } +[[ ${USER} =~ .*\@.* ]] || { usage ; _exit_with_error "username must include the domain" ; } if ! grep -qE "^${USER}\|" "${USER_DATABASE}" then - usage; _errex "user ${USER} does not exist" + usage; _exit_with_error "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))" + _exit_with_error "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 @@ -39,14 +39,14 @@ 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}" ]] && _exit_with_error "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))" + _exit_with_error "invalid quota format. e.g. 302M (B (byte), k (kilobyte), M (megabyte), G (gigabyte) or T (terabyte))" fi delquota "${USER}" diff --git a/target/bin/updatemailuser b/target/bin/updatemailuser index 52c264b8..7234a438 100755 --- a/target/bin/updatemailuser +++ b/target/bin/updatemailuser @@ -16,18 +16,18 @@ PASSWD="${*}" function usage { echo "Usage: updatemailuser [password]" ; } -[[ -z ${USER} ]] && { usage ; _errex "no username specified" ; } +[[ -z ${USER} ]] && { usage ; _exit_with_error "no username specified" ; } if [[ -z ${PASSWD} ]] then read -r -s -p "Enter Password: " PASSWD echo - [[ -z ${PASSWD} ]] && _errex "Password must not be empty" + [[ -z ${PASSWD} ]] && _exit_with_error "Password must not be empty" fi HASH="$(doveadm pw -s SHA512-CRYPT -u "${USER}" -p "${PASSWD}")" touch "${DATABASE}" _create_lock # Protect config file with lock to avoid race conditions -grep -qi "^$(_escape "${USER}")|" "${DATABASE}" 2>/dev/null || _errex "User \"${USER}\" does not exist" +grep -qi "^$(_escape "${USER}")|" "${DATABASE}" 2>/dev/null || _exit_with_error "User \"${USER}\" does not exist" sed -i "s ^""${USER}""|.* ""${USER}""|""${HASH}"" " "${DATABASE}" diff --git a/target/scripts/helpers/error.sh b/target/scripts/helpers/error.sh index 57151533..ae7fb799 100644 --- a/target/scripts/helpers/error.sh +++ b/target/scripts/helpers/error.sh @@ -1,12 +1,12 @@ #! /bin/bash -function _errex +function _exit_with_error { if [[ -n ${1+set} ]] then _log 'error' "${1}" else - _log 'error' "Call to '_errex' is missing a message to log" + _log 'error' "Call to '_exit_with_error' is missing a message to log" fi _log 'error' 'Aborting' diff --git a/target/scripts/helpers/lock.sh b/target/scripts/helpers/lock.sh index 63693ae4..76ba482f 100644 --- a/target/scripts/helpers/lock.sh +++ b/target/scripts/helpers/lock.sh @@ -31,7 +31,7 @@ function _create_lock function _remove_lock { LOCK_FILE="${LOCK_FILE:-"/tmp/docker-mailserver/${SCRIPT_NAME}.lock"}" - [[ -z "${LOCK_ID}" ]] && _errex "Cannot remove ${LOCK_FILE} as there is no LOCK_ID set" + [[ -z "${LOCK_ID}" ]] && _exit_with_error "Cannot remove ${LOCK_FILE} as there is no LOCK_ID set" if [[ -e "${LOCK_FILE}" ]] && grep -q "${LOCK_ID}" "${LOCK_FILE}" # Ensure we don't delete a lock that's not ours then rm -f "${LOCK_FILE}"