1
1
Fork 0
mirror of https://github.com/docker-mailserver/docker-mailserver synced 2024-05-05 20:16:05 +02:00

revamping the notify function (#1836)

This commit is contained in:
Georg Lauterbach 2021-02-24 17:28:59 +01:00 committed by GitHub
parent 1ef66fd5c5
commit 0fa5c1ef9d
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 27 deletions

View File

@ -4,7 +4,7 @@
. /usr/local/bin/helper-functions.sh . /usr/local/bin/helper-functions.sh
LOG_DATE=$(date +"%Y-%m-%d %H:%M:%S ") LOG_DATE=$(date +"%Y-%m-%d %H:%M:%S ")
echo "${LOG_DATE} Start check-for-changes script." _notify 'task' "${LOG_DATE} Start check-for-changes script."
# ? Checks # ? Checks
@ -13,14 +13,14 @@ cd /tmp/docker-mailserver || exit 1
# check postfix-accounts.cf exist else break # check postfix-accounts.cf exist else break
if [[ ! -f postfix-accounts.cf ]] if [[ ! -f postfix-accounts.cf ]]
then then
echo "${LOG_DATE} postfix-accounts.cf is missing! This should not run! Exit!" _notify 'inf' "${LOG_DATE} postfix-accounts.cf is missing! This should not run! Exit!"
exit 0 exit 0
fi fi
# verify checksum file exists; must be prepared by start-mailserver.sh # verify checksum file exists; must be prepared by start-mailserver.sh
if [[ ! -f ${CHKSUM_FILE} ]] if [[ ! -f ${CHKSUM_FILE} ]]
then then
echo "${LOG_DATE} ${CHKSUM_FILE} is missing! Start script failed? Exit!" _notify 'err' "${LOG_DATE} ${CHKSUM_FILE} is missing! Start script failed? Exit!"
exit 0 exit 0
fi fi
@ -36,7 +36,7 @@ else
fi fi
PM_ADDRESS="${POSTMASTER_ADDRESS:=postmaster@${DOMAINNAME}}" PM_ADDRESS="${POSTMASTER_ADDRESS:=postmaster@${DOMAINNAME}}"
echo "${LOG_DATE} Using postmaster address ${PM_ADDRESS}" _notify 'inf' "${LOG_DATE} Using postmaster address ${PM_ADDRESS}"
sleep 10 sleep 10
while true while true
@ -48,7 +48,7 @@ do
if ! cmp --silent -- "${CHKSUM_FILE}" "${CHKSUM_FILE}.new" if ! cmp --silent -- "${CHKSUM_FILE}" "${CHKSUM_FILE}.new"
then then
echo "${LOG_DATE} Change detected" _notify 'inf' "${LOG_DATE} Change detected"
CHANGED=$(grep -Fxvf "${CHKSUM_FILE}" "${CHKSUM_FILE}.new" | sed 's/^[^ ]\+ //') CHANGED=$(grep -Fxvf "${CHKSUM_FILE}" "${CHKSUM_FILE}.new" | sed 's/^[^ ]\+ //')
# Bug alert! This overwrites the alias set by start-mailserver.sh # Bug alert! This overwrites the alias set by start-mailserver.sh
@ -66,17 +66,18 @@ do
for FILE in ${CHANGED} for FILE in ${CHANGED}
do do
case ${FILE} in case "${FILE}" in
/etc/letsencrypt/acme.json) "/etc/letsencrypt/acme.json" )
for certdomain in ${SSL_DOMAIN} ${HOSTNAME} ${DOMAINNAME} for CERTDOMAIN in ${SSL_DOMAIN} ${HOSTNAME} ${DOMAINNAME}
do do
if _extract_certs_from_acme "${certdomain}" _extract_certs_from_acme "${CERTDOMAIN}" && break
then
break
fi
done done
;; ;;
* ) _notify 'warn' 'file not found for certificate in check_for_changes.sh' ;;
* )
_notify 'warn' 'File not found for certificate in check_for_changes.sh'
;;
esac esac
done done
@ -120,7 +121,7 @@ do
then then
while read -r LINE while read -r LINE
do do
if ! echo "${LINE}" | grep -q -e "\s*#" if ! grep -q -e "\s*#" <<< "${LINE}"
then then
echo "${LINE}" >>/etc/postfix/sasl_passwd echo "${LINE}" >>/etc/postfix/sasl_passwd
fi fi
@ -212,11 +213,11 @@ s/$/ regexp:\/etc\/postfix\/regexp/
if [[ -f /tmp/vhost.tmp ]] if [[ -f /tmp/vhost.tmp ]]
then then
# shellcheck disable=SC2002 sort < /tmp/vhost.tmp | uniq >/etc/postfix/vhost
cat /tmp/vhost.tmp | sort | uniq >/etc/postfix/vhost && rm /tmp/vhost.tmp rm /tmp/vhost.tmp
fi fi
if [[ $(find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .) -ne 0 ]] if find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | read -r
then then
chown -R 5000:5000 /var/mail chown -R 5000:5000 /var/mail
fi fi
@ -233,3 +234,5 @@ s/$/ regexp:\/etc\/postfix\/regexp/
sleep 1 sleep 1
done done
exit 0

