From d7b4ac6b46169368ea0568bc0e7e636a1094bf23 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 28 Nov 2020 22:17:47 +0000 Subject: [PATCH] feat(mcserver): select Minecraft release or snapshot (#3114) Select either release or snapshot branch. Also, have the option to select either latest or specific release/snapshot. A new more efficient way to get the local release that extracts the jar file and parses json file with version number Co-authored-by: Josh Bryans --- .../config-lgsm/mcserver/_default.cfg | 5 +- lgsm/functions/update_minecraft.sh | 65 ++++++------------- 2 files changed, 24 insertions(+), 46 deletions(-) diff --git a/lgsm/config-default/config-lgsm/mcserver/_default.cfg b/lgsm/config-default/config-lgsm/mcserver/_default.cfg index 92f25294c..b78195e3e 100644 --- a/lgsm/config-default/config-lgsm/mcserver/_default.cfg +++ b/lgsm/config-default/config-lgsm/mcserver/_default.cfg @@ -16,8 +16,11 @@ fn_parms(){ parms="nogui" } -## Branch, "snapshot" include snapshot and pre-release versions. | (release|snapshot) +## Release Settings | https://docs.linuxgsm.com/game-servers/minecraft#release-settings +# Branch (release|snapshot) branch="release" +# Version (latest|1.16) +mcversion="latest" #### LinuxGSM Settings #### diff --git a/lgsm/functions/update_minecraft.sh b/lgsm/functions/update_minecraft.sh index 98889ed64..e33840f3e 100755 --- a/lgsm/functions/update_minecraft.sh +++ b/lgsm/functions/update_minecraft.sh @@ -7,14 +7,12 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" fn_update_minecraft_dl(){ - if [ "${branch}" == "release" ]; then - latestmcreleaselink=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.latest.release as $latest | .versions[] | select(.id == $latest) | .url') - else - latestmcreleaselink=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.versions[0].url') - fi + # Generate link to version manifest json. + remotebuildlink=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r --arg branch ${branch} --arg mcversion ${remotebuild} '.versions | .[] | select(.type==$branch and .id==$mcversion) | .url') + # Generate link to server.jar + remotebuildurl=$(curl -s "${remotebuildlink}" | jq -r '.downloads.server.url') - latestmcbuildurl=$(curl -s "${latestmcreleaselink}" | jq -r '.downloads.server.url') - fn_fetch_file "${latestmcbuildurl}" "" "" "" "${tmpdir}" "minecraft_server.${remotebuild}.jar" "" "norun" "noforce" "nomd5" + fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "minecraft_server.${remotebuild}.jar" "" "norun" "noforce" "nomd5" echo -e "copying to ${serverfiles}...\c" cp "${tmpdir}/minecraft_server.${remotebuild}.jar" "${serverfiles}/minecraft_server.jar" local exitcode=$? @@ -34,53 +32,30 @@ fn_update_minecraft_dl(){ fn_update_minecraft_localbuild(){ # Gets local build info. fn_print_dots "Checking local build: ${remotelocation}" - # Uses log file to gather info. - localbuild=$(grep -i version "${consolelogdir}"/* | tail -1 | sed 's/.*[Vv]ersion //' | sed 's/\r//g' 2>/dev/null) - if [ -z "${localbuild}" ]; then - fn_print_error "Checking local build: ${remotelocation}" - fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info" - fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart" - fn_script_log_error "No log files containing version info" - fn_script_log_info "Forcing server restart" - exitbypass=1 - command_stop.sh - fn_firstcommand_reset - exitbypass=1 - command_start.sh - fn_firstcommand_reset - totalseconds=0 - localbuild=$(grep -i version "${consolelogdir}"/* | tail -1 | sed 's/.*[Vv]ersion //' | sed 's/\r//g' 2>/dev/null) - while [ -z "${localbuild}" ]; do - sleep 1 - fn_print_info "Checking local build: ${remotelocation}: waiting for log file: ${totalseconds}" - if [ -v "${loopignore}" ]; then - loopignore=1 - fn_script_log_info "Waiting for log file to generate" - fi - - localbuild=$(grep -i version "${consolelogdir}"/* | tail -1 | sed 's/.*[Vv]ersion //' | sed 's/\r//g' 2>/dev/null) - if [ "${totalseconds}" -gt "120" ]; then - localbuild="0" - fn_print_error "Checking local build: ${remotelocation}: waiting for log file" - fn_script_log_error "Local build did not generate" - fn_script_log_error "Required log file may be missing" - fn_script_log_error "Local build set to 0" - fi - totalseconds=$((totalseconds + 1)) - done - fi - if [ "${localbuild}" != "0" ]; then + # Uses executable to find local build. + cd "${executabledir}" || exit + if [ -f "minecraft_server.jar" ]; then + localbuild=$(unzip -p "minecraft_server.jar" version.json | jq -r '.id') fn_print_ok "Checking local build: ${remotelocation}" fn_script_log_pass "Checking local build" + else + localbuild="0" + fn_print_error "Checking local build: ${remotelocation}" + fn_script_log_error "Checking local build" fi } fn_update_minecraft_remotebuild(){ # Gets remote build info. - if [ "${branch}" == "release" ]; then + # Latest release. + if [ "${branch}" == "release" ] && [ "${mcversion}" == "latest" ]; then remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.latest.release') + # Latest snapshot. + elif [ "${branch}" == "snapshot" ] && [ "${mcversion}" == "latest" ]; then + remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.latest.snapshot') + # Specific release/snapshot. else - remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.versions[0].id') + remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r --arg branch ${branch} --arg mcversion ${mcversion} '.versions | .[] | select(.type==$branch and .id==$mcversion) | .id') fi if [ "${firstcommandname}" != "INSTALL" ]; then