Skip to content

Commit

Permalink
feat: Support authorization header for server download to avoid GitHu…
Browse files Browse the repository at this point in the history
…b ratelimits
  • Loading branch information
0ffz committed Oct 18, 2024
1 parent 456e9d8 commit 376b45a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/dev/download_server
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
set -e
# set -e

PREFIX="[Init]"
if [ "$CUSTOM_SERVER_REPO" ]; then
Expand All @@ -8,17 +8,21 @@ if [ "$CUSTOM_SERVER_REPO" ]; then

echo "$PREFIX Checking for server updates from $CUSTOM_SERVER_REPO"

[ "$KEEPUP_GITHUB_AUTH_TOKEN" ] && AUTHORIZATION="--header 'authorization: Bearer $KEEPUP_GITHUB_AUTH_TOKEN'" || AUTHORIZATION=""

GITHUB_API="https://api.github.com/repos/$CUSTOM_SERVER_REPO/releases/$CUSTOM_SERVER_TAG"
LATEST_RELEASE_DATE=$(curl -s "$GITHUB_API" --header "authorization: Bearer $KEEPUP_GITHUB_AUTH_TOKEN" | jq -r '.published_at' 2>/dev/null)
GITHUB_RESPONSE=$(curl $AUTHORIZATION -s "$GITHUB_API")

LATEST_RELEASE_DATE=$(echo $GITHUB_RESPONSE | jq -r '.published_at' 2>/dev/null)
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 "$GITHUB_API" | jq -r '.assets[] | select(.name | contains ("jar")) | .browser_download_url')\
-q --show-progress -O "$CUSTOM_SERVER"
wget $(echo $GITHUB_RESPONSE | jq -r '.assets[] | select(.name | contains ("jar")) | .browser_download_url')\
-q -O "$CUSTOM_SERVER"

setfattr -n user.release-date -v "$LATEST_RELEASE_DATE" "$CUSTOM_SERVER"
chmod +x "$CUSTOM_SERVER"
Expand Down

0 comments on commit 376b45a

Please sign in to comment.