From 57a840b06906725aeca6ecc8725cc22274878be1 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 3 Feb 2019 09:49:59 -0600 Subject: [PATCH] mc: added debug-ability to vanilla server downloading --- minecraft-server/start-deployVanilla | 34 +++++++++++++++++++++++++++- minecraft-server/start-utils | 14 ++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/minecraft-server/start-deployVanilla b/minecraft-server/start-deployVanilla index 64571af2..1a6ffe2a 100755 --- a/minecraft-server/start-deployVanilla +++ b/minecraft-server/start-deployVanilla @@ -1,10 +1,42 @@ #!/bin/bash +. /start-utils +set -o pipefail + export SERVER="minecraft_server.$VANILLA_VERSION.jar" if [ ! -e $SERVER ]; then echo "Downloading $SERVER ..." - curl -sSL -o $SERVER $(curl -s $(curl -s 'https://launchermeta.mojang.com/mc/game/version_manifest.json' | jq --arg VANILLA_VERSION "$VANILLA_VERSION" --raw-output '[.versions[]|select(.id == $VANILLA_VERSION)][0].url') | jq --raw-output '.downloads.server.url') + debug "Finding version manifest for $VANILLA_VERSION" + versionManifestUrl=$(curl -fsSL 'https://launchermeta.mojang.com/mc/game/version_manifest.json' | jq --arg VANILLA_VERSION "$VANILLA_VERSION" --raw-output '[.versions[]|select(.id == $VANILLA_VERSION)][0].url') + result=$? + if [ $result != 0 ]; then + echo "ERROR failed to obtain version manifest URL ($result)" + exit 1 + fi + if [ $versionManifestUrl = "null" ]; then + echo "ERROR couldn't find a matching manifest entry for $VANILLA_VERSION" + exit 1 + fi + debug "Found version manifest at $versionManifestUrl" + + serverDownloadUrl=$(curl -fsSL ${versionManifestUrl} | jq --raw-output '.downloads.server.url') + result=$? + if [ $result != 0 ]; then + echo "ERROR failed to obtain version manifest from $versionManifestUrl ($result)" + exit 1 + fi + + debug "Downloading server from $serverDownloadUrl" + if isDebugging; then + verbose=-v + fi + curl $verbose -fsSL -o $SERVER $serverDownloadUrl + result=$? + if [ $result != 0 ]; then + echo "ERROR failed to download server from $serverDownloadUrl ($result)" + exit 1 + fi fi # Continue to Final Setup diff --git a/minecraft-server/start-utils b/minecraft-server/start-utils index 78de1c76..151cf05a 100644 --- a/minecraft-server/start-utils +++ b/minecraft-server/start-utils @@ -25,4 +25,18 @@ function isTrue { esac return ${result} +} + +function isDebugging { + if [ ${DEBUG^^} = TRUE ]; then + return 0 + else + return 1 + fi +} + +function debug { + if isDebugging; then + echo "DEBUG: $*" + fi } \ No newline at end of file