diff --git a/Dockerfile b/Dockerfile index 720ccd5..412924b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN wget -nv -q -O keepup.zip https://github.com/MineInAbyss/Keepup/releases/dow FROM itzg/minecraft-server:java21-graalvm as minecraft LABEL org.opencontainers.image.authors="Offz " -RUN dnf install -y ansible-core rclone wget unzip jq openssh +RUN dnf install -y ansible-core rclone wget unzip jq openssh attr COPY --from=helper /keepup /usr/local ENV\ KEEPUP=true\ diff --git a/scripts/dev/download_server b/scripts/dev/download_server index 97f6efb..9aee6a4 100644 --- a/scripts/dev/download_server +++ b/scripts/dev/download_server @@ -1,10 +1,26 @@ #!/bin/sh set -e -if [ "$CUSTOM_SERVER_URL" ]; then - if [ ! "$CUSTOM_SERVER" ]; then - export CUSTOM_SERVER=server.jar +PREFIX="[Download Server]" +if [ "$CUSTOM_SERVER_REPO" ]; then + [ ! "$CUSTOM_SERVER" ] && export CUSTOM_SERVER=./server.jar + + echo "$PREFIX Checking for server updates from $CUSTOM_SERVER_REPO" + + export LATEST_RELEASE_DATE=$(curl -s "https://api.github.com/repos/$CUSTOM_SERVER_REPO/releases/latest" | jq -r '.published_at' 2>/dev/null) + export CURRENT_RELEASE_DATE=$(getfattr --only-values -n user.release-date "$CUSTOM_SERVER" 2>/dev/null) + + echo "$PREFIX Latest release date: $LATEST_RELEASE_DATE" + echo "$PREFIX Current release date: $CURRENT_RELEASE_DATE" + + if [ "$LATEST_RELEASE_DATE" != "$CURRENT_RELEASE_DATE" ]; then + echo "$PREFIX Downloading new release, release date: $LATEST_RELEASE_DATE" + wget $(curl -s https://api.github.com/repos/$CUSTOM_SERVER_REPO/releases/latest | jq -r '.assets[] | select(.name | contains ("jar")) | .browser_download_url')\ + -q --show-progress -O "$CUSTOM_SERVER" + + setfattr -n user.release-date -v "$LATEST_RELEASE_DATE" "$CUSTOM_SERVER" + chmod +x "$CUSTOM_SERVER" + else + echo "$PREFIX Server is up to date" fi - echo "Checking for server updates from $CUSTOM_SERVER_URL" - wget -N -q --show-progress "$CUSTOM_SERVER_URL" -c --output-document="$CUSTOM_SERVER" fi