2021-05-19 19:18:06 +00:00
|
|
|
#! /bin/bash
|
|
|
|
|
2022-03-26 09:17:08 +00:00
|
|
|
# shellcheck source=./helpers/log.sh
|
|
|
|
source /usr/local/bin/helpers/log.sh
|
2021-05-19 19:18:06 +00:00
|
|
|
|
2022-03-26 09:17:08 +00:00
|
|
|
VERSION=$(</VERSION)
|
|
|
|
VERSION_URL='https://raw.githubusercontent.com/docker-mailserver/docker-mailserver/master/VERSION'
|
|
|
|
CHANGELOG_URL='https://github.com/docker-mailserver/docker-mailserver/blob/master/CHANGELOG.md'
|
2021-05-19 19:18:06 +00:00
|
|
|
|
|
|
|
# check for correct syntax
|
|
|
|
# number + suffix. suffix must be 's' for seconds, 'm' for minutes, 'h' for hours or 'd' for days.
|
|
|
|
if [[ ! ${UPDATE_CHECK_INTERVAL} =~ ^[0-9]+[smhd]{1}$ ]]
|
|
|
|
then
|
2022-03-26 09:17:08 +00:00
|
|
|
_log_with_date 'warn' "Invalid 'UPDATE_CHECK_INTERVAL' value '${UPDATE_CHECK_INTERVAL}'"
|
|
|
|
_log_with_date 'warn' 'Falling back to daily update checks'
|
|
|
|
UPDATE_CHECK_INTERVAL='1d'
|
2021-05-19 19:18:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
# get remote version information
|
|
|
|
LATEST=$(curl -Lsf "${VERSION_URL}")
|
|
|
|
|
|
|
|
# did we get a valid response?
|
|
|
|
if [[ ${LATEST} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
|
|
|
then
|
2022-03-26 09:17:08 +00:00
|
|
|
_log_with_date 'debug' 'Remote version information fetched'
|
2021-05-19 19:18:06 +00:00
|
|
|
|
|
|
|
# compare versions
|
|
|
|
if dpkg --compare-versions "${VERSION}" lt "${LATEST}"
|
|
|
|
then
|
|
|
|
# send mail notification to postmaster
|
|
|
|
read -r -d '' MAIL << EOM
|
|
|
|
Hello ${POSTMASTER_ADDRESS}!
|
|
|
|
|
|
|
|
There is a docker-mailserver update available on your host: $(hostname -f)
|
|
|
|
|
|
|
|
Current version: ${VERSION}
|
|
|
|
Latest version: ${LATEST}
|
|
|
|
|
2022-03-26 09:17:08 +00:00
|
|
|
Changelog: ${CHANGELOG_URL}
|
2021-05-19 19:18:06 +00:00
|
|
|
EOM
|
|
|
|
|
2022-03-26 09:17:08 +00:00
|
|
|
_log_with_date 'info' "Update available [ ${VERSION} --> ${LATEST} ]"
|
2021-05-19 19:18:06 +00:00
|
|
|
|
|
|
|
# only notify once
|
2022-03-26 09:17:08 +00:00
|
|
|
echo "${MAIL}" | mail -s "Mailserver update available! [ ${VERSION} --> ${LATEST} ]" "${POSTMASTER_ADDRESS}" && exit 0
|
2021-05-19 19:18:06 +00:00
|
|
|
else
|
2022-03-26 09:17:08 +00:00
|
|
|
_log_with_date 'info' 'No update available'
|
2021-05-19 19:18:06 +00:00
|
|
|
fi
|
|
|
|
else
|
2022-03-26 09:17:08 +00:00
|
|
|
_log_with_date 'warn' 'Update check failed'
|
2021-05-19 19:18:06 +00:00
|
|
|
fi
|
2022-03-26 09:17:08 +00:00
|
|
|
|
|
|
|
# check again in 'UPDATE_CHECK_INTERVAL' time
|
2021-05-19 19:18:06 +00:00
|
|
|
sleep "${UPDATE_CHECK_INTERVAL}"
|
|
|
|
done
|