]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Getting upstream version and download URL.
authorFrank Brehm <frank@brehm-online.com>
Sun, 18 Apr 2021 17:24:29 +0000 (19:24 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 18 Apr 2021 17:24:29 +0000 (19:24 +0200)
bin/update-minecraft-server-jar

index 2264825a7b8e363d20e95f10a17639ca8aafd487..08f6879366865cc2f008fecb9fa41c07529d4658 100755 (executable)
@@ -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
 
 }