mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
scripts: apply fixes to helpers when using set -eE
(#3285)
For an upcoming PR, these changes are required, because the script that is using the helpers uses `set -eE`. This leads to situations where errors are not properly handled in our helpers (yet; I plan on changing that in the future).
This commit is contained in:
parent
449d53fc3f
commit
7e7497ae5a
|
@ -41,7 +41,7 @@ function _obtain_hostname_and_domainname
|
|||
# of this variable or if a more deterministic approach with `cut` should be relied on.
|
||||
if [[ $(_get_label_count "${HOSTNAME}") -gt 2 ]]
|
||||
then
|
||||
if [[ -n ${OVERRIDE_HOSTNAME} ]]
|
||||
if [[ -n ${OVERRIDE_HOSTNAME:-} ]]
|
||||
then
|
||||
# Emulates the intended behaviour of `hostname -d`:
|
||||
# Assign the HOSTNAME value minus everything up to and including the first `.`
|
||||
|
|
|
@ -87,3 +87,26 @@ function _shutdown
|
|||
kill -SIGTERM 1 # Trigger graceful DMS shutdown.
|
||||
kill -SIGUSR1 "${SCRIPT_PID}" # Stop start-mailserver.sh execution, even when _shutdown() is called from a subshell.
|
||||
}
|
||||
|
||||
# Calling this function sets up a handler for the `ERR` signal, that occurs when
|
||||
# an error is not properly checked (e.g., in an `if`-clause or in an `&&` block).
|
||||
#
|
||||
# This is mostly useful for debugging. It also helps when using something like `set -eE`,
|
||||
# as it shows where the script aborts.
|
||||
function _trap_err_signal
|
||||
{
|
||||
trap '__log_unexpected_error "${FUNCNAME[0]:-}" "${BASH_COMMAND:-}" "${LINENO:-}" "${?:-}"' ERR
|
||||
|
||||
# shellcheck disable=SC2317
|
||||
function __log_unexpected_error
|
||||
{
|
||||
local MESSAGE="Unexpected error occured :: script = ${SCRIPT:-${0}} "
|
||||
MESSAGE+=" | function = ${1:-none (global)}"
|
||||
MESSAGE+=" | command = ${2:-?}"
|
||||
MESSAGE+=" | line = ${3:-?}"
|
||||
MESSAGE+=" | exit code = ${4:-?}"
|
||||
|
||||
_log 'error' "${MESSAGE}"
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,9 +123,9 @@ function _get_log_level_or_default
|
|||
if [[ -n ${LOG_LEVEL+set} ]]
|
||||
then
|
||||
echo "${LOG_LEVEL}"
|
||||
elif [[ -e /etc/dms-settings ]]
|
||||
elif [[ -e /etc/dms-settings ]] && grep -q -E "^LOG_LEVEL='[a-z]+'" /etc/dms-settings
|
||||
then
|
||||
grep "^LOG_LEVEL=" /etc/dms-settings | cut -d "'" -f 2
|
||||
grep '^LOG_LEVEL=' /etc/dms-settings | cut -d "'" -f 2
|
||||
else
|
||||
echo 'info'
|
||||
fi
|
||||
|
|
|
@ -16,7 +16,13 @@ function _get_valid_lines_from_file
|
|||
# and it will return its value stored in /etc/dms-settings
|
||||
function _get_dms_env_value
|
||||
{
|
||||
if [[ -f /etc/dms-settings ]]
|
||||
then
|
||||
grep "^${1}=" /etc/dms-settings | cut -d "'" -f 2
|
||||
else
|
||||
_log 'warn' "Call to '_get_dms_env_value' but '/etc/dms-settings' is not present"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# TODO: `chown -R 5000:5000 /var/mail` has existed since the projects first commit.
|
||||
|
@ -33,6 +39,7 @@ function _chown_var_mail_if_necessary
|
|||
_log 'trace' 'Fixing /var/mail permissions'
|
||||
chown -R 5000:5000 /var/mail || return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function _require_n_parameters_or_print_usage
|
||||
|
@ -43,6 +50,7 @@ function _require_n_parameters_or_print_usage
|
|||
|
||||
[[ ${1:-} == 'help' ]] && { __usage ; exit 0 ; }
|
||||
[[ ${#} -lt ${COUNT} ]] && { __usage ; exit 1 ; }
|
||||
return 0
|
||||
}
|
||||
|
||||
# NOTE: Postfix commands that read `main.cf` will stall execution,
|
||||
|
@ -56,6 +64,7 @@ function _adjust_mtime_for_postfix_maincf
|
|||
then
|
||||
touch -d '2 seconds ago' /etc/postfix/main.cf
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
function _reload_postfix
|
||||
|
|
Loading…
Reference in a new issue