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
No known key found for this signature in database
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
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
@ -13,14 +13,14 @@ cd /tmp/docker-mailserver || exit 1
# check postfix-accounts.cf exist else break
if [[ ! -f postfix-accounts.cf ]]
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
fi
# verify checksum file exists; must be prepared by start-mailserver.sh
if [[ ! -f ${CHKSUM_FILE} ]]
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
fi
@ -36,7 +36,7 @@ else
fi
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
while true
@ -48,7 +48,7 @@ do
if ! cmp --silent -- "${CHKSUM_FILE}" "${CHKSUM_FILE}.new"
then
echo "${LOG_DATE} Change detected"
_notify 'inf' "${LOG_DATE} Change detected"
CHANGED=$(grep -Fxvf "${CHKSUM_FILE}" "${CHKSUM_FILE}.new" | sed 's/^[^ ]\+ //')
# Bug alert! This overwrites the alias set by start-mailserver.sh
@ -66,17 +66,18 @@ do
for FILE in ${CHANGED}
do
case ${FILE} in
/etc/letsencrypt/acme.json)
for certdomain in ${SSL_DOMAIN} ${HOSTNAME} ${DOMAINNAME}
case "${FILE}" in
"/etc/letsencrypt/acme.json" )
for CERTDOMAIN in ${SSL_DOMAIN} ${HOSTNAME} ${DOMAINNAME}
do
if _extract_certs_from_acme "${certdomain}"
then
break
fi
_extract_certs_from_acme "${CERTDOMAIN}" && break
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
done
@ -120,7 +121,7 @@ do
then
while read -r LINE
do
if ! echo "${LINE}" | grep -q -e "\s*#"
if ! grep -q -e "\s*#" <<< "${LINE}"
then
echo "${LINE}" >>/etc/postfix/sasl_passwd
fi
@ -212,11 +213,11 @@ s/$/ regexp:\/etc\/postfix\/regexp/
if [[ -f /tmp/vhost.tmp ]]
then
# shellcheck disable=SC2002
cat /tmp/vhost.tmp | sort | uniq >/etc/postfix/vhost && rm /tmp/vhost.tmp
sort < /tmp/vhost.tmp | uniq >/etc/postfix/vhost
rm /tmp/vhost.tmp
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
chown -R 5000:5000 /var/mail
fi
@ -233,3 +234,5 @@ s/$/ regexp:\/etc\/postfix\/regexp/
sleep 1
done
exit 0

View file

@ -110,17 +110,25 @@ export -f _extract_certs_from_acme
function _notify
{
{ [[ -z ${1:-} ]] || [[ -z ${2:-} ]] ; } && return
{ [[ -z ${1:-} ]] || [[ -z ${2:-} ]] ; } && return 0
case ${1} in
tasklog ) echo "-e${3:-}" "[ \e[0;92mTASKLOG\e[0m ] ${2}" ;; # light green
warn ) echo "-e${3:-}" "[ \e[0;93mWARNING\e[0m ] ${2}" ;; # light yellow
err ) echo "-e${3:-}" "[ \e[0;31mERROR\e[0m ] ${2}" ;; # light red
fatal ) echo "-e${3:-}" "[ \e[0;91mFATAL\e[0m ] ${2}" ;; # red
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
* ) ;;
local RESET LGREEN LYELLOW LRED RED LBLUE LGREY LMAGENTA
RESET='\e[0m' ; LGREEN='\e[92m' ; LYELLOW='\e[93m'
LRED='\e[31m' ; RED='\e[91m' ; LBLUE='\e[34m'
LGREY='\e[37m' ; LMAGENTA='\e[95m'
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
return 0
}
export -f _notify

View file

@ -37,7 +37,7 @@ function setup_file() {
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
-v "${PRIVATE_CONFIG}/acme.json":/etc/letsencrypt/acme.json: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_DOMAIN=*.example.com" \
-h mail.my-domain.com -t "${NAME}"