2022-10-17 08:40:09 +00:00
|
|
|
#!/bin/bash
|
2021-05-19 19:18:06 +00:00
|
|
|
|
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
|
|
|
|
2023-11-29 21:21:26 +00:00
|
|
|
VERSION="${DMS_RELEASE#v}"
|
|
|
|
VERSION_URL='https://github.com/docker-mailserver/docker-mailserver/releases/latest'
|
2022-03-26 09:17:08 +00:00
|
|
|
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.
|
2023-05-24 07:06:59 +00:00
|
|
|
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
|
|
|
|
|
2023-05-25 23:39:39 +00:00
|
|
|
while true; do
|
2021-05-19 19:18:06 +00:00
|
|
|
# get remote version information
|
2023-11-29 21:21:26 +00:00
|
|
|
# JSON response provides a field for the release tag, the `v` prefix is removed with `[1:]`
|
|
|
|
LATEST=$(curl -sfL -H 'accept: application/json' "${VERSION_URL}" | jaq -r '.tag_name[1:]')
|
2021-05-19 19:18:06 +00:00
|
|
|
|
|
|
|
# did we get a valid response?
|
2023-05-24 07:06:59 +00:00
|
|
|
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
|
2023-05-24 07:06:59 +00:00
|
|
|
if dpkg --compare-versions "${VERSION}" lt "${LATEST}"; then
|
2021-05-19 19:18:06 +00:00
|
|
|
# send mail notification to postmaster
|
2023-01-25 09:28:59 +00:00
|
|
|
read -r -d '' MAIL << EOF
|
2021-05-19 19:18:06 +00:00
|
|
|
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}
|
2023-01-25 09:28:59 +00:00
|
|
|
EOF
|
2021-05-19 19:18:06 +00:00
|
|
|
|
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
|