VERSION_MANIFEST='https://launchermeta.mojang.com/mc/game/version_manifest.json'
-CURRENT_VERSION=
+CURRENT_VERSION="<unknown>"
UPSTREAM_VERSION=
DOWNLOAD_URL=
+SHA1_SUM=
TARGET_JAR=
DESCRIPTION=$( cat <<-EOF
check_for_root
- local -a tools=('curl' 'jq')
+ local -a tools=('curl' 'jq' 'sha1sum')
local tool=
local folder=
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."
+ local release_manifest_url=$( echo "${upstream_manifest}" | jq -r --arg VERSION_TARGET "${snapshot}" '.versions | .[] | select(.id==$VERSION_TARGET) | .url' - )
+ if [[ -z "${release_manifest_url}" ]] ; then
+ error "Could not evaluate release manifest URL of snapshot id '${CYAN}${snapshot}${NORMAL}' from manifest."
exit 7
fi
+ debug "Release manifest URL: '${CYAN}${release_manifest_url}${NORMAL}'."
+
+ local release_manifest=$( curl -s "${release_manifest_url}" )
+ if [[ -z "${release_manifest}" ]] ; then
+ error "Did not get a valid release manifest from '${CYAN}${release_manifest_url}${NORMAL}'."
+ exit 8
+ fi
+
+ DOWNLOAD_URL=$( echo "${release_manifest}" | jq -r .downloads.server.url )
+ if [[ -z "${DOWNLOAD_URL}" ]] ; then
+ error "Could not evaluate download URL from release manifest."
+ exit 9
+ fi
debug "Download URL: '${CYAN}${DOWNLOAD_URL}${NORMAL}'."
+
+ SHA1_SUM=$( echo "${release_manifest}" | jq -r .downloads.server.sha1 )
+ if [[ -z "${SHA1_SUM}" ]] ; then
+ error "Could not evaluate SHA1 sum of jar file from release manifest."
+ exit 9
+ fi
+ debug "SHA1 sum of jar file: '${CYAN}${SHA1_SUM}${NORMAL}'."
+
TARGET_JAR="minecraft_server.${UPSTREAM_VERSION}.jar"
+ debug "Target jar file: '${CYAN}${TARGET_JAR}${NORMAL}'."
}
}
+#------------------------------------------------------------------------------
+check_sha1() {
+
+ info "Checking SHA1 sum integrety of '${CYAN}${TARGET_JAR}${NORMAL}' ..."
+
+ local cur_sha1sum=$( sha1sum "${TARGET_JAR}" | awk '{print $1}' )
+ debug "SHA1 sum of current file: '${cur_sha1sum}'."
+
+ if [[ "${cur_sha1sum}" != "${SHA1_SUM}" ]] ; then
+ error "SHA1 sums of local jar file and upstream are not matching."
+ return 10
+ fi
+ debug "SHA1 sums of local jar file and upstream are matching."
+ return 0
+
+}
+
#------------------------------------------------------------------------------
main() {
check_preferences
detecting_cur_version
get_upstream_info
+ if [[ -f "${TARGET_JAR}" ]] ; then
+ check_sha1
+ fi
if [[ "${UPSTREAM_VERSION}" == "${CURRENT_VERSION}" ]] ; then
info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update."
exit 0
fi
do_download
+ check_sha1
}