From 0897858b1d2dc4697971f7703a051bbf1e78dfeb Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 18 Apr 2021 19:24:29 +0200 Subject: [PATCH] Getting upstream version and download URL. --- bin/update-minecraft-server-jar | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bin/update-minecraft-server-jar b/bin/update-minecraft-server-jar index 2264825..08f6879 100755 --- a/bin/update-minecraft-server-jar +++ b/bin/update-minecraft-server-jar @@ -28,6 +28,7 @@ VERSION_MANIFEST='https://launchermeta.mojang.com/mc/game/version_manifest.json' CURRENT_VERSION= UPSTREAM_VERSION= +DOWNLOAD_URL= DESCRIPTION=$( cat <<-EOF Update Micraft server .jar file. @@ -149,6 +150,40 @@ detecting_cur_version() { } +#------------------------------------------------------------------------------ +get_upstream_info() { + + info "Trying to get info about current upstream version." + + local upstream_manifest=$( curl -s "${VERSION_MANIFEST}" ) + if [[ -z "${upstream_manifest}" ]] ; then + error "Did not get a valid manifest from mohjang.com" + exit 6 + fi + + UPSTREAM_VERSION=$( echo "${upstream_manifest}" | jq -r .latest.release ) + if [[ -z "${UPSTREAM_VERSION}" ]] ; then + error "Could not evaluate current version from manifest." + exit 7 + fi + info "Latest released version: '${GREEN}${UPSTREAM_VERSION}${NORMAL}'." + + local snapshot=$( echo "${upstream_manifest}" | jq -r .latest.snapshot ) + if [[ -z "${snapshot}" ]] ; then + error "Could not evaluate current snapshot id from manifest." + exit 7 + fi + debug "Current snapshot id: '${CYAN}${snapshot}${NORMAL}'." + + DOWNLOAD_URL=$( echo "${upstream_manifest}" | jq -r --arg VERSION_TARGET "${snapshot}" '.versions | .[] | select(.id==$VERSION_TARGET) | .url' - ) + if [[ -z "${DOWNLOAD_URL=}" ]] ; then + error "Could not evaluate download URL of snapshot id '${CYAN}${snapshot}${NORMAL}' from manifest." + exit 7 + fi + debug "Download URL: '${CYAN}${DOWNLOAD_URL}${NORMAL}'." + +} + #------------------------------------------------------------------------------ main() { @@ -157,6 +192,11 @@ main() { check_preferences detecting_cur_version + get_upstream_info + if [[ "${UPSTREAM_VERSION}" == "${CURRENT_VERSION}" ]] ; then + info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update." + exit 0 + fi } -- 2.39.5