scripts: Improve error handling, when parameters are missing (#2854)

This commit is contained in:
Casper 2022-10-29 11:04:35 +02:00 committed by GitHub
parent caf2338201
commit 897d84f0f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 26 additions and 20 deletions

View file

@ -17,6 +17,7 @@ All notable changes to this project will be documented in this file. The format
### Fixed
- **scripts**: Improve error handling, when parameters are missing ([#2854](https://github.com/docker-mailserver/docker-mailserver/pull/2854))
- **scripts**: Fix unbound variable error ([#2849](https://github.com/docker-mailserver/docker-mailserver/pull/2849), [#2853](https://github.com/docker-mailserver/docker-mailserver/pull/2853))
- **scripts**: Make fetchmail data persistant ([#2851](https://github.com/docker-mailserver/docker-mailserver/pull/2851))
- **scripts**: Run `user-patches.sh` right before starting daemons ([#2817](https://github.com/docker-mailserver/docker-mailserver/pull/2817))

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 2 "${@}"
local MAIL_ALIAS="${1}"
local RECIPIENT="${2}"

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local MAIL_ACCOUNT="${1}"
shift

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local MAIL_ACCOUNT="${1}"
shift

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 2 "${@}"
local DOMAIN="${1}"
local HOST="${2}"

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 2 "${@}"
local DOMAIN="${1}"
local RELAY_ACCOUNT="${2}"

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 2 "${@}"
local MAIL_ALIAS="${1}"
local RECIPIENT="${2}"

View file

@ -5,10 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
# Validate Parameters:
[[ -z ${*} ]] && { __usage ; _exit_with_error 'No account specified' ; }
_require_n_parameters_or_print_usage 1 "${@}"
# Actual command to perform:
for MAIL_ACCOUNT in "${@}"

View file

@ -5,12 +5,11 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
# Tests expect early exit without error if no DB exists:
[[ -s ${DATABASE_ACCOUNTS} ]] || return 0
# Validate Parameters:
[[ -z ${*} ]] && { __usage ; _exit_with_error 'No account specified' ; }
_maildel_request_if_missing
# TODO: May want to lock all database files prior to loop? (DATABASE_ACCOUNTS DATABASE_QUOTA DATABASE_VIRTUAL)

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local MAIL_ACCOUNT="${1}"

View file

@ -5,10 +5,9 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local DOMAIN="${1}"
[[ -z ${DOMAIN} ]] && { __usage ; _exit_with_error 'No domain specified' ; }
_exclude_domain_from_relayhosts
}

View file

@ -51,7 +51,7 @@ ${ORANGE}EXIT STATUS${RESET}
"
}
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 0 "${@}"
while [[ ${#} -gt 0 ]]
do

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local MAIL_ACCOUNT="${1}"
shift

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local MAIL_ACCOUNT="${1}"
shift

View file

@ -5,7 +5,7 @@ source /usr/local/bin/helpers/index.sh
function _main
{
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
_require_n_parameters_or_print_usage 1 "${@}"
local MAIL_ACCOUNT="${1}"
shift

View file

@ -34,3 +34,13 @@ function _chown_var_mail_if_necessary
chown -R 5000:5000 /var/mail || return 1
fi
}
function _require_n_parameters_or_print_usage
{
local COUNT
COUNT=${1}
shift
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
[[ ${#} -lt ${COUNT} ]] && { __usage ; exit 1 ; }
}