View File

@ -110,17 +110,25 @@ export -f _extract_certs_from_acme
function _notify function _notify
{ {
{ [[ -z ${1:-} ]] || [[ -z ${2:-} ]] ; } && return { [[ -z ${1:-} ]] || [[ -z ${2:-} ]] ; } && return 0
case ${1} in local RESET LGREEN LYELLOW LRED RED LBLUE LGREY LMAGENTA
tasklog ) echo "-e${3:-}" "[ \e[0;92mTASKLOG\e[0m ] ${2}" ;; # light green
warn ) echo "-e${3:-}" "[ \e[0;93mWARNING\e[0m ] ${2}" ;; # light yellow RESET='\e[0m' ; LGREEN='\e[92m' ; LYELLOW='\e[93m'
err ) echo "-e${3:-}" "[ \e[0;31mERROR\e[0m ] ${2}" ;; # light red LRED='\e[31m' ; RED='\e[91m' ; LBLUE='\e[34m'
fatal ) echo "-e${3:-}" "[ \e[0;91mFATAL\e[0m ] ${2}" ;; # red LGREY='\e[37m' ; LMAGENTA='\e[95m'
inf ) [[ ${DMS_DEBUG} -eq 1 ]] && echo "-e${3:-}" "[[ \e[0;34mINF\e[0m ]] ${2}" ;; # light blue
task ) [[ ${DMS_DEBUG} -eq 1 ]] && echo "-e${3:-}" "[[ \e[0;37mTASKS\e[0m ]] ${2}" ;; # light grey case "${1}" in
* ) ;; 'tasklog' ) echo "-e${3:-}" "[ ${LGREEN}TASKLOG${RESET} ] ${2}" ;;
'warn' ) echo "-e${3:-}" "[ ${LYELLOW}WARNING${RESET} ] ${2}" ;;
'err' ) echo "-e${3:-}" "[ ${LRED}ERROR${RESET} ] ${2}" ;;
'fatal' ) echo "-e${3:-}" "[ ${RED}FATAL${RESET} ] ${2}" ;;
'inf' ) [[ ${DMS_DEBUG} -eq 1 ]] && echo "-e${3:-}" "[[ ${LBLUE}INF${RESET} ]] ${2}" ;;
'task' ) [[ ${DMS_DEBUG} -eq 1 ]] && echo "-e${3:-}" "[[ ${LGREY}TASKS${RESET} ]] ${2}" ;;
* ) echo "-e${3:-}" "[ ${LMAGENTA}UNKNOWN${RESET} ] ${2}" ;;
esac esac
return 0
} }
export -f _notify export -f _notify

View File

@ -37,7 +37,7 @@ function setup_file() {
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "${PRIVATE_CONFIG}/acme.json":/etc/letsencrypt/acme.json:ro \ -v "${PRIVATE_CONFIG}/acme.json":/etc/letsencrypt/acme.json:ro \
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
-e DMS_DEBUG=0 \ -e DMS_DEBUG=1 \
-e SSL_TYPE=letsencrypt \ -e SSL_TYPE=letsencrypt \
-e "SSL_DOMAIN=*.example.com" \ -e "SSL_DOMAIN=*.example.com" \
-h mail.my-domain.com -t "${NAME}" -h mail.my-domain.com -t "${NAME}"