Braunson 9 лет назад
Родитель
Сommit
939854cfe0

+ 3 - 1
lgsm/functions/command_update.sh

@@ -20,7 +20,9 @@ elif [ "${engine}" == "lwjgl2" ]; then
 elif [ "${gamename}" == "Mumble" ]; then
 	update_mumble.sh
 elif [ "${gamename}" == "Factorio" ]; then
-        update_factorio.sh
+  update_factorio.sh
+elif [ "$Pgamename" == "Multi Theft Auto" ]; then
+	update_mta.sh
 else
 	update_steamcmd.sh
 fi

+ 5 - 0
lgsm/functions/core_functions.sh

@@ -462,6 +462,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+update_mta.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 update_factorio.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_function

+ 6 - 3
lgsm/functions/core_getopt.sh

@@ -350,6 +350,8 @@ case "${getopt}" in
 		command_stop.sh;;
 	r|restart)
 		command_restart.sh;;
+	u|update)
+		command_update.sh;;
 	uf|update-functions)
 		command_update_functions.sh;;
 	m|monitor)
@@ -394,6 +396,7 @@ case "${getopt}" in
 		echo -e "${blue}start\t${default}st |Start the server."
 		echo -e "${blue}stop\t${default}sp |Stop the server."
 		echo -e "${blue}restart\t${default}r  |Restart the server."
+		echo -e "${blue}update\t${default}u  |Checks and applies updates from linux.mtasa.com."
 		echo -e "${blue}update-functions\t${default}uf |Removes all functions so latest can be downloaded."
 		echo -e "${blue}monitor\t${default}m  |Checks that the server is running."
 		echo -e "${blue}test-alert\t${default}ta |Sends test alert."
@@ -845,7 +848,7 @@ elif [ "${gamename}" == "Multi Theft Auto" ]; then
 # Mumble
 elif [ "${gamename}" == "Mumble" ]; then
 	fn_getopt_mumble
-# Teamspeak 3	
+# Teamspeak 3
 elif [ "${gamename}" == "TeamSpeak 3" ]; then
 	fn_getopt_teamspeak3
 # Unreal 2 Engine
@@ -855,14 +858,14 @@ elif [ "${engine}" == "unreal2" ]; then
 	else
 		fn_getopt_unreal2
 	fi
