From 4e1c56a66129cc3b6d6a246f880836cfdbcece8e Mon Sep 17 00:00:00 2001 From: Bensuperpc Date: Tue, 14 Jun 2022 00:39:19 +0200 Subject: [PATCH] Add custom download URL for Purpur Add custom download URL for Purpur Signed-off-by: Bensuperpc --- README.md | 1 + scripts/start-deployPurpur | 56 +++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 37e7630d7a9..dc9e5d93669 100644 --- a/README.md +++ b/README.md @@ -460,6 +460,7 @@ Extra variables: - `PURPUR_BUILD=LATEST` : set a specific Purpur build to use - `FORCE_REDOWNLOAD=false` : set to true to force the located server jar to be re-downloaded - `USE_FLARE_FLAGS=false` : set to true to add appropriate flags for the built-in [Flare](https://blog.airplane.gg/flare) profiler +- `PURPUR_DOWNLOAD_URL=` : set URL to download Purpur from custom URL. ### Running a Magma server diff --git a/scripts/start-deployPurpur b/scripts/start-deployPurpur index 499253b1fdb..162da6c125c 100755 --- a/scripts/start-deployPurpur +++ b/scripts/start-deployPurpur @@ -6,33 +6,45 @@ IFS=$'\n\t' . "${SCRIPTS:-/}start-utils" isDebugging && set -x -: "${VANILLA_VERSION:?}" -: "${PURPUR_BUILD:=LATEST}" -: "${FORCE_REDOWNLOAD:=false}" - -if [[ ${PURPUR_BUILD} == LATEST ]]; then - if ! PURPUR_BUILD=$(get --json-path=".builds.latest" "https://api.purpurmc.org/v2/purpur/${VANILLA_VERSION}"); then - log "ERROR: Failed to locate a Purpur build for ${VANILLA_VERSION}." - log " Please check if a download is available at https://purpur.pl3x.net/downloads/" - exit 1 +if [[ $PURPUR_DOWNLOAD_URL ]]; then + export SERVER=$(getFilenameFromUrl "${PURPUR_DOWNLOAD_URL}") + + if [ -f "$SERVER" ]; then + zarg=(-z "$SERVER") fi -fi -export SERVER="purpur-${VANILLA_VERSION}-${PURPUR_BUILD}.jar" + echo "Preparing custom Purpur jar from $PURPUR_DOWNLOAD_URL" -log "Removing old Purpur versions ..." -shopt -s nullglob -for f in purpur-*.jar; do - [[ $f != "$SERVER" ]] && rm "$f" -done + curl -fsSL -o "$SERVER" "${zarg[@]}" "${PURPUR_DOWNLOAD_URL}" +else + : "${VANILLA_VERSION:?}" + : "${PURPUR_BUILD:=LATEST}" + : "${FORCE_REDOWNLOAD:=false}" -if [ ! -f "$SERVER" ] || isTrue "$FORCE_REDOWNLOAD"; then - downloadUrl="https://api.purpurmc.org/v2/purpur/${VANILLA_VERSION}/${PURPUR_BUILD}/download" - log "Downloading Purpur from $downloadUrl ..." - if ! get -o "$SERVER" "$downloadUrl"; then - log "ERROR: failed to download from $downloadUrl (status=$?)" - exit 3 + if [[ ${PURPUR_BUILD} == LATEST ]]; then + if ! PURPUR_BUILD=$(get --json-path=".builds.latest" "https://api.purpurmc.org/v2/purpur/${VANILLA_VERSION}"); then + log "ERROR: Failed to locate a Purpur build for ${VANILLA_VERSION}." + log " Please check if a download is available at https://purpur.pl3x.net/downloads/" + exit 1 fi + fi + + export SERVER="purpur-${VANILLA_VERSION}-${PURPUR_BUILD}.jar" + + log "Removing old Purpur versions ..." + shopt -s nullglob + for f in purpur-*.jar; do + [[ $f != "$SERVER" ]] && rm "$f" + done + + if [ ! -f "$SERVER" ] || isTrue "$FORCE_REDOWNLOAD"; then + downloadUrl="https://api.purpurmc.org/v2/purpur/${VANILLA_VERSION}/${PURPUR_BUILD}/download" + log "Downloading Purpur from $downloadUrl ..." + if ! get -o "$SERVER" "$downloadUrl"; then + log "ERROR: failed to download from $downloadUrl (status=$?)" + exit 3 + fi + fi fi # Normalize on Spigot for later operations