1
1
Fork 0
mirror of https://github.com/docker-mailserver/docker-mailserver synced 2024-05-13 11:36:04 +02:00
docker-mailserver/target/scripts/update-check.sh

54 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/bash
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
# shellcheck source=./helpers/log.sh
source /usr/local/bin/helpers/log.sh
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01: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'
# 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 09:06:59 +02:00
if [[ ! ${UPDATE_CHECK_INTERVAL} =~ ^[0-9]+[smhd]{1}$ ]]; then
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01: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'
fi
2023-05-26 01:39:39 +02:00
while true; do
# get remote version information
LATEST=$(curl -Lsf "${VERSION_URL}")
# did we get a valid response?
2023-05-24 09:06:59 +02:00
if [[ ${LATEST} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
_log_with_date 'debug' 'Remote version information fetched'
# compare versions
2023-05-24 09:06:59 +02:00
if dpkg --compare-versions "${VERSION}" lt "${LATEST}"; then
# send mail notification to postmaster
feature: provide better rspamd suppport (#3016) * added options to toggle OpenDKIM & OpenDMARC rspamd can provide DKIM signing and DMARC checking itself, so users should be able to disable OpenDKIM & OpenDMARC. The default is left at 1, so users have to to opt-in when the want to disable the features. * misc small enhancements * adjusted start of rspamd The order of starting redis + rspamd was reversed (now correct) and rspamd now starts with the correct user. * adjusted rspamd core configuration The main configuration was revised. This includes AV configuration as well as worker/proxy/controller configuration used to control the main rspamd processes. The configuration is not tested extensively, but well enough that I am confident to go forward with it until we declare rspamd support as stable. * update & improve the documentation * add tests These are some initial tests which test the most basic functionality. * tests(refactor): Improve consistency and documentation for test helpers (#3012) * added `ALWAYS_RUN` target `Makefile` recipies (#3013) This ensures the recipies are always run. Co-authored-by: georglauterbach <44545919+georglauterbach@users.noreply.github.com> * adjusted rspamd test to refactored test helper functions * improve documentation * apply suggestions from code review (no. 1 by @polarthene) Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com> * streamline heredoc (EOM -> EOF) * adjust rspamd test (remove unnecessary run arguments) Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2023-01-25 10:28:59 +01:00
read -r -d '' MAIL << EOF
Hello ${POSTMASTER_ADDRESS}!
There is a docker-mailserver update available on your host: $(hostname -f)
Current version: ${VERSION}
Latest version: ${LATEST}
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
Changelog: ${CHANGELOG_URL}
feature: provide better rspamd suppport (#3016) * added options to toggle OpenDKIM & OpenDMARC rspamd can provide DKIM signing and DMARC checking itself, so users should be able to disable OpenDKIM & OpenDMARC. The default is left at 1, so users have to to opt-in when the want to disable the features. * misc small enhancements * adjusted start of rspamd The order of starting redis + rspamd was reversed (now correct) and rspamd now starts with the correct user. * adjusted rspamd core configuration The main configuration was revised. This includes AV configuration as well as worker/proxy/controller configuration used to control the main rspamd processes. The configuration is not tested extensively, but well enough that I am confident to go forward with it until we declare rspamd support as stable. * update & improve the documentation * add tests These are some initial tests which test the most basic functionality. * tests(refactor): Improve consistency and documentation for test helpers (#3012) * added `ALWAYS_RUN` target `Makefile` recipies (#3013) This ensures the recipies are always run. Co-authored-by: georglauterbach <44545919+georglauterbach@users.noreply.github.com> * adjusted rspamd test to refactored test helper functions * improve documentation * apply suggestions from code review (no. 1 by @polarthene) Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com> * streamline heredoc (EOM -> EOF) * adjust rspamd test (remove unnecessary run arguments) Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2023-01-25 10:28:59 +01:00
EOF
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
_log_with_date 'info' "Update available [ ${VERSION} --> ${LATEST} ]"
# only notify once
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
echo "${MAIL}" | mail -s "Mailserver update available! [ ${VERSION} --> ${LATEST} ]" "${POSTMASTER_ADDRESS}" && exit 0
else
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
_log_with_date 'info' 'No update available'
fi
else
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
_log_with_date 'warn' 'Update check failed'
fi
scripts: refactoring & miscellaneous small changes (#2499) * `update-check.sh` now uses the new log * refactored `setup-stack.sh` The changes are: 1. Replaced `""` wiht `''` where possible (reasoning: Bash is very implicit and I'd like to use `''` where possible to indicate no variables are expanded here) 2. `> /file` -> `>/file` according to our style guide 3. Some log adjustments for messages where I deemed it appropriate 4. Then, an error message from a Dovecot setup was also prevented (by adding a check whether the directory is present before a `: >...` command would create a file in this directory). These are all small, miscellaneous changes that I wanted to combine into one commit and ultimately one PR because I see no point in opening a PR for every small change here. I hope this is fine. * added a small `sleep` to the `_shutdown` function This ensure the last log message is actually logged before Supervisor logs the message that it received a SIGTERM. This makes reading the log easier because now the causal relationship is shown (we are terminating Supervisor, and not someone else and we're just logging it). I forgot to replace `""` with `''` in `update-check.sh`, so I included it here because this is the last commit before PR review. * re-add exit on successful update (only) * re-added date information to update-check log messages * added `_log_with_date` function The new function will log a message with a proper timestamp. This is all handled in `log.sh`, we therefore not need to source other files too. This will be used in the future by `check-for-changes.sh` as well :) Co-authored-by: Casper <casperklein@users.noreply.github.com> Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
2022-03-26 10:17:08 +01:00
# check again in 'UPDATE_CHECK_INTERVAL' time
sleep "${UPDATE_CHECK_INTERVAL}"
done