diff --git a/scripts/check-update.sh b/scripts/check-update.sh index a85727ab9728ec414f95da0deb801e41a73f6917..f90dc5f357bcfd48c10ddf29284df504c2977633 100755 --- a/scripts/check-update.sh +++ b/scripts/check-update.sh @@ -3,26 +3,24 @@ set -e source /mnt/repo-base/scripts/base.sh -KNOWN_VERSION_FILE="/mnt/repo-base/config/latest-known-version" -# TODO: delete this once config folder is included in the repo -mkdir /mnt/repo-base/config/ || true -touch $KNOWN_VERSION_FILE +# This file stores the latest tag that we have seen in the repo. It is used +# to ensure that we dont send out multiple emails for the same update. +KNOWN_VERSION_FILE="/mnt/repo-base/config-dynamic/updater/latest-known-version" + +# Create file and populate with current version on first run. +if [ ! -f $KNOWN_VERSION_FILE ]; then + mkdir -p "/mnt/repo-base/config-dynamic/updater/" + git tag --sort=creatordate | tail -n 1 > $KNOWN_VERSION_FILE +fi -CURRENT_VERSION_DATE=$(git show -s --format=%ci HEAD) git fetch --tags LATEST_TAG=$(git tag --sort=creatordate | tail -n 1) -LATEST_VERSION_DATE=$(git show -s --format=%ci "$LATEST_TAG") -if [[ "$LATEST_VERSION_DATE" > "$CURRENT_VERSION_DATE" ]] -then +echo "Current version: $(git describe), latest tag: $LATEST_TAG" +if [ "$LATEST_TAG" != "$(cat $KNOWN_VERSION_FILE)" ]; then echo "New version $LATEST_TAG is available!" - if [ "$LATEST_TAG" != "$(cat $KNOWN_VERSION_FILE)" ] - then - echo "$LATEST_TAG" > "$KNOWN_VERSION_FILE" - cat "templates/mail/update-notification.txt" | \ - sed "s/@@@DOMAIN@@@/$DOMAIN/g" | \ - docker-compose exec -T eelomailserver sendmail -f "drive@$DOMAIN" -t "$ALT_EMAIL" - fi -else - echo "No update available" + echo $LATEST_TAG > $KNOWN_VERSION_FILE + cat "templates/mail/update-notification.txt" | \ + sed "s/@@@VERSION@@@/$LATEST_TAG/g" | \ + docker-compose exec -T eelomailserver sendmail -f "drive@$DOMAIN" -t "$ALT_EMAIL" fi diff --git a/templates/mail/update-notification.txt b/templates/mail/update-notification.txt index 04d42f8f2889cfb7d1d08e89166b8480c819a205..f090ce7479eb222402fb54e6d2220725b308aff1 100644 --- a/templates/mail/update-notification.txt +++ b/templates/mail/update-notification.txt @@ -1,5 +1,4 @@ -Subject:Update available for @@@DOMAIN@@@ -A new update is available. Please login via ssh and run the following -command: +Subject:Update available for ecloud selfhosting +Please visit the following link to see the update instructions: -bash /mnt/repo-base/scripts/update.sh +https://gitlab.e.foundation/e/infra/ecloud-selfhosting/-/tags/@@@VERSION@@@