From 84f0d3dab475afb10c71adbaf7a82007ec9df353 Mon Sep 17 00:00:00 2001 From: Davide Polonio Date: Mon, 20 Sep 2021 08:21:30 +0000 Subject: [PATCH] Bump mail server to 10.1.2 --- mail/docker-compose.yml | 2 +- mail/setup.sh | 136 +++++++++++++++++++--------------------- 2 files changed, 67 insertions(+), 71 deletions(-) diff --git a/mail/docker-compose.yml b/mail/docker-compose.yml index 4659d1e..ea9441d 100644 --- a/mail/docker-compose.yml +++ b/mail/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.7' services: mail: - image: mailserver/docker-mailserver:9.1.0 + image: mailserver/docker-mailserver:10.1.2 hostname: ${HOSTNAME} domainname: ${DOMAINNAME} container_name: ${CONTAINER_NAME} diff --git a/mail/setup.sh b/mail/setup.sh index 6b26ef1..0cffd32 100755 --- a/mail/setup.sh +++ b/mail/setup.sh @@ -19,15 +19,14 @@ RESET="\e[0m" set -euEo pipefail trap '__log_err "${FUNCNAME[0]:-?}" "${BASH_COMMAND:-?}" "${LINENO:-?}" "${?:-?}"' ERR -trap '_unset_vars || :' EXIT function __log_err { - printf "\n––– ${BOLD}${RED}UNCHECKED ERROR${RESET}\n%s\n%s\n%s\n%s\n\n" \ - " – script = ${SCRIPT:-${0}}" \ - " – function = ${1} / ${2}" \ - " – line = ${3}" \ - " – exit code = ${4}" >&2 + printf "\n--- ${BOLD}${RED}UNCHECKED ERROR${RESET}\n%s\n%s\n%s\n%s\n\n" \ + " - script = ${SCRIPT:-${0}}" \ + " - function = ${1} / ${2}" \ + " - line = ${3}" \ + " - exit code = ${4}" >&2 printf "Make sure you use a version of this script that matches the version / tag of docker-mailserver. Please read the @@ -35,39 +34,38 @@ the version / tag of docker-mailserver. Please read the ly and use ./setup.sh help and read the VERSION section.\n" >&2 } -function _unset_vars -{ - unset CDIR CRI INFO IMAGE_NAME CONTAINER_NAME DEFAULT_CONFIG_PATH - unset USE_CONTAINER WISHED_CONFIG_PATH CONFIG_PATH VOLUME USE_TTY - unset SCRIPT USING_SELINUX -} - -function _get_current_directory +function _get_absolute_script_directory { + if [[ "$(uname)" == "Darwin" ]] + then + readlink() { + greadlink "${@:+$@}" # Requires coreutils + } + fi if dirname "$(readlink -f "${0}")" &>/dev/null then - CDIR="$(dirname "$(readlink -f "${0}")")" + DIR="$(dirname "$(readlink -f "${0}")")" elif realpath -e -L "${0}" &>/dev/null then - CDIR="$(realpath -e -L "${0}")" - CDIR="${CDIR%/setup.sh}" + DIR="$(realpath -e -L "${0}")" + DIR="${DIR%/setup.sh}" fi } -CDIR="$(pwd)" -_get_current_directory +DIR="$(pwd)" +_get_absolute_script_directory CRI= -INFO= -IMAGE_NAME= -CONTAINER_NAME= -DEFAULT_CONFIG_PATH="${CDIR}/config" -USE_CONTAINER=false -WISHED_CONFIG_PATH= CONFIG_PATH= -VOLUME= +CONTAINER_NAME= +DEFAULT_CONFIG_PATH="${DIR}/config" +IMAGE_NAME= +INFO= +USE_CONTAINER=false USE_TTY= -USING_SELINUX= +USE_SELINUX= +VOLUME= +WISHED_CONFIG_PATH= function _check_root { @@ -158,7 +156,7 @@ ${ORANGE}OPTIONS${RESET} -p PATH Provides the config folder path. The default is - ${WHITE}${CDIR}/config/${RESET} + ${WHITE}${DIR}/config/${RESET} ${LBLUE}SELinux${RESET} -z @@ -171,36 +169,35 @@ ${ORANGE}OPTIONS${RESET} ${RED}[${ORANGE}SUB${RED}]${ORANGE}COMMANDS${RESET} ${LBLUE}COMMAND${RESET} email ${RED}:=${RESET} - ${0} email add [] - ${0} email update [] - ${0} email del [ OPTIONS${RED}...${RESET} ] [ ${RED}...${RESET} ] - ${0} email restrict [] - ${0} email list + ${0} email ${CYAN}add${RESET} [] + ${0} email ${CYAN}update${RESET} [] + ${0} email ${CYAN}del${RESET} [ OPTIONS${RED}...${RESET} ] [ ${RED}...${RESET} ] + ${0} email ${CYAN}restrict${RESET} [] + ${0} email ${CYAN}list${RESET} ${LBLUE}COMMAND${RESET} alias ${RED}:=${RESET} - ${0} alias add - ${0} alias del - ${0} alias list + ${0} alias ${CYAN}add${RESET} + ${0} alias ${CYAN}del${RESET} + ${0} alias ${CYAN}list${RESET} ${LBLUE}COMMAND${RESET} quota ${RED}:=${RESET} - ${0} quota set [] - ${0} quota del + ${0} quota ${CYAN}set${RESET} [] + ${0} quota ${CYAN}del${RESET} ${LBLUE}COMMAND${RESET} config ${RED}:=${RESET} - ${0} config dkim [ ARGUMENTS${RED}...${RESET} ] - ${0} config ssl (${CYAN}ATTENTION${RESET}: This is deprecated and will be removed soon.) + ${0} config ${CYAN}dkim${RESET} [ ARGUMENTS${RED}...${RESET} ] ${LBLUE}COMMAND${RESET} relay ${RED}:=${RESET} - ${0} relay add-domain [] - ${0} relay add-auth [] - ${0} relay exclude-domain + ${0} relay ${CYAN}add-domain${RESET} [] + ${0} relay ${CYAN}add-auth${RESET} [] + ${0} relay ${CYAN}exclude-domain${RESET} ${LBLUE}COMMAND${RESET} debug ${RED}:=${RESET} - ${0} debug fetchmail - ${0} debug fail2ban [unban ] - ${0} debug show-mail-logs - ${0} debug inspect - ${0} debug login + ${0} debug ${CYAN}fetchmail${RESET} + ${0} debug ${CYAN}fail2ban${RESET} [unban ] + ${0} debug ${CYAN}show-mail-logs${RESET} + ${0} debug ${CYAN}inspect${RESET} + ${0} debug ${CYAN}login${RESET} ${ORANGE}EXAMPLES${RESET} ${WHITE}./setup.sh email add test@domain.tld${RESET} @@ -234,7 +231,7 @@ function _docker_image if ${USE_CONTAINER} then # reuse existing container specified on command line - ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@}" + ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@:+$@}" else # start temporary container with specified image if ! _docker_image_exists "${IMAGE_NAME}" @@ -244,8 +241,8 @@ function _docker_image fi ${CRI} run --rm \ - -v "${CONFIG_PATH}:/tmp/docker-mailserver${USING_SELINUX}" \ - "${USE_TTY}" "${IMAGE_NAME}" "${@}" + -v "${CONFIG_PATH}:/tmp/docker-mailserver${USE_SELINUX}" \ + "${USE_TTY}" "${IMAGE_NAME}" "${@:+$@}" fi } @@ -253,7 +250,7 @@ function _docker_container { if [[ -n ${CONTAINER_NAME} ]] then - ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@}" + ${CRI} exec "${USE_TTY}" "${CONTAINER_NAME}" "${@:+$@}" else echo "The mailserver is not running!" exit 1 @@ -300,8 +297,8 @@ function _main do case ${OPT} in i ) IMAGE_NAME="${OPTARG}" ;; - z ) USING_SELINUX=":z" ;; - Z ) USING_SELINUX=":Z" ;; + z ) USE_SELINUX=":z" ;; + Z ) USE_SELINUX=":Z" ;; c ) # container specified, connect to running instance CONTAINER_NAME="${OPTARG}" @@ -311,7 +308,7 @@ function _main p ) case "${OPTARG}" in /* ) WISHED_CONFIG_PATH="${OPTARG}" ;; - * ) WISHED_CONFIG_PATH="${CDIR}/${OPTARG}" ;; + * ) WISHED_CONFIG_PATH="${DIR}/${OPTARG}" ;; esac if [[ ! -d ${WISHED_CONFIG_PATH} ]] @@ -349,11 +346,11 @@ function _main email ) case ${2:-} in - add ) shift 2 ; _docker_image addmailuser "${@}" ;; - update ) shift 2 ; _docker_image updatemailuser "${@}" ;; - del ) shift 2 ; _docker_container delmailuser "${@}" ;; - restrict ) shift 2 ; _docker_container restrict-access "${@}" ;; - list ) _docker_image listmailuser ;; + add ) shift 2 ; _docker_image addmailuser "${@:+$@}" ;; + update ) shift 2 ; _docker_image updatemailuser "${@:+$@}" ;; + del ) shift 2 ; _docker_container delmailuser "${@:+$@}" ;; + restrict ) shift 2 ; _docker_container restrict-access "${@:+$@}" ;; + list ) _docker_container listmailuser ;; * ) _usage ;; esac ;; @@ -369,25 +366,24 @@ function _main quota ) case ${2:-} in - set ) shift 2 ; _docker_image setquota "${@}" ;; - del ) shift 2 ; _docker_image delquota "${@}" ;; + set ) shift 2 ; _docker_image setquota "${@:+$@}" ;; + del ) shift 2 ; _docker_image delquota "${@:+$@}" ;; * ) _usage ;; esac ;; config ) case ${2:-} in - dkim ) shift 2 ; _docker_image open-dkim "${@}" ;; - ssl ) shift 2 ; _docker_image generate-ssl-certificate "${1}" ;; + dkim ) shift 2 ; _docker_image open-dkim "${@:+$@}" ;; * ) _usage ;; esac ;; relay ) case ${2:-} in - add-domain ) shift 2 ; _docker_image addrelayhost "${@}" ;; - add-auth ) shift 2 ; _docker_image addsaslpassword "${@}" ;; - exclude-domain ) shift 2 ; _docker_image excluderelaydomain "${@}" ;; + add-domain ) shift 2 ; _docker_image addrelayhost "${@:+$@}" ;; + add-auth ) shift 2 ; _docker_image addsaslpassword "${@:+$@}" ;; + exclude-domain ) shift 2 ; _docker_image excluderelaydomain "${@:+$@}" ;; * ) _usage ;; esac ;; @@ -395,7 +391,7 @@ function _main debug ) case ${2:-} in fetchmail ) _docker_image debug-fetchmail ;; - fail2ban ) shift 2 ; _docker_container fail2ban "${@}" ;; + fail2ban ) shift 2 ; _docker_container fail2ban "${@:+$@}" ;; show-mail-logs ) _docker_container cat /var/log/mail/mail.log ;; inspect ) _inspect ;; login ) @@ -404,7 +400,7 @@ function _main then _docker_container /bin/bash else - _docker_container /bin/bash -c "${@}" + _docker_container /bin/bash -c "${@:+$@}" fi ;; * ) _usage ; exit 1 ;; @@ -416,4 +412,4 @@ function _main esac } -_main "${@}" +_main "${@:+$@}"