Sfoglia il codice sorgente

feat: update refactor (#4146)

* feat(ut99): add oldunreal update functionality

* non-steam update refactor

* chore: flipping exit code if statements

Must have consistancy XD

* rename variables

* feat(ut99): now supports native x64

* extracts will now fail if files doesnt exist

* localbuild fix

* a

* fix: exit code bug

* improve progress bar

* add extractsrc and extractdest to deal with specific dir extracts

* update ts3 extract

* update

* paper REFACTOR

* mta


a

* fix(mta): prevent default resources exit from installer

* streamline mcserver

* mcb

* jk2

* fixes

* correct directory extract for factorio

* mcb remove non printable characters

* codacy
Daniel Gibbs 3 anni fa
parent
commit
e86848c41c

+ 1 - 1
lgsm/config-default/config-lgsm/ut99server/_default.cfg

@@ -145,7 +145,7 @@ glibc="2.1"
 # Edit with care
 
 ## Game Server Directories
-systemdir="${serverfiles}/System"
+systemdir="${serverfiles}/System64"
 executabledir="${systemdir}"
 executable="./ucc-bin"
 servercfgdir="${systemdir}"

+ 2 - 2
lgsm/functions/alert.sh

@@ -60,7 +60,7 @@ fn_alert_update() {
 	alertemoji="🎮"
 	alertsound="1"
 	alerturl="not enabled"
-	alertbody="${gamename} received update"
+	alertbody="${gamename} received update: ${remotebuildversion}"
 }
 
 fn_alert_check_update() {
@@ -69,7 +69,7 @@ fn_alert_check_update() {
 	alertemoji="🎮"
 	alertsound="1"
 	alerturl="not enabled"
-	alertbody="${gamename} update available"
+	alertbody="${gamename} update available: ${remotebuildversion}"
 }
 
 fn_alert_permissions() {

+ 6 - 5
lgsm/functions/command_backup.sh

@@ -99,16 +99,17 @@ fn_backup_migrate_olddir() {
 			fn_script_log_info "${rootdir}/backups > ${backupdir}"
 			mv "${rootdir}/backups/"* "${backupdir}" 2> /dev/null
 			exitcode=$?
-			if [ "${exitcode}" -eq 0 ]; then
+			if [ "${exitcode}" == 0 ]; then
 				rmdir "${rootdir}/backups" 2> /dev/null
 				exitcode=$?
 			fi
-			if [ "${exitcode}" -eq 0 ]; then
-				fn_print_ok_nl "Backup directory is being migrated"
-				fn_script_log_pass "Backup directory is being migrated"
-			else
+			if [ "${exitcode}" != 0 ]; then
 				fn_print_error_nl "Backup directory is being migrated"
 				fn_script_log_error "Backup directory is being migrated"
+			else
+
+				fn_print_ok_nl "Backup directory is being migrated"
+				fn_script_log_pass "Backup directory is being migrated"
 			fi
 		fi
 	fi

+ 19 - 9
lgsm/functions/command_check_update.sh

@@ -14,16 +14,26 @@ fn_print_dots ""
 check.sh
 core_logs.sh
 
-if [ "${appid}" ]; then
-	core_steamcmd.sh
-
-	check_steamcmd.sh
-
-	fn_update_steamcmd_localbuild
-	fn_update_steamcmd_remotebuild
-	fn_update_steamcmd_compare
-elif [ "${shortname}" == "ts3" ]; then
+if [ "${shortname}" == "ts3" ]; then
 	update_ts3.sh
+elif [ "${shortname}" == "mc" ]; then
+	update_minecraft.sh
+elif [ "${shortname}" == "mcb" ]; then
+	update_minecraft_bedrock.sh
+elif [ "${shortname}" == "pmc" ] || [ "${shortname}" == "vpmc" ] || [ "${shortname}" == "wmc" ]; then
+	update_papermc.sh
+elif [ "${shortname}" == "fctr" ]; then
+	update_factorio.sh
+elif [ "${shortname}" == "mta" ]; then
+	update_mta.sh
+elif [ "${shortname}" == "jk2" ]; then
+	update_jediknight2.sh
+elif [ "${shortname}" == "vints" ]; then
+	update_vintagestory.sh
+elif [ "${shortname}" == "ut99" ]; then
+	update_ut99.sh
+else
+	update_steamcmd.sh
 fi
 
 core_exit.sh

+ 1 - 3
lgsm/functions/command_install_resources_mta.sh

@@ -12,7 +12,7 @@ fn_firstcommand_set
 
 fn_install_resources() {
 	echo -e ""
-	echo -e "Installing Default Resources"
+	echo -e "${lightyellow}Installing Default Resources${default}"
 	echo -e "================================="
 	fn_fetch_file "http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip" "" "" "" "${tmpdir}" "mtasa-resources-latest.zip" "nochmodx" "norun" "noforce" "nohash"
 	fn_dl_extract "${tmpdir}" "mtasa-resources-latest.zip" "${resourcesdir}"
@@ -30,5 +30,3 @@ else
 	fn_print_warning_nl "Default resources are not installed when using ./${selfname} auto-install."
 	fn_print_information_nl "To install default resources use ./${selfname} install"
 fi
-
-core_exit.sh

+ 2 - 2
lgsm/functions/command_mods_update.sh

@@ -27,8 +27,8 @@ fn_remove_cfg_files() {
 			filetopreserve=$(echo -e "${modkeepfiles}" | awk -F ';' -v x=${preservefilesindex} '{ print $x }')
 			echo -e "	* serverfiles/${filetopreserve}"
 			# If it matches an existing file that have been extracted delete the file.
-			if [ -f "${extractdir}/${filetopreserve}" ] || [ -d "${extractdir}/${filetopreserve}" ]; then
-				rm -r "${extractdir:?}/${filetopreserve}"
+			if [ -f "${extractdest}/${filetopreserve}" ] || [ -d "${extractdest}/${filetopreserve}" ]; then
+				rm -r "${extractdest:?}/${filetopreserve}"
 				# Write the file path in a tmp file, to rebuild a full file list as it is rebuilt upon update.
 				if [ ! -f "${modsdir}/.removedfiles.tmp" ]; then
 					touch "${modsdir}/.removedfiles.tmp"

+ 2 - 0
lgsm/functions/command_update.sh

@@ -31,6 +31,8 @@ elif [ "${shortname}" == "jk2" ]; then
 	update_jediknight2.sh
 elif [ "${shortname}" == "vints" ]; then
 	update_vintagestory.sh
+elif [ "${shortname}" == "ut99" ]; then
+	update_ut99.sh
 else
 	update_steamcmd.sh
 fi

+ 53 - 29
lgsm/functions/core_dl.sh

@@ -14,8 +14,8 @@
 # hash: Optional, set an hash sum and will compare it against the file.
 #
 # Downloads can be defined in code like so:
-# fn_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
-# fn_fetch_file "http://example.com/file.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"
+# fn_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${hash}"
+# fn_fetch_file "http://example.com/file.tar.bz2" "http://example.com/file2.tar.bz2" "file.tar.bz2" "file2.tar.bz2" "/some/dir" "file.tar.bz2" "chmodx" "run" "forcedl" "10cd7353aa9d758a075c600a6dd193fd"
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
@@ -124,7 +124,7 @@ fn_dl_steamcmd() {
 				echo -en "Please provide content log to LinuxGSM developers https://linuxgsm.com/steamcmd-error"
 				fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Unknown error occured"
 			fi
-		elif [ "${exitcode}" != "0" ]; then
+		elif [ "${exitcode}" != 0 ]; then
 			fn_print_error2_nl "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
 			fn_script_log_error "${commandaction} ${selfname}: ${remotelocation}: Exit code: ${exitcode}"
 		else
@@ -146,12 +146,12 @@ fn_clear_tmp() {
 	if [ -d "${tmpdir}" ]; then
 		rm -rf "${tmpdir:?}/"*
 		local exitcode=$?
-		if [ "${exitcode}" == 0 ]; then
-			fn_print_ok_eol_nl
-			fn_script_log_pass "clearing LinuxGSM tmp directory"
-		else
+		if [ "${exitcode}" != 0 ]; then
 			fn_print_error_eol_nl
 			fn_script_log_error "clearing LinuxGSM tmp directory"
+		else
+			fn_print_ok_eol_nl
+			fn_script_log_pass "clearing LinuxGSM tmp directory"
 		fi
 	fi
 }
@@ -202,31 +202,56 @@ fn_dl_hash() {
 
 # Extracts bzip2, gzip or zip files.
 # Extracts can be defined in code like so:
-# fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdir}"
+# fn_dl_extract "${local_filedir}" "${local_filename}" "${extractdest}" "${extractsrc}"
 # fn_dl_extract "/home/gameserver/lgsm/tmp" "file.tar.bz2" "/home/gamserver/serverfiles"
 fn_dl_extract() {
 	local_filedir="${1}"
 	local_filename="${2}"
-	extractdir="${3}"
+	extractdest="${3}"
+	extractsrc="${4}"
 	# Extracts archives.
 	echo -en "extracting ${local_filename}..."
-	mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
-	if [ ! -d "${extractdir}" ]; then
-		mkdir "${extractdir}"
+
+	if [ ! -d "${extractdest}" ]; then
+		mkdir "${extractdest}"
+	fi
+	if [ ! -f "${local_filedir}/${local_filename}" ]; then
+		fn_print_fail_eol_nl
+		echo -en "file ${local_filedir}/${local_filename} not found"
+		fn_script_log_fatal "Extracting ${local_filename}"
+		fn_script_log_fatal "File ${local_filedir}/${local_filename} not found"
+		core_exit.sh
 	fi
+	mime=$(file -b --mime-type "${local_filedir}/${local_filename}")
 	if [ "${mime}" == "application/gzip" ] || [ "${mime}" == "application/x-gzip" ]; then
-		extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdir}")
+		if [ -n "${extractsrc}" ]; then
+			extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
+		else
+			extractcmd=$(tar -zxf "${local_filedir}/${local_filename}" -C "${extractdest}")
+		fi
 	elif [ "${mime}" == "application/x-bzip2" ]; then
-		extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdir}")
+		if [ -n "${extractsrc}" ]; then
+			extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
+		else
+			extractcmd=$(tar -jxf "${local_filedir}/${local_filename}" -C "${extractdest}")
+		fi
 	elif [ "${mime}" == "application/x-xz" ]; then
-		extractcmd=$(tar -xf "${local_filedir}/${local_filename}" -C "${extractdir}")
+		if [ -n "${extractsrc}" ]; then
+			extractcmd=$(tar -Jxf "${local_filedir}/${local_filename}" -C "${extractdest}" --strip-components=1 "${extractsrc}")
+		else
+			extractcmd=$(tar -Jxf "${local_filedir}/${local_filename}" -C "${extractdest}")
+		fi
 	elif [ "${mime}" == "application/zip" ]; then
-		extractcmd=$(unzip -qo -d "${extractdir}" "${local_filedir}/${local_filename}")
+		if [ -n "${extractsrc}" ]; then
+			extractcmd=$(unzip -qoj -d "${extractdest}" "${local_filedir}/${local_filename}" "${extractsrc}"/*)
+		else
+			extractcmd=$(unzip -qo -d "${extractdest}" "${local_filedir}/${local_filename}")
+		fi
 	fi
 	local exitcode=$?
 	if [ "${exitcode}" != 0 ]; then
 		fn_print_fail_eol_nl
-		fn_script_log_fatal "Extracting download"
+		fn_script_log_fatal "Extracting ${local_filename}"
 		if [ -f "${lgsmlog}" ]; then
 			echo -e "${extractcmd}" >> "${lgsmlog}"
 		fi
@@ -234,7 +259,7 @@ fn_dl_extract() {
 		core_exit.sh
 	else
 		fn_print_ok_eol_nl
-		fn_script_log_pass "Extracting download"
+		fn_script_log_pass "Extracting ${local_filename}"
 	fi
 }
 
@@ -360,21 +385,21 @@ fn_fetch_file() {
 			trap fn_fetch_trap INT
 			# Larger files show a progress bar.
 			if [ "${local_filename##*.}" == "bz2" ] || [ "${local_filename##*.}" == "gz" ] || [ "${local_filename##*.}" == "zip" ] || [ "${local_filename##*.}" == "jar" ] || [ "${local_filename##*.}" == "xz" ]; then
-				echo -en "downloading ${local_filename}..."
+				echo -e "downloading ${local_filename}..."
 				fn_sleep_time
-				echo -en "\033[1K"
 				curlcmd=$(curl --connect-timeout 10 --progress-bar --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
+				local exitcode=$?
 				echo -en "downloading ${local_filename}..."
 			else
+				curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}")
+				local exitcode=$?
 				echo -en "fetching ${fileurl_name} ${local_filename}...\c"
-				curlcmd=$(curl --connect-timeout 10 -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}" 2>&1)
 			fi
-			local exitcode=$?
 
 			# Download will fail if downloads a html file.
 			if [ -f "${local_filedir}/${local_filename}" ]; then
-				if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE")" ]; then
-					rm -f "${local_filedir:?}/${local_filename:?}"
+				if head -n 1 "${local_filedir}/${local_filename}" | grep -q "DOCTYPE"; then
+					rm "${local_filedir:?}/${local_filename:?}"
 					local exitcode=2
 				fi
 			fi
@@ -384,22 +409,21 @@ fn_fetch_file() {
 				if [ ${counter} -ge 2 ]; then
 					fn_print_fail_eol_nl
 					if [ -f "${lgsmlog}" ]; then
-						fn_script_log_fatal "Downloading ${local_filename}"
+						fn_script_log_fatal "Downloading ${local_filename}..."
 						fn_script_log_fatal "${fileurl}"
 					fi
 					core_exit.sh
 				else
 					fn_print_error_eol_nl
 					if [ -f "${lgsmlog}" ]; then
-						fn_script_log_error "Downloading ${local_filename}"
+						fn_script_log_error "Downloading ${local_filename}..."
 						fn_script_log_error "${fileurl}"
 					fi
 				fi
 			else
-				fn_print_ok_eol
-				echo -en "\033[2K\\r"
+				fn_print_ok_eol_nl
 				if [ -f "${lgsmlog}" ]; then
-					fn_script_log_pass "Downloading ${local_filename}"
+					fn_script_log_pass "Downloading ${local_filename}..."
 				fi
 
 				# Make file executable if chmodx is set.

+ 1 - 1
lgsm/functions/core_exit.sh

@@ -25,7 +25,7 @@ fi
 
 if [ "${exitbypass}" ]; then
 	unset exitbypass
-elif [ "${exitcode}" ] && [ "${exitcode}" != "0" ]; then
+elif [ "${exitcode}" != "0" ]; then
 	# List LinuxGSM version in logs
 	fn_script_log_info "LinuxGSM version: ${version}"
 	if [ "${exitcode}" == "1" ]; then

+ 5 - 0
lgsm/functions/core_functions.sh

@@ -680,6 +680,11 @@ update_vintagestory.sh() {
 	fn_fetch_function
 }
 
+update_ut99.sh() {
+	functionfile="${FUNCNAME[0]}"
+	fn_fetch_function
+}
+
 fn_update_functions.sh() {
 	functionfile="${FUNCNAME[0]}"
 	fn_fetch_function

+ 7 - 5
lgsm/functions/core_getopt.sh

@@ -65,8 +65,8 @@ currentopt+=("${cmd_update_linuxgsm[@]}")
 
 # Exclude noupdate games here.
 if [ "${shortname}" == "jk2" ] || [ "${engine}" != "idtech3" ]; then
-	if [ "${shortname}" != "bf1942" ] && [ "${shortname}" != "bfv" ] && [ "${engine}" != "idtech2" ] && [ "${engine}" != "iw2.0" ] && [ "${engine}" != "iw3.0" ] && [ "${engine}" != "quake" ] && [ "${shortname}" != "samp" ] && [ "${shortname}" != "ut2k4" ] && [ "${shortname}" != "ut99" ]; then
-		currentopt+=("${cmd_update[@]}")
+	if [ "${shortname}" != "bf1942" ] && [ "${shortname}" != "bfv" ] && [ "${engine}" != "idtech2" ] && [ "${engine}" != "iw2.0" ] && [ "${engine}" != "iw3.0" ] && [ "${engine}" != "quake" ] && [ "${shortname}" != "samp" ] && [ "${shortname}" != "ut2k4" ]; then
+		currentopt+=("${cmd_update[@]}" "${cmd_check_update[@]}")
 		# force update for SteamCMD or Multi Theft Auto only.
 		if [ "${appid}" ] || [ "${shortname}" == "mta" ]; then
 			currentopt+=("${cmd_force_update[@]}")
@@ -75,8 +75,8 @@ if [ "${shortname}" == "jk2" ] || [ "${engine}" != "idtech3" ]; then
 fi
 
 # Validate and check-update command.
-if [ "${appid}" ] || [ "${shortname}" == "ts3" ]; then
-	currentopt+=("${cmd_validate[@]}" "${cmd_check_update[@]}")
+if [ "${appid}" ]; then
+	currentopt+=("${cmd_validate[@]}")
 fi
 
 # Backup.
@@ -102,10 +102,12 @@ if [ "${shortname}" == "ts3" ]; then
 	currentopt+=("${cmd_change_password[@]}")
 fi
 
-# Unreal exclusive.
+# Rust exclusive.
 if [ "${shortname}" == "rust" ]; then
 	currentopt+=("${cmd_fullwipe[@]}" "${cmd_mapwipe[@]}")
 fi
+
+# Unreal exclusive.
 if [ "${engine}" == "unreal2" ]; then
 	if [ "${shortname}" == "ut2k4" ]; then
 		currentopt+=("${cmd_install_cdkey[@]}" "${cmd_map_compressor_u2[@]}")

+ 16 - 16
lgsm/functions/core_steamcmd.sh

@@ -14,7 +14,7 @@ fn_install_steamcmd() {
 	if [ ! -d "${steamcmddir}" ]; then
 		mkdir -p "${steamcmddir}"
 	fi
-	fn_fetch_file "http://media.steampowered.com/client/steamcmd_linux.tar.gz" "" "" "" "${tmpdir}" "steamcmd_linux.tar.gz" "" "norun" "noforce" "nohash"
+	fn_fetch_file "http://media.steampowered.com/client/steamcmd_linux.tar.gz" "" "" "" "${tmpdir}" "steamcmd_linux.tar.gz" "nochmodx" "norun" "noforce" "nohash"
 	fn_dl_extract "${tmpdir}" "steamcmd_linux.tar.gz" "${steamcmddir}"
 	chmod +x "${steamcmddir}/steamcmd.sh"
 }
@@ -157,9 +157,9 @@ fn_update_steamcmd_localbuild() {
 	fi
 
 	# Checks if localbuild variable has been set.
-	if [ -z "${localbuild}" ] || [ "${localbuild}" == "null" ]; then
-		fn_print_fail "Checking local build: ${remotelocation}"
-		fn_script_log_fatal "Checking local build"
+	if [ -z "${localbuild}" ]; then
+		fn_print_fail "Checking local build: ${remotelocation}: missing local build info"
+		fn_script_log_fatal "Missing local build info"
 		core_exit.sh
 	else
 		fn_print_ok "Checking local build: ${remotelocation}"
@@ -168,7 +168,7 @@ fn_update_steamcmd_localbuild() {
 }
 
 fn_update_steamcmd_remotebuild() {
-	# Gets remote build info.
+	# Get remote build info.
 	if [ -d "${steamcmddir}" ]; then
 		cd "${steamcmddir}" || exit
 	fi
@@ -179,12 +179,12 @@ fn_update_steamcmd_remotebuild() {
 	fi
 
 	# password for branch not needed to check the buildid
-	remotebuild=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed -e '/"branches"/,/^}/!d' | sed -n "/\"${branch}\"/,/}/p" | grep -m 1 buildid | tr -cd '[:digit:]')
+	remotebuildversion=$(${steamcmdcommand} +login "${steamuser}" "${steampass}" +app_info_update 1 +app_info_print "${appid}" +quit | sed -e '/"branches"/,/^}/!d' | sed -n "/\"${branch}\"/,/}/p" | grep -m 1 buildid | tr -cd '[:digit:]')
 
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -194,7 +194,7 @@ fn_update_steamcmd_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -204,12 +204,12 @@ fn_update_steamcmd_remotebuild() {
 
 fn_update_steamcmd_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	if [ "${localbuild}" != "${remotebuild}" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
@@ -220,14 +220,14 @@ fn_update_steamcmd_compare() {
 		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
 		if [ -n "${branch}" ]; then
 			fn_script_log_info "Branch: ${branch}"
 		fi
 		if [ -n "${betapassword}" ]; then
 			fn_script_log_info "Branch password: ${betapassword}"
 		fi
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
 		if [ "${commandname}" == "UPDATE" ]; then
 			unset updateonstart
@@ -246,8 +246,8 @@ fn_update_steamcmd_compare() {
 				exitbypass=1
 				command_start.sh
 				fn_firstcommand_reset
-				unset exitbypass
 			fi
+			unset exitbypass
 			date +%s > "${lockdir}/lastupdate.lock"
 			alert="update"
 		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
@@ -259,7 +259,7 @@ fn_update_steamcmd_compare() {
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
@@ -270,7 +270,7 @@ fn_update_steamcmd_compare() {
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
 		if [ -n "${branch}" ]; then
 			fn_script_log_info "Branch: ${branch}"
 		fi

+ 1 - 1
lgsm/functions/fix.sh

@@ -17,7 +17,7 @@ fn_fix_msg_start() {
 
 fn_fix_msg_start_nl() {
 	fn_print_dots "Applying ${fixname} fix: ${gamename}"
-	fn_print_info "Applying ${fixname} fix: ${gamename}"
+	fn_print_info_nl "Applying ${fixname} fix: ${gamename}"
 	fn_script_log_info "Applying ${fixname} fix: ${gamename}"
 }
 

+ 3 - 3
lgsm/functions/info_game.sh

@@ -2551,10 +2551,10 @@ if [ ! -f "${tmpdir}/extip.txt" ]; then
 	extip="$(curl --connect-timeout 10 -s https://api.ipify.org 2> /dev/null)"
 	exitcode=$?
 	# if curl passes add extip to externalip.txt
-	if [ "${exitcode}" == "0" ]; then
-		echo "${extip}" > "${tmpdir}/extip.txt"
-	else
+	if [ "${exitcode}" != "0" ]; then
 		echo "Unable to get external IP address"
+	else
+		echo "${extip}" > "${tmpdir}/extip.txt"
 	fi
 else
 	extip="$(cat "${tmpdir}/extip.txt")"

+ 0 - 2
lgsm/functions/install_eula.sh

@@ -31,11 +31,9 @@ if [ -z "${autoinstall}" ]; then
 	fi
 elif [ "${commandname}" == "START" ]; then
 	fn_print_info "By continuing you are indicating your agreement to the EULA."
-	echo -e ""
 	sleep 5
 else
 	echo -e "By using auto-install you are indicating your agreement to the EULA."
-	echo -e ""
 	sleep 5
 fi
 

+ 3 - 0
lgsm/functions/install_server_files.sh

@@ -233,6 +233,9 @@ elif [ "${shortname}" == "jk2" ]; then
 	update_jediknight2.sh
 elif [ "${shortname}" == "vints" ]; then
 	update_vintagestory.sh
+elif [ "${shortname}" == "ut99" ]; then
+	fn_install_server_files
+	update_ut99.sh
 elif [ -z "${appid}" ] || [ "${shortname}" == "ahl" ] || [ "${shortname}" == "bb" ] || [ "${shortname}" == "ns" ] || [ "${shortname}" == "sfc" ] || [ "${shortname}" == "ts" ] || [ "${shortname}" == "vs" ] || [ "${shortname}" == "zmr" ]; then
 	if [ "${shortname}" == "ut" ]; then
 		install_eula.sh

+ 5 - 5
lgsm/functions/install_ts3db.sh

@@ -12,13 +12,13 @@ fn_install_ts3db_mariadb() {
 		echo -e "copying libmariadb.so.2...\c"
 		cp "${serverfiles}/redist/libmariadb.so.2" "${serverfiles}"
 		local exitcode=$?
-		if [ "${exitcode}" == "0" ]; then
-			fn_print_ok_eol_nl
-			fn_script_log_pass "copying libmariadb.so.2"
-		else
+		if [ "${exitcode}" != "0" ]; then
 			fn_print_fail_eol_nl
 			fn_script_log_fatal "copying libmariadb.so.2"
 			core_exit.sh
+		else
+			fn_print_ok_eol_nl
+			fn_script_log_pass "copying libmariadb.so.2"
 		fi
 	fi
 
@@ -64,7 +64,7 @@ fi
 install_eula.sh
 
 echo -e ""
-echo -e "${lightyellow}Getting privilege key${default}"
+echo -e "${lightyellow}Getting Privilege Key${default}"
 echo -e "================================="
 fn_sleep_time
 fn_print_information_nl "Save these details for later."

+ 9 - 9
lgsm/functions/mods_core.sh

@@ -10,7 +10,7 @@ functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 # Files and Directories.
 modsdir="${lgsmdir}/mods"
 modstmpdir="${modsdir}/tmp"
-extractdir="${modstmpdir}/extract"
+extractdest="${modstmpdir}/extract"
 modsinstalledlist="installed-mods.txt"
 modsinstalledlistfullpath="${modsdir}/${modsinstalledlist}"
 
@@ -25,10 +25,10 @@ fn_mod_install_files() {
 		fn_script_log_fatal "An issue occurred downloading ${modprettyname}"
 		core_exit.sh
 	fi
-	if [ ! -d "${extractdir}" ]; then
-		mkdir -p "${extractdir}"
+	if [ ! -d "${extractdest}" ]; then
+		mkdir -p "${extractdest}"
 	fi
-	fn_dl_extract "${modstmpdir}" "${modfilename}" "${extractdir}"
+	fn_dl_extract "${modstmpdir}" "${modfilename}" "${extractdest}"
 }
 
 # Convert mod files to lowercase if needed.
@@ -39,9 +39,9 @@ fn_mod_lowercase() {
 		fn_sleep_time
 		fn_script_log_info "Converting ${modprettyname} files to lowercase"
 		# Total files and directories for the mod, to output to the user
-		fileswc=$(find "${extractdir}" | wc -l)
+		fileswc=$(find "${extractdest}" | wc -l)
 		# Total uppercase files and directories for the mod, to output to the user
-		filesupperwc=$(find "${extractdir}" -name '*[[:upper:]]*' | wc -l)
+		filesupperwc=$(find "${extractdest}" -name '*[[:upper:]]*' | wc -l)
 		fn_script_log_info "Found ${filesupperwc} uppercase files out of ${fileswc}, converting"
 		echo -en "Found ${filesupperwc} uppercase files out of ${fileswc}, converting..."
 		# Convert files and directories starting from the deepest to prevent issues (-depth argument)
@@ -63,7 +63,7 @@ fn_mod_lowercase() {
 					core_exit.sh
 				fi
 			fi
-		done < <(find "${extractdir}" -depth -name '*[[:upper:]]*')
+		done < <(find "${extractdest}" -depth -name '*[[:upper:]]*')
 		fn_print_ok_eol_nl
 	fi
 }
@@ -73,7 +73,7 @@ fn_mod_create_filelist() {
 	echo -en "building ${modcommand}-files.txt..."
 	fn_sleep_time
 	# ${modsdir}/${modcommand}-files.txt.
-	find "${extractdir}" -mindepth 1 -printf '%P\n' > "${modsdir}/${modcommand}-files.txt"
+	find "${extractdest}" -mindepth 1 -printf '%P\n' > "${modsdir}/${modcommand}-files.txt"
 	local exitcode=$?
 	if [ "${exitcode}" != 0 ]; then
 		fn_print_fail_eol_nl
@@ -93,7 +93,7 @@ fn_mod_create_filelist() {
 fn_mod_copy_destination() {
 	echo -en "copying ${modprettyname} to ${modinstalldir}..."
 	fn_sleep_time
-	cp -Rf "${extractdir}/." "${modinstalldir}/"
+	cp -Rf "${extractdest}/." "${modinstalldir}/"
 	local exitcode=$?
 	if [ "${exitcode}" != 0 ]; then
 		fn_print_fail_eol_nl

+ 86 - 83
lgsm/functions/update_factorio.sh

@@ -7,47 +7,44 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_factorio_dl() {
-	fn_fetch_file "https://factorio.com/get-download/${downloadbranch}/headless/${factorioarch}" "" "" "" "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuild}.tar.xz" "" "norun" "noforce" "nohash"
-	fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuild}.tar.xz" "${tmpdir}"
-	echo -e "copying to ${serverfiles}...\c"
-	cp -R "${tmpdir}/factorio/"* "${serverfiles}"
-	local exitcode=$?
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Copying to ${serverfiles}"
-		fn_clear_tmp
-	else
-		fn_print_fail_eol_nl
-		fn_script_log_fatal "Copying to ${serverfiles}"
-		core_exit.sh
-		fn_clear_tmp
-	fi
+fn_update_dl() {
+	# Download and extract files to serverfiles
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
+	fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${remotebuildversion}.tar.xz" "${serverfiles}" "factorio"
+	fn_clear_tmp
 }
 
-fn_update_factorio_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses executable to find local build.
-	cd "${executabledir}" || exit
-	if [ -f "${executable}" ]; then
+	# Uses executable to get local build.
+	if [ -d "${exutabledir}" ]; then
+		cd "${executabledir}" || exit
 		localbuild=$(${executable} --version | grep "Version:" | awk '{print $2}')
-		fn_print_ok "Checking for update: ${remotelocation}: checking local build"
-		fn_script_log_pass "Checking local build"
-	else
+	fi
+	if [ -z "${localbuild}" ]; then
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
+		fn_script_log_error "Missing local build info"
+		fn_script_log_error "Set localbuild to 0"
 		localbuild="0"
-		fn_print_error "Checking for update: ${remotelocation}: checking local build"
-		fn_script_log_error "Checking local build"
+	else
+		fn_print_ok "Checking local build: ${remotelocation}"
+		fn_script_log_pass "Checking local build"
 	fi
 }
 
-fn_update_factorio_remotebuild() {
-	# Gets remote build info.
-	remotebuild=$(curl -s "https://factorio.com/get-download/${downloadbranch}/headless/${factorioarch}" | grep -o '[0-9]\.[0-9]\{1,\}\.[0-9]\{1,\}' | head -1)
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://factorio.com/get-download/${branch}/headless/${factorioarch}"
+	remotebuildresponse=$(curl -s "${apiurl}")
+	remotebuildversion=$(echo "${remotebuildresponse}" | grep -o '[0-9]\.[0-9]\{1,\}\.[0-9]\{1,\}' | head -1)
+	remotebuildurl="https://factorio.com/get-download/${branch}/headless/${factorioarch}"
+	remotebuildfilename="factorio_headless_${factorioarch}-${remotebuildversion}.tar.xz"
+
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -57,7 +54,7 @@ fn_update_factorio_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -65,101 +62,107 @@ fn_update_factorio_remotebuild() {
 	fi
 }
 
-fn_update_factorio_compare() {
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	# Removes dots so if statement can compare version numbers.
-	fn_print_dots "Checking for update: ${remotelocation}"
-	localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
-	remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
-	if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild} ${factorioarch}${default}"
-		echo -e "* Remote build: ${green}${remotebuild} ${factorioarch}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion} ${factorioarch}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild} ${factorioarch}"
-		fn_script_log_info "Remote build: ${remotebuild} ${factorioarch}"
-		if [ -v "${branch}" ]; then
+		fn_script_log_info "Remote build: ${remotebuildversion} ${factorioarch}"
+		if [ -n "${branch}" ]; then
 			fn_script_log_info "Branch: ${branch}"
 		fi
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
-		unset updateonstart
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			fn_update_factorio_dl
-			if [ "${requirerestart}" == "1" ]; then
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
 				exitbypass=1
-				command_start.sh
+				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				command_stop.sh
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
 				fn_firstcommand_reset
 			fi
-		# If server started.
-		else
-			fn_print_restart_warning
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-			exitbypass=1
-			fn_update_factorio_dl
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		unset exitbypass
-		date +%s > "${lockdir}/lastupdate.lock"
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild} ${factorioarch}${default}"
-		echo -e "* Remote build: ${green}${remotebuild} ${factorioarch}${default}"
-		if [ -v "${branch}" ]; then
+		echo -e "* Remote build: ${green}${remotebuildversion} ${factorioarch}${default}"
+		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild} ${factorioarch}"
-		fn_script_log_info "Remote build: ${remotebuild} ${factorioarch}"
-		if [ -v "${branch}" ]; then
+		fn_script_log_info "Remote build: ${remotebuildversion} ${factorioarch}"
+		if [ -n "${branch}" ]; then
 			fn_script_log_info "Branch: ${branch}"
 		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
-# The location where the builds are checked and downloaded.
-remotelocation="factorio.com"
-
 # Game server architecture.
 factorioarch="linux64"
 
-if [ "${branch}" == "stable" ]; then
-	downloadbranch="stable"
-elif [ "${branch}" == "experimental" ]; then
-	downloadbranch="latest"
-else
-	downloadbranch="${branch}"
-fi
+# The location where the builds are checked and downloaded.
+remotelocation="factorio.com"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_factorio_remotebuild
-	fn_update_factorio_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_factorio_localbuild
-	fn_update_factorio_remotebuild
-	fn_update_factorio_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 92 - 103
lgsm/functions/update_jediknight2.sh

@@ -3,81 +3,45 @@
 # Author: Daniel Gibbs
 # Contributors: http://linuxgsm.com/contrib
 # Website: https://linuxgsm.com
-# Description: Handles updating of jk2 servers.
+# Description: Handles updating of Jedi Knight 2 servers.
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_jk2_dl() {
-	fn_fetch_file "https://github.com/mvdevs/jk2mv/releases/download/${remotebuild}/jk2mv-v${remotebuild}-dedicated.zip" "" "" "" "${tmpdir}" "jk2mv-${remotebuild}-dedicated.zip" "" "norun" "noforce" "nohash"
-	fn_dl_extract "${tmpdir}" "jk2mv-${remotebuild}-dedicated.zip" "${tmpdir}/jk2mv-v${remotebuild}-dedicated"
-	echo -e "copying to ${serverfiles}...\c"
-	cp -R "${tmpdir}/jk2mv-v${remotebuild}-dedicated/linux-amd64/jk2mvded"* "${serverfiles}/GameData"
-	local exitcode=$?
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Copying to ${serverfiles}"
-		fn_clear_tmp
-	else
-		fn_print_fail_eol_nl
-		fn_script_log_fatal "Copying to ${serverfiles}"
-		core_exit.sh
-	fi
+fn_update_dl() {
+	# Download and extract files to serverfiles
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
+	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}/GameData" "linux-amd64"
+	fn_clear_tmp
 }
 
-fn_update_jk2_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses log file to gather info.
-	# Log is generated and cleared on startup but filled on shutdown.
-	requirerestart=1
-	localbuild=$(grep "\"version\"" "${consolelogdir}"/* 2> /dev/null | sed 's/.*://' | awk '{print $1}' | head -n 1)
-	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"
-
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
-			sleep 3
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-		# If server started.
-		else
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-		fi
-	fi
-
-	if [ -z "${localbuild}" ]; then
-		localbuild=$(grep Version "$(ls -tr "${consolelogdir}"/* 2> /dev/null)" | tail -1 | sed 's/.*Version //')
-	fi
-
+	# Uses log file to get local build.
+	localbuild=$(grep "\"version\"" "${consolelogdir}"/* 2> /dev/null | sed 's/.*://' | awk '{print $1}' | head -n 1 | sed 's/v//')
 	if [ -z "${localbuild}" ]; then
-		localbuild="0"
-		fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info"
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
 		fn_script_log_error "Missing local build info"
 		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
 	else
 		fn_print_ok "Checking local build: ${remotelocation}"
 		fn_script_log_pass "Checking local build"
 	fi
 }
 
-fn_update_jk2_remotebuild() {
-	# Gets remote build info.
-	remotebuild=$(curl -s "https://api.github.com/repos/mvdevs/jk2mv/releases/latest" | grep dedicated.zip | tail -1 | awk -F"/" '{ print $8 }')
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://api.github.com/repos/mvdevs/jk2mv/releases/latest"
+	remotebuildresponse=$(curl -s "${apiurl}")
+	remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("dedicated.zip")) | .name')
+	remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("dedicated.zip")) | .browser_download_url')
+	remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
+
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -87,7 +51,7 @@ fn_update_jk2_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -95,80 +59,105 @@ fn_update_jk2_remotebuild() {
 	fi
 }
 
-fn_update_jk2_compare() {
-	# Removes dots so if statement can compare version numbers.
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
-	remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
-	if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
-		echo -e "* Local build: ${red}${localbuild} ${jk2arch}${default}"
-		echo -e "* Remote build: ${green}${remotebuild} ${jk2arch}${default}"
+		echo -e "* Local build: ${red}${localbuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "Update available"
-		fn_script_log_info "Local build: ${localbuild} ${jk2arch}"
-		fn_script_log_info "Remote build: ${remotebuild} ${jk2arch}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "Local build: ${localbuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
-		unset updateonstart
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			fn_update_jk2_dl
-			if [ "${requirerestart}" == "1" ]; then
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
 				exitbypass=1
-				command_start.sh
+				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				command_stop.sh
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
 				fn_firstcommand_reset
 			fi
-		# If server started.
-		else
-			fn_print_restart_warning
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-			exitbypass=1
-			fn_update_jk2_dl
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		date +%s > "${lockdir}/lastupdate.lock"
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "No update available"
-		echo -e "* Local build: ${green}${localbuild} ${jk2arch}${default}"
-		echo -e "* Remote build: ${green}${remotebuild} ${jk2arch}${default}"
+		echo -e "* Local build: ${green}${localbuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
-		fn_script_log_info "Local build: ${localbuild} ${jk2arch}"
-		fn_script_log_info "Remote build: ${remotebuild} ${jk2arch}"
+		fn_script_log_info "Local build: ${localbuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
 # The location where the builds are checked and downloaded.
-remotelocation="jk2mv.org"
-
-# Game server architecture.
-jk2arch="x64"
+remotelocation="github.com"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_jk2_remotebuild
-	fn_update_jk2_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	update_steamcmd.sh
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_jk2_localbuild
-	fn_update_jk2_remotebuild
-	fn_update_jk2_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 85 - 74
lgsm/functions/update_minecraft.sh

@@ -3,66 +3,57 @@
 # Author: Daniel Gibbs
 # Contributors: http://linuxgsm.com/contrib
 # Website: https://linuxgsm.com
-# Description: Handles updating of Minecraft servers.
+# Description: Handles updating of Minecraft: Java Edition servers.
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_minecraft_dl() {
-	# 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')
-
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "minecraft_server.${remotebuild}.jar" "" "norun" "noforce" "nohash"
-	echo -e "copying to ${serverfiles}...\c"
-	cp "${tmpdir}/minecraft_server.${remotebuild}.jar" "${serverfiles}/minecraft_server.jar"
-	local exitcode=$?
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Copying to ${serverfiles}"
-		chmod u+x "${serverfiles}/minecraft_server.jar"
-		fn_clear_tmp
-	else
-		fn_print_fail_eol_nl
-		fn_script_log_fatal "Copying to ${serverfiles}"
-		fn_clear_tmp
-		core_exit.sh
-	fi
+fn_update_dl() {
+	# Download and extract files to serverfiles
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${serverfiles}" "minecraft_server.jar" "chmodx" "norun" "noforce" "nohash"
 }
 
-fn_update_minecraft_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses executable to find local build.
-	cd "${executabledir}" || exit
-	if [ -f "minecraft_server.jar" ]; then
+	# Uses executable to get local build.
+	if [ -d "${exutabledir}" ]; then
+		cd "${executabledir}" || exit
 		localbuild=$(unzip -p "minecraft_server.jar" version.json | jq -r '.id')
+	fi
+	if [ -z "${localbuild}" ]; then
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
+		fn_script_log_error "Missing local build info"
+		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
+	else
 		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.
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://launchermeta.mojang.com/mc/game/version_manifest.json"
+	remotebuildresponse=$(curl -s "${apiurl}")
 	# Latest release.
 	if [ "${branch}" == "release" ] && [ "${mcversion}" == "latest" ]; then
-		remotebuild=$(curl -s "https://launchermeta.${remotelocation}/mc/game/version_manifest.json" | jq -r '.latest.release')
+		remotebuildversion=$(echo "${remotebuildresponse}" | 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')
+		remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.latest.snapshot')
 	# Specific release/snapshot.
 	else
-		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')
+		remotebuildversion=$(echo "${remotebuildresponse}" | jq -r --arg branch "${branch}" --arg mcversion "${mcversion}" '.versions | .[] | select(.type==$branch and .id==$mcversion) | .id')
 	fi
+	# Generate link to version manifest json.
+	remotebuildmanifest=$(echo "${remotebuildresponse}" | jq -r --arg branch "${branch}" --arg mcversion "${remotebuildversion}" '.versions | .[] | select(.type==$branch and .id==$mcversion) | .url')
+	# Generate link to server.jar
+	remotebuildurl=$(curl -s "${remotebuildmanifest}" | jq -r '.downloads.server.url')
 
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -72,7 +63,7 @@ fn_update_minecraft_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -80,70 +71,90 @@ fn_update_minecraft_remotebuild() {
 	fi
 }
 
-fn_update_minecraft_compare() {
-	# Removes dots so if statement can compare version numbers.
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
-		unset updateonstart
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			fn_update_minecraft_dl
-			if [ "${requirerestart}" == "1" ]; then
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
 				exitbypass=1
-				command_start.sh
+				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				command_stop.sh
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
 				fn_firstcommand_reset
 			fi
-		# If server started.
-		else
-			fn_print_restart_warning
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-			exitbypass=1
-			fn_update_minecraft_dl
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		unset exitbypass
-		date +%s > "${lockdir}/lastupdate.lock"
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
 		if [ -n "${branch}" ]; then
 			fn_script_log_info "Branch: ${branch}"
 		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
@@ -151,13 +162,13 @@ fn_update_minecraft_compare() {
 remotelocation="mojang.com"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_minecraft_remotebuild
-	fn_update_minecraft_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_minecraft_localbuild
-	fn_update_minecraft_remotebuild
-	fn_update_minecraft_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 93 - 96
lgsm/functions/update_minecraft_bedrock.sh

@@ -7,90 +7,60 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-#random number for userAgent
-randnum=$((1 + RANDOM % 5000))
-
-fn_update_minecraft_dl() {
-	fn_fetch_file "https://minecraft.azureedge.net/bin-linux/bedrock-server-${remotebuild}.zip" "" "" "" "${tmpdir}" "bedrock_server.${remotebuild}.zip"
+fn_update_dl() {
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "bedrock_server.${remotebuildversion}.zip"
 	echo -e "Extracting to ${serverfiles}...\c"
 	if [ "${firstcommandname}" == "INSTALL" ]; then
-		unzip -oq "${tmpdir}/bedrock_server.${remotebuild}.zip" -x "server.properties" -d "${serverfiles}"
+		unzip -oq "${tmpdir}/bedrock_server.${remotebuildversion}.zip" -x "server.properties" -d "${serverfiles}"
 	else
-		unzip -oq "${tmpdir}/bedrock_server.${remotebuild}.zip" -x "permissions.json" "server.properties" "allowlist.json" -d "${serverfiles}"
+		unzip -oq "${tmpdir}/bedrock_server.${remotebuildversion}.zip" -x "permissions.json" "server.properties" "allowlist.json" -d "${serverfiles}"
 	fi
 	local exitcode=$?
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Extracting to ${serverfiles}"
-		chmod u+x "${serverfiles}/bedrock_server"
-		fn_clear_tmp
-	else
+	if [ "${exitcode}" != 0 ]; then
 		fn_print_fail_eol_nl
-		fn_script_log_fatal "Extracting to ${serverfiles}"
-		fn_clear_tmp
+		fn_script_log_fatal "Extracting ${local_filename}"
+		if [ -f "${lgsmlog}" ]; then
+			echo -e "${extractcmd}" >> "${lgsmlog}"
+		fi
+		echo -e "${extractcmd}"
 		core_exit.sh
+	else
+		fn_print_ok_eol_nl
+		fn_script_log_pass "Extracting ${local_filename}"
 	fi
 }
 
-fn_update_minecraft_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses log file to gather info.
-	# Log is generated and cleared on startup but filled on shutdown.
-	requirerestart=1
-	localbuild=$(grep Version "${consolelogdir}"/* 2> /dev/null | tail -1 | sed 's/.*Version //')
-	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"
-
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
-			sleep 3
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-		# If server started.
-		else
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-		fi
-	fi
-
-	if [ -z "${localbuild}" ]; then
-		localbuild=$(grep Version "$(ls -tr "${consolelogdir}"/* 2> /dev/null)" | tail -1 | sed 's/.*Version //')
-	fi
-
+	# Uses log file to get local build.
+	localbuild=$(grep Version "${consolelogdir}"/* 2> /dev/null | tail -1 | sed 's/.*Version //' | tr -d '\000-\011\013-\037')
 	if [ -z "${localbuild}" ]; then
-		localbuild="0"
-		fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info"
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
 		fn_script_log_error "Missing local build info"
 		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
 	else
 		fn_print_ok "Checking local build: ${remotelocation}"
 		fn_script_log_pass "Checking local build"
 	fi
 }
 
-fn_update_minecraft_remotebuild() {
-	# Gets remote build info.
+fn_update_remotebuild() {
+	# Random number for userAgent
+	randnum=$((1 + RANDOM % 5000))
+	# Get remote build info.
 	if [ "${mcversion}" == "latest" ]; then
-		remotebuild=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randnum}.212 Safari/537.36" "https://www.minecraft.net/en-us/download/server/bedrock/" | grep -o 'https://minecraft.azureedge.net/bin-linux/[^"]*' | sed 's/.*\///' | grep -Eo "[.0-9]+[0-9]")
+		remotebuildversion=$(curl -H "Accept-Encoding: identity" -H "Accept-Language: en" -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.${randnum}.212 Safari/537.36" "https://www.minecraft.net/en-us/download/server/bedrock/" | grep -o 'https://minecraft.azureedge.net/bin-linux/[^"]*' | sed 's/.*\///' | grep -Eo "[.0-9]+[0-9]")
 	else
-		remotebuild="${mcversion}"
+		remotebuildversion="${mcversion}"
 	fi
+	remotebuildurl="https://minecraft.azureedge.net/bin-linux/bedrock-server-${remotebuildversion}.zip"
 
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -100,7 +70,7 @@ fn_update_minecraft_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -108,63 +78,90 @@ fn_update_minecraft_remotebuild() {
 	fi
 }
 
-fn_update_minecraft_compare() {
-	# Removes dots so if statement can compare version numbers.
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
-	remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
-	if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
-		unset updateonstart
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			fn_update_minecraft_dl
-			if [ "${requirerestart}" == "1" ]; then
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
 				exitbypass=1
-				command_start.sh
+				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				command_stop.sh
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
 				fn_firstcommand_reset
 			fi
-		# If server started.
-		else
-			fn_print_restart_warning
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-			exitbypass=1
-			fn_update_minecraft_dl
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		unset exitbypass
-		date +%s > "${lockdir}/lastupdate.lock"
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
@@ -172,13 +169,13 @@ fn_update_minecraft_compare() {
 remotelocation="minecraft.net"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_minecraft_remotebuild
-	fn_update_minecraft_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_minecraft_localbuild
-	fn_update_minecraft_remotebuild
-	fn_update_minecraft_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 86 - 123
lgsm/functions/update_mta.sh

@@ -7,103 +7,39 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_mta_dl() {
-	fn_fetch_file "http://linux.mtasa.com/dl/multitheftauto_linux_x64.tar.gz" "" "" "" "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "" "norun" "noforce" "nohash"
-	mkdir "${tmpdir}/multitheftauto_linux_x64"
-	fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "${tmpdir}/multitheftauto_linux_x64"
-	echo -e "copying to ${serverfiles}...\c"
-	cp -R "${tmpdir}/multitheftauto_linux_x64/multitheftauto_linux_x64/"* "${serverfiles}"
-	local exitcode=$?
-	fn_clear_tmp
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Copying to ${serverfiles}"
-		chmod u+x "${serverfiles}/mta-server64"
-	else
-		fn_print_fail_eol_nl
-		fn_script_log_fatal "Copying to ${serverfiles}"
-		core_exit.sh
-	fi
+fn_update_dl() {
+	# Download and extract files to tmpdir.
+	fn_fetch_file "http://linux.mtasa.com/dl/multitheftauto_linux_x64.tar.gz" "" "" "" "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "nochmodx" "norun" "force" "nohash"
+	fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64.tar.gz" "${serverfiles}" "multitheftauto_linux_x64"
 }
 
-fn_update_mta_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses log file to gather info.
-	# Gives time for log file to generate.
-	requirerestart=1
-	if [ ! -f "${serverfiles}/mods/deathmatch/logs/server.log" ]; 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
-		exitbypass=1
-		command_start.sh
-		fn_firstcommand_reset
-		totalseconds=0
-		# Check again, allow time to generate logs.
-		while [ ! -f "${serverfiles}/mods/deathmatch/logs/server.log" ]; 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
-
-			if [ "${totalseconds}" -gt "120" ]; then
-				localbuild="0"
-				fn_print_error "Checking local build: ${remotelocation}: waiting for log file: missing log file"
-				fn_script_log_error "Missing log file"
-				fn_script_log_error "Set localbuild to 0"
-			fi
-
-			totalseconds=$((totalseconds + 1))
-		done
-	fi
-
+	# Uses log file to get local build.
+	localbuild=$(grep "= Multi Theft Auto: San Andreas v" "${serverfiles}/mods/deathmatch/logs/server.log" | awk '{ print $7 }' | sed -r 's/^.{1}//' | tail -1)
 	if [ -z "${localbuild}" ]; then
-		localbuild=$(grep "= Multi Theft Auto: San Andreas v" "${serverfiles}/mods/deathmatch/logs/server.log" | awk '{ print $7 }' | sed -r 's/^.{1}//' | tail -1)
-	fi
-
-	if [ -z "${localbuild}" ]; then
-		# Gives time for var to generate.
-		totalseconds=0
-		for seconds in {1..120}; do
-			fn_print_info "Checking local build: ${remotelocation}: waiting for local build: ${totalseconds}"
-			if [ -z "${loopignore}" ]; then
-				loopignore=1
-				fn_script_log_info "Waiting for local build to generate"
-			fi
-			localbuild=$(grep "= Multi Theft Auto: San Andreas v" "${serverfiles}/mods/deathmatch/logs/server.log" | awk '{ print $7 }' | sed -r 's/^.{1}//' | tail -1)
-			if [ "${localbuild}" ]; then
-				break
-			fi
-			sleep 1
-			totalseconds=$((totalseconds + 1))
-		done
-	fi
-
-	if [ -z "${localbuild}" ]; then
-		localbuild="0"
-		fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info"
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
 		fn_script_log_error "Missing local build info"
 		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
 	else
 		fn_print_ok "Checking local build: ${remotelocation}"
 		fn_script_log_pass "Checking local build"
 	fi
 }
 
-fn_update_mta_remotebuild() {
-	# Gets remote build info.
-	remotebuild=$(curl -s "https://api.github.com/repos/multitheftauto/mtasa-blue/releases/latest" | jq -r '.tag_name')
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://api.github.com/repos/multitheftauto/mtasa-blue/releases/latest"
+	remotebuildresponse=$(curl -s "${apiurl}")
+	remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .name')
+	remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .browser_download_url')
+	remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -113,7 +49,7 @@ fn_update_mta_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -121,69 +57,96 @@ fn_update_mta_remotebuild() {
 	fi
 }
 
-fn_update_mta_compare() {
-	# Removes dots so if statement can compare version numbers.
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
-	remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
-	if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then
-		fn_print_ok_nl "Checking for update: ${remotelocation}"
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		if [ "${forceupdate}" == "1" ]; then
 			# forceupdate bypasses checks, useful for small build changes
 			mtaupdatestatus="forced"
 		else
 			mtaupdatestatus="available"
 		fi
+		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
-		echo -e "Update ${mtaupdatestatus}:"
+		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
-		unset updateonstart
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			fn_update_mta_dl
-			if [ "${requirerestart}" == "1" ]; then
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
 				exitbypass=1
-				command_start.sh
+				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				command_stop.sh
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
 				fn_firstcommand_reset
 			fi
-		# If server started.
-		else
-			fn_print_restart_warning
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-			exitbypass=1
-			fn_update_mta_dl
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		unset exitbypass
-		date +%s > "${lockdir}/lastupdate.lock"
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
@@ -191,13 +154,13 @@ fn_update_mta_compare() {
 remotelocation="linux.mtasa.com"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_mta_remotebuild
-	fn_update_mta_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_mta_localbuild
-	fn_update_mta_remotebuild
-	fn_update_mta_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 139 - 108
lgsm/functions/update_papermc.sh

@@ -5,115 +5,167 @@
 # Website: https://linuxgsm.com
 # Description: Handles updating of PaperMC and Waterfall servers.
 
-commandname="UPDATE"
-commandaction="Update"
-function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
+functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_papermc_dl() {
-	# get build info
-	builddata=$(curl -s "https://${remotelocation}/api/v2/projects/${paperproject}/versions/${paperversion}/builds/${remotebuild}" | jq '.downloads')
-	buildname=$(echo -e "${builddata}" | jq -r '.application.name')
-	buildsha256=$(echo -e "${builddata}" | jq -r '.application.sha256')
-
-	fn_fetch_file "https://${remotelocation}/api/v2/projects/${paperproject}/versions/${paperversion}/builds/${remotebuild}/downloads/${buildname}" "" "" "" "${tmpdir}" "${buildname}" "nochmodx" "norun" "force" "${buildsha256}"
-
-	echo -e "copying to ${serverfiles}...\c"
-	cp -f "${tmpdir}/${buildname}" "${serverfiles}/${executable#./}"
-	local exitcode=$?
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Copying to ${serverfiles}"
-		chmod u+x "${serverfiles}/${executable#./}"
-		echo "${remotebuild}" > "${localversionfile}"
-		fn_clear_tmp
-	else
-		fn_print_fail_eol_nl
-		fn_script_log_fatal "Copying to ${serverfiles}"
-		core_exit.sh
-	fi
+fn_update_dl() {
+	# Download and extract files to serverfiles
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${serverfiles}" "${executable#./}" "chmodx" "norun" "force" "${remotebuildhash}"
+	echo "${remotebuildversion}" > "${serverfiles}/build.txt"
 }
 
-fn_update_papermc_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
-	fn_print_dots "Checking for update: ${remotelocation}: checking local build"
-	sleep 0.5
-
-	if [ ! -f "${localversionfile}" ]; then
-		fn_print_error_nl "Checking for update: ${remotelocation}: checking local build: no local build files"
-		fn_script_log_error "No local build file found"
-	else
-		localbuild=$(head -n 1 "${localversionfile}")
-	fi
-
+	fn_print_dots "Checking local build: ${remotelocation}"
+	# Uses version file to get local build.
+	localbuild=$(head -n 1 "${serverfiles}/build.txt")
 	if [ -z "${localbuild}" ]; then
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
+		fn_script_log_error "Missing local build info"
+		fn_script_log_error "Set localbuild to 0"
 		localbuild="0"
-		fn_print_error "Checking for update: ${remotelocation}: waiting for local build: missing local build info"
-		fn_script_log_error "Missing local build info, Set localbuild to 0"
 	else
-		fn_print_ok "Checking for update: ${remotelocation}: checking local build"
+		fn_print_ok "Checking local build: ${remotelocation}"
 		fn_script_log_pass "Checking local build"
 	fi
-	sleep 0.5
 }
 
-fn_update_papermc_remotebuild() {
-	# Gets remote build info.
-	remotebuild=$(curl -s "https://${remotelocation}/api/v2/projects/${paperproject}/versions/${paperversion}" | jq -r '.builds[-1]')
-
-	# Checks if remotebuild variable has been set.
-	if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
-		fn_print_failure "Unable to get remote build"
-		fn_script_log_fatal "Unable to get remote build"
-		core_exit.sh
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://papermc.io/api/v2/projects/"
+	# Get list of projects.
+	remotebuildresponse=$(curl -s "${apiurl}")
+	# Get list of Minecraft versions for project.
+	remotebuildresponseproject=$(curl -s "${apiurl}/${paperproject}")
+	# Get latest Minecraft: Java Edition version or user specified version.
+	if [ "${mcversion}" == "latest" ]; then
+		remotebuildmcversion=$(echo "${remotebuildresponseproject}" | jq -r '.versions[-1]')
 	else
-		fn_print_ok "Got build for version ${paperversion}"
-		fn_script_log "Got build for version ${paperversion}"
+		# Checks if user specified version exists.
+		remotebuildmcversion=$(echo "${remotebuildresponseproject}" | jq -r -e --arg mcversion "${mcversion}" '.versions[]|select(. == $mcversion)')
+		if [ -z "${remotebuildmcversion}" ]; then
+			# user passed version does not exist
+			fn_print_error_nl "Version ${mcversion} not available from ${remotelocation}"
+			fn_script_log_error "Version ${mcversion} not available from ${remotelocation}"
+			core_exit.sh
+		fi
+	fi
+	# Get list of paper builds for specific Minecraft: Java Edition version.
+	remotebuildresponsemcversion=$(curl -s "${apiurl}/paper/versions/${remotebuildmcversion}")
+	# Get latest paper build for specific Minecraft: Java Edition version.
+	remotebuildpaperversion=$(echo "${remotebuildresponsemcversion}" | jq -r '.builds[-1]')
+	# Get various info about the paper build.
+	remotebuildresponseversion=$(curl -s "${apiurl}/${paperproject}/versions/${remotebuildmcversion}/builds/${remotebuildpaperversion}")
+	remotebuildfilename=$(echo "${remotebuildresponseversion}" | jq -r '.downloads.application.name')
+	remotebuildhash=$(echo "${remotebuildresponseversion}" | jq -r '.downloads.application.sha256')
+	remotebuildurl="${apiurl}/${paperproject}/versions/${remotebuildmcversion}/builds/${remotebuildpaperversion}/downloads/${remotebuildfilename}"
+	# Combines Minecraft: Java Edition version and paper build. e.g 1.16.5-456
+	remotebuildversion="${remotebuildmcversion}-${remotebuildpaperversion}"
+
+	if [ "${firstcommandname}" != "INSTALL" ]; then
+		fn_print_dots "Checking remote build: ${remotelocation}"
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
+			fn_print_fail "Checking remote build: ${remotelocation}"
+			fn_script_log_fatal "Checking remote build"
+			core_exit.sh
+		else
+			fn_print_ok "Checking remote build: ${remotelocation}"
+			fn_script_log_pass "Checking remote build"
+		fi
+	else
+		# Checks if remotebuild variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
+			fn_print_failure "Unable to get remote build"
+			fn_script_log_fatal "Unable to get remote build"
+			core_exit.sh
+		fi
 	fi
 }
 
-fn_update_papermc_compare() {
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	sleep 0.5
-	if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
-		echo -e "Update available for version ${paperversion}"
+		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
-		fn_script_log_info "Update available for version ${paperversion}"
-		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
-		echo -en "\n"
-		echo -en "applying update.\r"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
-
-		unset updateonstart
-
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			fn_update_papermc_dl
-		# If server started.
-		else
-			exitbypass=1
-			command_stop.sh
-			exitbypass=1
-			fn_update_papermc_dl
-			exitbypass=1
-			command_start.sh
+		fn_script_log_info "Update available"
+		fn_script_log_info "Local build: ${localbuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
+
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
+				exitbypass=1
+				command_stop.sh
+				fn_firstcommand_reset
+				exitbypass=1
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
+				fn_firstcommand_reset
+			fi
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
-		echo -e "No update available for version ${paperversion}"
+		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
@@ -128,35 +180,14 @@ elif [ "${shortname}" == "wmc" ]; then
 	paperproject="waterfall"
 fi
 
-localversionfile="${datadir}/${paperproject}-version"
-
-# check if datadir was created, if not create it
-if [ ! -d "${datadir}" ]; then
-	mkdir -p "${datadir}"
-fi
-
-# check version if the user did set one and check it
-if [ "${mcversion}" == "latest" ]; then
-	paperversion=$(curl -s "https://${remotelocation}/api/v2/projects/${paperproject}" | jq -r '.versions[-1]')
-else
-	# check if version there for the download from the api
-	paperversion=$(curl -s "https://${remotelocation}/api/v2/projects/${paperproject}" | jq -r -e --arg mcversion "${mcversion}" '.versions[]|select(. == $mcversion)')
-	if [ -z "${paperversion}" ]; then
-		# user passed version does not exist
-		fn_print_error_nl "Version ${mcversion} not available from ${remotelocation}"
-		fn_script_log_error "Version ${mcversion} not available from ${remotelocation}"
-		core_exit.sh
-	fi
-fi
-
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_papermc_remotebuild
-	fn_update_papermc_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
+	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	sleep 0.5
-	fn_update_papermc_localbuild
-	fn_update_papermc_remotebuild
-	fn_update_papermc_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 68 - 112
lgsm/functions/update_ts3.sh

@@ -7,116 +7,48 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_ts3_dl() {
-	ts3latestdata=$(curl -s "https://www.${remotelocation}/versions/server.json" | jq '.linux')
-	if [ "${ts3arch}" == "amd64" ]; then
-		remotebuildurl=$(echo -e "${ts3latestdata}" | jq -r '.x86_64.mirrors."teamspeak.com"')
-		remotehash=$(echo -e "${ts3latestdata}" | jq -r '.x86_64.checksum')
-	elif [ "${ts3arch}" == "x86" ]; then
-		remotebuildurl=$(echo -e "${ts3latestdata}" | jq -r '.x86.mirrors."teamspeak.com"')
-		remotehash=$(echo -e "${ts3latestdata}" | jq -r '.x86.checksum')
-	fi
-	remotefile=$(basename "${remotebuildurl}")
-	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotefile}" "" "norun" "noforce" "${remotehash}"
-	fn_dl_extract "${tmpdir}" "${remotefile}" "${tmpdir}"
-	echo -e "copying to ${serverfiles}...\c"
-	cp -R "${tmpdir}/teamspeak3-server_linux_${ts3arch}/"* "${serverfiles}"
-	local exitcode=$?
-	if [ "${exitcode}" == "0" ]; then
-		fn_print_ok_eol_nl
-		fn_script_log_pass "Copying to ${serverfiles}"
-		fn_clear_tmp
-	else
-		fn_print_fail_eol_nl
-		fn_script_log_fatal "Copying to ${serverfiles}"
-		fn_clear_tmp
-		core_exit.sh
-	fi
+fn_update_dl() {
+	# Download and extract files to serverfiles
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" "teamspeak3-server_linux_${ts3arch}"
+	fn_clear_tmp
 }
 
-fn_update_ts3_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses log file to gather info.
-	# Gives time for log file to generate.
-	requirerestart=1
-	if [ ! -d "${serverfiles}/logs" ] || [ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; 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
-		exitbypass=1
-		command_start.sh
-		fn_firstcommand_reset
-		totalseconds=0
-		# Check again, allow time to generate logs.
-		while [ ! -d "${serverfiles}/logs" ] || [ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; 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
-
-			if [ "${totalseconds}" -gt "120" ]; then
-				localbuild="0"
-				fn_print_error "Checking local build: ${remotelocation}: waiting for log file: missing log file"
-				fn_script_log_error "Missing log file"
-				fn_script_log_error "Set localbuild to 0"
-			fi
-
-			totalseconds=$((totalseconds + 1))
-		done
-	fi
-
-	if [ -z "${localbuild}" ]; then
-		localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1)
-	fi
-
-	if [ -z "${localbuild}" ]; then
-		# Gives time for var to generate.
-		totalseconds=0
-		for seconds in {1..120}; do
-			fn_print_info "Checking local build: ${remotelocation}: waiting for local build: ${totalseconds}"
-			if [ -z "${loopignore}" ]; then
-				loopignore=1
-				fn_script_log_info "Waiting for local build to generate"
-			fi
-			localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1)
-			if [ "${localbuild}" ] || [ "${seconds}" == "120" ]; then
-				break
-			fi
-			sleep 1
-			totalseconds=$((totalseconds + 1))
-		done
-	fi
-
+	# Uses log file to get local build.
+	localbuild=$(grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1)
 	if [ -z "${localbuild}" ]; then
-		localbuild="0"
-		fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info"
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
 		fn_script_log_error "Missing local build info"
 		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
 	else
 		fn_print_ok "Checking local build: ${remotelocation}"
 		fn_script_log_pass "Checking local build"
 	fi
 }
 
-fn_update_ts3_remotebuild() {
-	# Gets remote build info.
-	ts3latestdata=$(curl -s "https://www.${remotelocation}/versions/server.json" | jq '.linux')
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://www.teamspeak.com/versions/server.json"
+	remotebuildresponse=$(curl -s "${apiurl}")
+
 	if [ "${ts3arch}" == "amd64" ]; then
-		remotebuild=$(echo -e "${ts3latestdata}" | jq -r '.x86_64.version')
+		remotebuildurl=$(echo -e "${remotebuildresponse}" | jq -r '.linux.x86_64.mirrors."teamspeak.com"')
+		remotebuildhash=$(echo -e "${remotebuildresponse}" | jq -r '.linux.x86_64.checksum')
 	elif [ "${ts3arch}" == "x86" ]; then
-		remotebuild=$(echo -e "${ts3latestdata}" | jq -r '.x86.version')
+		remotebuildurl=$(echo -e "${remotebuildresponse}" | jq -r '.linux.x86.mirrors."teamspeak.com"')
+		remotebuildhash=$(echo -e "${remotebuildresponse}" | jq -r '.linux.x86.checksum')
 	fi
+	remotebuildfilename=$(basename "${remotebuildurl}")
+	remotebuildversion=$(echo -e "${remotebuildresponse}" | jq -r '.linux.x86_64.version')
+
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -126,7 +58,7 @@ fn_update_ts3_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -134,34 +66,45 @@ fn_update_ts3_remotebuild() {
 	fi
 }
 
-fn_update_ts3_compare() {
-	# Removes dots so if statement can compare version numbers.
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
-	remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
-	if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
+		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
 		if [ "${commandname}" == "UPDATE" ]; then
 			unset updateonstart
 			check_status.sh
 			# If server stopped.
 			if [ "${status}" == "0" ]; then
-				exitbypass=1
-				fn_update_ts3_dl
-				if [ "${requirerestart}" == "1" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
 					exitbypass=1
 					command_start.sh
 					fn_firstcommand_reset
 					exitbypass=1
+					sleep 5
 					command_stop.sh
 					fn_firstcommand_reset
 				fi
@@ -172,7 +115,7 @@ fn_update_ts3_compare() {
 				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				fn_update_ts3_dl
+				fn_update_dl
 				exitbypass=1
 				command_start.sh
 				fn_firstcommand_reset
@@ -189,11 +132,24 @@ fn_update_ts3_compare() {
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
@@ -213,13 +169,13 @@ fi
 remotelocation="teamspeak.com"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_ts3_remotebuild
-	fn_update_ts3_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_ts3_localbuild
-	fn_update_ts3_remotebuild
-	fn_update_ts3_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi

+ 163 - 0
lgsm/functions/update_ut99.sh

@@ -0,0 +1,163 @@
+#!/bin/bash
+# LinuxGSM command_ut99.sh module
+# Author: Daniel Gibbs
+# Contributors: http://linuxgsm.com/contrib
+# Website: https://linuxgsm.com
+# Description: Handles updating of Unreal Tournament 99 servers.
+
+functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
+
+fn_update_dl() {
+	# Download and extract files to serverfiles
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
+	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
+	echo "${remotebuildversion}" > "${serverfiles}/build.txt"
+	fn_clear_tmp
+}
+
+fn_update_localbuild() {
+	# Gets local build info.
+	fn_print_dots "Checking local build: ${remotelocation}"
+	# Uses build file to get local build.
+	localbuild=$(head -n 1 "${serverfiles}/build.txt")
+	if [ -z "${localbuild}" ]; then
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
+		fn_script_log_error "Missing local build info"
+		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
+	else
+		fn_print_ok "Checking local build: ${remotelocation}"
+		fn_script_log_pass "Checking local build"
+	fi
+}
+
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="https://api.github.com/repos/OldUnreal/UnrealTournamentPatches/releases/latest"
+	remotebuildresponse=$(curl -s "${apiurl}")
+	remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .name')
+	remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .browser_download_url')
+	remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
+
+	if [ "${firstcommandname}" != "INSTALL" ]; then
+		fn_print_dots "Checking remote build: ${remotelocation}"
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
+			fn_print_fail "Checking remote build: ${remotelocation}"
+			fn_script_log_fatal "Checking remote build"
+			core_exit.sh
+		else
+			fn_print_ok "Checking remote build: ${remotelocation}"
+			fn_script_log_pass "Checking remote build"
+		fi
+	else
+		# Checks if remotebuild variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
+			fn_print_failure "Unable to get remote build"
+			fn_script_log_fatal "Unable to get remote build"
+			core_exit.sh
+		fi
+	fi
+}
+
+fn_update_compare() {
+	fn_print_dots "Checking for update: ${remotelocation}"
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
+		fn_print_ok_nl "Checking for update: ${remotelocation}"
+		echo -en "\n"
+		echo -e "Update available"
+		echo -e "* Local build: ${red}${localbuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
+		echo -en "\n"
+		fn_script_log_info "Update available"
+		fn_script_log_info "Local build: ${localbuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
+
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
+				exitbypass=1
+				command_stop.sh
+				fn_firstcommand_reset
+				exitbypass=1
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
+				fn_firstcommand_reset
+			fi
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
+		fi
+		alert.sh
+	else
+		fn_print_ok_nl "Checking for update: ${remotelocation}"
+		echo -en "\n"
+		echo -e "No update available"
+		echo -e "* Local build: ${green}${localbuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
+		if [ -n "${branch}" ]; then
+			echo -e "* Branch: ${branch}"
+		fi
+		echo -en "\n"
+		fn_script_log_info "No update available"
+		fn_script_log_info "Local build: ${localbuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
+	fi
+}
+
+# The location where the builds are checked and downloaded.
+remotelocation="github.com"
+
+if [ "${firstcommandname}" == "INSTALL" ]; then
+	fn_update_remotebuild
+	fn_update_dl
+else
+	fn_print_dots "Checking for update"
+	fn_print_dots "Checking for update: ${remotelocation}"
+	fn_script_log_info "Checking for update: ${remotelocation}"
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
+fi

+ 82 - 60
lgsm/functions/update_vintagestory.sh

@@ -7,46 +7,49 @@
 
 functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
 
-fn_update_vs_dl() {
-	# get version info for download
-	remotebuildresponse=$(curl -s "${apiurl}" | jq --arg version "${remotebuild}" '.[$version].server')
-	remotebuildfile=$(echo -e "${remotebuildresponse}" | jq -r '.filename')
-	remotebuildlink=$(echo -e "${remotebuildresponse}" | jq -r '.urls.cdn')
-	remotebuildmd5=$(echo -e "${remotebuildresponse}" | jq -r '.md5')
-
+fn_update_dl() {
 	# Download and extract files to serverfiles
-	fn_fetch_file "${remotebuildlink}" "" "" "" "${tmpdir}" "${remotebuildfile}" "nochmodx" "norun" "force" "${remotebuildmd5}"
-	fn_dl_extract "${tmpdir}" "${remotebuildfile}" "${serverfiles}"
+	fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
+	fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
 	fn_clear_tmp
 }
 
-fn_update_vs_localbuild() {
+fn_update_localbuild() {
 	# Gets local build info.
 	fn_print_dots "Checking local build: ${remotelocation}"
-	# Uses executable to find local build.
-	cd "${executabledir}" || exit
-	if [ -f "${executable}" ]; then
+	# Uses executable to get local build.
+	if [ -d "${exutabledir}" ]; then
+		cd "${executabledir}" || exit
 		localbuild="$(${preexecutable} ${executable} --version | sed '/^[[:space:]]*$/d')"
+	fi
+	if [ -z "${localbuild}" ]; then
+		fn_print_error "Checking local build: ${remotelocation}: missing local build info"
+		fn_script_log_error "Missing local build info"
+		fn_script_log_error "Set localbuild to 0"
+		localbuild="0"
+	else
 		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_vs_remotebuild() {
+fn_update_remotebuild() {
+	# Get remote build info.
+	apiurl="http://api.vintagestory.at/stable-unstable.json"
+	remotebuildresponse=$(curl -s "${apiurl}")
 	if [ "${branch}" == "stable" ]; then
-		remotebuild=$(curl -s "${apiurl}" | jq -r '[ to_entries[] ] | .[].key' | grep -Ev "\-rc|\-pre" | sort -r -V | head -1)
+		remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '[ to_entries[] ] | .[].key' | grep -Ev "\-rc|\-pre" | sort -r -V | head -1)
 	else
-		remotebuild=$(curl -s "${apiurl}" | jq -r '[ to_entries[] ] | .[].key' | grep -E "\-rc|\-pre" | sort -r -V | head -1)
+		remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '[ to_entries[] ] | .[].key' | grep -E "\-rc|\-pre" | sort -r -V | head -1)
 	fi
+	remotebuildfilename=$(echo "${remotebuildresponse}" | jq --arg remotebuildversion "${remotebuildversion}" -r '.[$remotebuildversion].server.filename')
+	remotebuildurl=$(echo "${remotebuildresponse}" | jq --arg remotebuildversion "${remotebuildversion}" -r '.[$remotebuildversion].server.urls.cdn')
+	remotebuildhash=$(echo "${remotebuildresponse}" | jq --arg remotebuildversion "${remotebuildversion}" -r '.[$remotebuildversion].server.md5')
 
 	if [ "${firstcommandname}" != "INSTALL" ]; then
 		fn_print_dots "Checking remote build: ${remotelocation}"
-		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		# Checks if remotebuildversion variable has been set.
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_fail "Checking remote build: ${remotelocation}"
 			fn_script_log_fatal "Checking remote build"
 			core_exit.sh
@@ -56,7 +59,7 @@ fn_update_vs_remotebuild() {
 		fi
 	else
 		# Checks if remotebuild variable has been set.
-		if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
+		if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
 			fn_print_failure "Unable to get remote build"
 			fn_script_log_fatal "Unable to get remote build"
 			core_exit.sh
@@ -64,85 +67,104 @@ fn_update_vs_remotebuild() {
 	fi
 }
 
-fn_update_vs_compare() {
-	# Removes dots so if statement can compare version numbers.
+fn_update_compare() {
 	fn_print_dots "Checking for update: ${remotelocation}"
-	if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
+	if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "Update available"
 		echo -e "* Local build: ${red}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 		echo -en "\n"
 		fn_script_log_info "Update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
-		fn_script_log_info "${localbuild} > ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
+		if [ -n "${branch}" ]; then
+			fn_script_log_info "Branch: ${branch}"
+		fi
+		fn_script_log_info "${localbuild} > ${remotebuildversion}"
 
-		unset updateonstart
-		check_status.sh
-		# If server stopped.
-		if [ "${status}" == "0" ]; then
-			exitbypass=1
-			fn_update_vs_dl
-			if [ "${requirerestart}" == "1" ]; then
+		if [ "${commandname}" == "UPDATE" ]; then
+			unset updateonstart
+			check_status.sh
+			# If server stopped.
+			if [ "${status}" == "0" ]; then
+				fn_update_dl
+				if [ "${localbuild}" == "0" ]; then
+					exitbypass=1
+					command_start.sh
+					fn_firstcommand_reset
+					exitbypass=1
+					sleep 5
+					command_stop.sh
+					fn_firstcommand_reset
+				fi
+			# If server started.
+			else
+				fn_print_restart_warning
 				exitbypass=1
-				command_start.sh
+				command_stop.sh
 				fn_firstcommand_reset
 				exitbypass=1
-				command_stop.sh
+				fn_update_dl
+				exitbypass=1
+				command_start.sh
 				fn_firstcommand_reset
 			fi
-		# If server started.
-		else
-			fn_print_restart_warning
-			exitbypass=1
-			command_stop.sh
-			fn_firstcommand_reset
-			exitbypass=1
-			fn_update_vs_dl
-			exitbypass=1
-			command_start.sh
-			fn_firstcommand_reset
+			unset exitbypass
+			date +%s > "${lockdir}/lastupdate.lock"
+			alert="update"
+		elif [ "${commandname}" == "CHECK-UPDATE" ]; then
+			alert="check-update"
 		fi
-		unset exitbypass
-		date +%s > "${lockdir}/lastupdate.lock"
-		alert="update"
 		alert.sh
 	else
 		fn_print_ok_nl "Checking for update: ${remotelocation}"
 		echo -en "\n"
 		echo -e "No update available"
 		echo -e "* Local build: ${green}${localbuild}${default}"
-		echo -e "* Remote build: ${green}${remotebuild}${default}"
+		echo -e "* Remote build: ${green}${remotebuildversion}${default}"
 		if [ -n "${branch}" ]; then
 			echo -e "* Branch: ${branch}"
 		fi
 		echo -en "\n"
 		fn_script_log_info "No update available"
 		fn_script_log_info "Local build: ${localbuild}"
-		fn_script_log_info "Remote build: ${remotebuild}"
+		fn_script_log_info "Remote build: ${remotebuildversion}"
 		if [ -n "${branch}" ]; then
 			fn_script_log_info "Branch: ${branch}"
 		fi
+		if [ -f "${rootdir}/.dev-debug" ]; then
+			echo -e "Remote build info"
+			echo -e "* apiurl: ${apiurl}"
+			echo -e "* remotebuildfilename: ${remotebuildfilename}"
+			echo -e "* remotebuildurl: ${remotebuildurl}"
+			echo -e "* remotebuildversion: ${remotebuildversion}"
+		fi
 	fi
 }
 
 # The location where the builds are checked and downloaded.
 remotelocation="vintagestory.at"
-apiurl="http://api.${remotelocation}/stable-unstable.json"
 
 if [ "${firstcommandname}" == "INSTALL" ]; then
-	fn_update_vs_remotebuild
-	fn_update_vs_dl
+	fn_update_remotebuild
+	fn_update_dl
 else
 	fn_print_dots "Checking for update"
 	fn_print_dots "Checking for update: ${remotelocation}"
 	fn_script_log_info "Checking for update: ${remotelocation}"
-	fn_update_vs_localbuild
-	fn_update_vs_remotebuild
-	fn_update_vs_compare
+	fn_update_localbuild
+	fn_update_remotebuild
+	fn_update_compare
 fi