#!/bin/bash
# A quick and dirty script to fetch the latest stable minecraft_server.jar
-# URL https://s3.amazonaws.com/Minecraft.Download/versions/1.9.2/minecraft_server.1.9.2.jar
-BASE_URL="https://s3.amazonaws.com/Minecraft.Download/versions"
VERSION_URL="https://launchermeta.mojang.com/mc/game/version_manifest.json"
-LATEST_VER=$(wget -qO - ${VERSION_URL} | python -m json.tool | grep "\"release\":" | cut -d '"' -f 4)
+LATEST_VER=$(wget -qO - "${VERSION_URL}" | jq -r .latest.release)
# Our CURRENT_VER is stored in current_ver and we don't need no stinking error messages
+
source current_ver > /dev/null 2>&1
-if [ ! ${CURRENT_VER:-1} = ${LATEST_VER} ] || [ ! -f minecraft_server.jar ]; then
- wget -q ${BASE_URL}/${LATEST_VER}/minecraft_server.${LATEST_VER}.jar -O minecraft_server.jar && \
- echo "CURRENT_VER=${LATEST_VER}" > current_ver
+# Check if we need a new minecraft_server.jar
+if [ ! "${CURRENT_VER:-1}" = "${LATEST_VER}" ] || [ ! -f minecraft_server.jar ]; then
+ LATEST_MANIFEST=$(wget -qO - "${VERSION_URL}" | jq -r --arg VERSION_TARGET "${LATEST_VER}" '.versions | .[] | select(.id==$VERSION_TARGET) | .url')
+ LATEST_SERVER_URL=$(wget -qO - "${LATEST_MANIFEST}" | jq -r .downloads.server.url)
+ wget -q "${LATEST_SERVER_URL}" -O minecraft_server.jar && echo "CURRENT_VER=${LATEST_VER}" > current_ver
fi