Parcourir la source

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 <joshhsoj1902@gmail.com>
Daniel Gibbs il y a 5 ans
Parent
commit
d7b4ac6b46

+ 4 - 1
lgsm/config-default/config-lgsm/mcserver/_default.cfg

@@ -16,8 +16,11 @@ fn_parms(){
 parms="nogui"
 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"
 branch="release"
+# Version (latest|1.16)
+mcversion="latest"
 
 
 #### LinuxGSM Settings ####
 #### LinuxGSM Settings ####
 
 

+ 20 - 45
lgsm/functions/update_minecraft.sh

@@ -7,14 +7,12 @@
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
 
 fn_update_minecraft_dl(){
 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"
 	echo -e "copying to ${serverfiles}...\c"
 	cp "${tmpdir}/minecraft_server.${remotebuild}.jar" "${serverfiles}/minecraft_server.jar"
 	cp "${tmpdir}/minecraft_server.${remotebuild}.jar" "${serverfiles}/minecraft_server.jar"
 	local exitcode=$?
 	local exitcode=$?
@@ -34,53 +32,30 @@ fn_update_minecraft_dl(){
 fn_update_minecraft_localbuild(){
 fn_update_minecraft_localbuild(){
 	# Gets local build info.
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
 	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_print_ok "Checking local build: ${remotelocation}"
 		fn_script_log_pass "Checking local build"
 		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
 	fi
 }
 }
 
 
 fn_update_minecraft_remotebuild(){
 fn_update_minecraft_remotebuild(){
 	# Gets remote build info.
 	# 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')
 		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
 	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
 	fi
 
 
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 	if [ "${firstcommandname}" != "INSTALL" ]; then