-# Unreal Engine	
+# Unreal Engine
 elif [ "${engine}" == "unreal" ]; then
 	fn_getopt_unreal
 # Generic
 elif [ "${gamename}" == "Battlefield: 1942" ]||[ "${gamename}" == "Call of Duty" ]||[ "${gamename}" == "Call of Duty: United Offensive" ]||[ "${gamename}" == "Call of Duty 2" ]||[ "${gamename}" == "Call of Duty 4" ]||[ "${gamename}" == "Call of Duty: World at War" ]||[ "${gamename}" == "QuakeWorld" ]||[ "${gamename}" == "Quake 2" ]||[ "${gamename}" == "Quake 3: Arena" ]||[ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 	fn_getopt_generic_no_update
 elif  [ "${gamename}" == "Factorio" ]; then
-	fn_getopt_generic_update_no_steam	
+	fn_getopt_generic_update_no_steam
 else
 	fn_getopt_generic
 fi

+ 2 - 0
lgsm/functions/install_server_files.sh

@@ -131,6 +131,8 @@ elif [ "${gamename}" == "Minecraft" ]; then
 	update_minecraft.sh
 elif [ "${gamename}" == "Mumble" ]; then
 	update_mumble.sh
+elif [ "${gamename}" == "Multi Theft Auto" ]; then
+	update_mta.sh
 elif [ "${gamename}" == "Factorio" ]; then
   update_factorio.sh
   install_factorio_save.sh

+ 149 - 0
lgsm/functions/update_mta.sh

@@ -0,0 +1,149 @@
+#!/bin/bash
+# LGSM update_mta.sh function
+# Author: Daniel Gibbs
+# Website: https://gameservermanagers.com
+# Description: Handles updating of Multi Theft Auto servers.
+
+local commandname="UPDATE"
+local commandaction="Update"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+fn_update_mta_dl(){
+	fn_fetch_file "http://linux.mtasa.com/dl/${NUM_VERSION}/multitheftauto_linux_x64-${FUL_VERSION}.tar.gz"
+	fn_dl_extract "${tmpdir}" "multitheftauto_linux_x64-${FUL_VERSION}.tar.gz" "${tmpdir}"
+	echo -e "copying to ${filesdir}...\c"
+	fn_script_log "Copying to ${filesdir}"
+	cp -R "${tmpdir}/multitheftauto_linux_x64-${FUL_VERSION}.tar.gz"* "${filesdir}"
+	local exitcode=$?
+	if [ "${exitcode}" == "0" ]; then
+		fn_print_ok_eol_nl
+	else
+		fn_print_fail_eol_nl
+	fi
+}
+
+fn_update_mta_currentbuild(){
+	# Gets current build info
+	# Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
+	if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
+		fn_print_error "Checking for update: linux.mtasa.com"
+		sleep 1
+		fn_print_error_nl "Checking for update: linux.mtasa.com: No logs with server version found"
+		fn_script_log_error "Checking for update: linux.mtasa.com: No logs with server version found"
+		sleep 1
+		fn_print_info_nl "Checking for update: linux.mtasa.com: Forcing server restart"
+		fn_script_log_info "Checking for update: linux.mtasa.com: Forcing server restart"
+		sleep 1
+		exitbypass=1
+		command_stop.sh
+		exitbypass=1
+		command_start.sh
+		sleep 1
+		# Check again and exit on failure.
+		if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
+			fn_print_fail_nl "Checking for update: linux.mtasa.com: Still No logs with server version found"
+			fn_script_log_fatal "Checking for update: linux.mtasa.com: Still No logs with server version found"
+			core_exit.sh
+		fi
+	fi
+
+	# Get current build from logs
+	currentbuild=$(awk -F"= Multi Theft Auto: San Andreas v" '{print $2}' "${consolelogdir}"/"${servicename}"-console.log | awk '{print $1}')
+	if [ -z "${currentbuild}" ]; then
+		fn_print_error_nl "Checking for update: linux.mtasa.com: Current build version not found"
+		fn_script_log_error "Checking for update: linux.mtasa.com: Current build version not found"
+		sleep 1
+		fn_print_info_nl "Checking for update: linux.mtasa.com: Forcing server restart"
+		fn_script_log_info "Checking for update: linux.mtasa.com: Forcing server restart"
+		exitbypass=1
+		command_stop.sh
+		exitbypass=1
+		command_start.sh
+		currentbuild=$(awk -F"= Multi Theft Auto: San Andreas v" '{print $2}' "${consolelogdir}"/"${servicename}"-console.log | awk '{print $1}')
+		if [ -z "${currentbuild}" ]; then
+			fn_print_fail_nl "Checking for update: linux.mtasa.com: Current build version still not found"
+			fn_script_log_fatal "Checking for update: linux.mtasa.com: Current build version still not found"
+			core_exit.sh
+		fi
+	fi
+}
+
+fn_mta_getServerVersion()
+{
+		fn_fetch_file "https://raw.githubusercontent.com/multitheftauto/mtasa-blue/master/Server/version.h" "${tmpdir}" # we need to find latest stable version here
+		local MAJOR_VERSION="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MAJOR" | awk '{ print $3 }' | sed 's/\r//g')"
+		local MINOR_VERSION="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MINOR" | awk '{ print $3 }' | sed 's/\r//g')"
+		local MAINTENANCE_VERSION="$(cat ${tmpdir}/version.h | grep "#define MTASA_VERSION_MAINTENANCE" | awk '{ print $3 }' | sed 's/\r//g')"
+		NUM_VERSION="${MAJOR_VERSION}${MINOR_VERSION}${MAINTENANCE_VERSION}"
+		FUL_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${MAINTENANCE_VERSION}"
+		rm -f "${tmpdir}/version.h"
+}
+
+fn_update_mta_compare(){
+	# Removes dots so if can compare version numbers
+	currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
+
+	if [ "${currentbuilddigit}" -ne "${NUM_VERSION}" ]; then
+		echo -e "\n"
+		echo -e "Update available:"
+		sleep 1
+		echo -e "	Current build: ${red}${currentbuild} ${default}"
+		echo -e "	Available build: ${green}${FULL_VERSION} ${default}"
+		echo -e ""
+		sleep 1
+		echo ""
+		echo -en "Applying update.\r"
+		sleep 1
+		echo -en "Applying update..\r"
+		sleep 1
+		echo -en "Applying update...\r"
+		sleep 1
+		echo -en "\n"
+		fn_script_log "Update available"
+		fn_script_log "Current build: ${currentbuild}"
+		fn_script_log "Available build: ${FULL_VERSION}"
+		fn_script_log "${currentbuild} > ${FULL_VERSION}"
+
+		unset updateonstart
+
+		check_status.sh
+		if [ "${status}" == "0" ]; then
+			fn_update_mta_dl
+			exitbypass=1
+			command_start.sh
+			exitbypass=1
+			command_stop.sh
+		else
+			exitbypass=1
+			command_stop.sh
+			fn_update_mta_dl
+			exitbypass=1
+			command_start.sh
+		fi
+		alert="update"
+		alert.sh
+	else
+		echo -e "\n"
+		echo -e "No update available:"
+		echo -e "	Current version: ${green}${currentbuild}${default}"
+		echo -e "	Available version: ${green}${FULL_VERSION}${default}"
+		echo -e ""
+		fn_print_ok_nl "No update available"
+		fn_script_log_info "Current build: ${currentbuild}"
+		fn_script_log_info "Available build: ${FULL_VERSION}"
+	fi
+}
+
+
+if [ "${installer}" == "1" ]; then
+	fn_mta_getServerVersion
+	fn_update_mta_dl
+else
+	# Checks for server update from linux.mtasa.com using the github repo.
+	fn_print_dots "Checking for update: linux.mtasa.com"
+	fn_script_log_info "Checking for update: linux.mtasa.com"
+	sleep 1
+	fn_update_mta_currentbuild
+	fn_mta_getServerVersion
+	fn_update_mta_compare
+fi