Răsfoiți Sursa

Merge pull request #1134 from GameServerManagers/pr/1133

Factorio Final
Daniel Gibbs 9 ani în urmă
părinte
comite
28433ac6f6

+ 148 - 0
Factorio/fctrserver

@@ -0,0 +1,148 @@
+#!/bin/bash
+# Factorio
+# Server Management Script
+# Author: Daniel Gibbs
+# Contributor: Kristian Polso
+# Website: https://gameservermanagers.com
+if [ -f ".dev-debug" ]; then
+        exec 5>dev-debug.log
+        BASH_XTRACEFD="5"
+        set -x
+fi
+
+version="171016"
+
+#### Variables ####
+
+# Notification Alerts
+# (on|off)
+
+# Email
+emailalert="off"
+email="email@example.com"
+#emailfrom="email@example.com"
+
+# Pushbullet
+# https://www.pushbullet.com/#settings
+pushbulletalert="off"
+pushbullettoken="accesstoken"
+
+# Server settings
+# More settings available after install in serverfiles/data/server-settings.json
+updateonstart="off"
+port="34197"
+rconport="34198"
+rconpassword="factorio"
+
+fn_parms(){
+parms="--start-server ${filesdir}/save1.zip --server-settings ${servercfgfullpath} --port ${port} --rcon-port ${rconport} --rcon-password ${rconpassword}"
+}
+
+#### Advanced Variables ####
+
+# Github Branch Select
+# Allows for the use of different function files
+# from a different repo and/or branch.
+githubuser="Krisseck"
+githubrepo="LinuxGSM"
+githubbranch="master"
+
+# Server Details
+gamename="Factorio"
+servicename="fctr-server"
+
+# Directories
+rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
+selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+lockselfname=".${servicename}.lock"
+lgsmdir="${rootdir}/lgsm"
+functionsdir="${lgsmdir}/functions"
+libdir="${lgsmdir}/lib"
+tmpdir="${lgsmdir}/tmp"
+filesdir="${rootdir}/serverfiles"
+systemdir="${filesdir}"
+executabledir="${filesdir}"
+executable="./bin/x64/factorio"
+servercfg="data/server-settings.json"
+servercfgdefault="data/server-settings.example.json"
+servercfgdir="${filesdir}"
+servercfgfullpath="${servercfgdir}/${servercfg}"
+backupdir="${rootdir}/backups"
+
+# Logging
+logdays="7"
+gamelogdir="${rootdir}/log"
+scriptlogdir="${rootdir}/log/script"
+consolelogdir="${rootdir}/log/console"
+consolelogging="on"
+
+scriptlog="${scriptlogdir}/${servicename}-script.log"
+consolelog="${consolelogdir}/${servicename}-console.log"
+emaillog="${scriptlogdir}/${servicename}-email.log"
+
+scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
+consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
+
+##### Script #####
+# Do not edit
+
+# Fetches core_dl for file downloads
+fn_fetch_core_dl(){
+github_file_url_dir="lgsm/functions"
+github_file_url_name="${functionfile}"
+filedir="${functionsdir}"
+filename="${github_file_url_name}"
+githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
+# If the file is missing, then download
+if [ ! -f "${filedir}/${filename}" ]; then
+        if [ ! -d "${filedir}" ]; then
+                mkdir -p "${filedir}"
+        fi
+        echo -e "    fetching ${filename}...\c"
+        # Check curl exists and use available path
+        curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
+        for curlcmd in ${curlpaths}
+        do
+                if [ -x "${curlcmd}" ]; then
+                        break
+                fi
+        done
+        # If curl exists download file
+        if [ "$(basename ${curlcmd})" == "curl" ]; then
+                curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
+                if [ $? -ne 0 ]; then
+                        echo -e "\e[0;31mFAIL\e[0m\n"
+                        echo "${curlfetch}"
+                        echo -e "${githuburl}\n"
+                        exit 1
+                else
+                        echo -e "\e[0;32mOK\e[0m"
+                fi
+        else
+                echo -e "\e[0;31mFAIL\e[0m\n"
+                echo "Curl is not installed!"
+                echo -e ""
+                exit 1
+        fi
+        chmod +x "${filedir}/${filename}"
+fi
+source "${filedir}/${filename}"
+}
+
+core_dl.sh(){
+# Functions are defined in core_functions.sh.
+functionfile="${FUNCNAME}"
+fn_fetch_core_dl
+}
+
+core_functions.sh(){
+# Functions are defined in core_functions.sh.
+functionfile="${FUNCNAME}"
+fn_fetch_core_dl
+}
+
+core_dl.sh
+core_functions.sh
+
+getopt=$1
+core_getopt.sh

+ 13 - 1
lgsm/functions/command_details.sh

@@ -318,7 +318,7 @@ fn_details_ports(){
 		fi
 	done
 	# engines that require editing in the script file
-	local ports_edit_array=( "Hurtworld" "iw3.0" "goldsource" "Rust" "spark" "source" "starbound" "unreal4" )
+	local ports_edit_array=( "Factorio" "goldsource" "Hurtworld" "iw3.0"  "Rust" "spark" "source" "starbound" "unreal4" )
 	for port_edit in "${ports_edit_array[@]}"
 	do
 		if [ "${engine}" == "${port_edit}" ]||[ "${gamename}" == "${port_edit}" ]; then
@@ -408,6 +408,15 @@ fn_details_dontstarve(){
 	} | column -s $'\t' -t
 }
 
+fn_details_factorio(){
+	echo -e "netstat -atunp | grep factorio"
+	echo -e ""
+	{
+		echo -e "DESCRIPTION\tDIRECTION\tPORT\tPROTOCOL"
+		echo -e "> Game\tINBOUND\t${port}\ttcp"
+	} | column -s $'\t' -t
+}
+
 fn_details_minecraft(){
 	echo -e "netstat -atunp | grep java"
 	echo -e ""
@@ -783,6 +792,8 @@ fn_display_details() {
 		fn_details_rust
 	elif [ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 		fn_details_wolfensteinenemyterritory
+	elif [ "${gamename}" == "Factorio" ]; then
+		fn_details_factorio
 	else
 		fn_print_error_nl "Unable to detect server engine."
 	fi
@@ -795,3 +806,4 @@ then
   fn_display_details
   core_exit.sh
 fi
+

+ 1 - 1
lgsm/functions/command_install.sh

@@ -18,7 +18,7 @@ check_deps.sh
 if [ "${gamename}" == "Unreal Tournament 2004" ]; then
 	install_server_files.sh
 	install_ut2k4_key.sh
-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}" == "Minecraft" ]||[ "${gamename}" == "Quake 2" ]||[ "${gamename}" == "Quake 3: Arena" ]||[ "${gamename}" == "QuakeWorld" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament" ]||[ "${gamename}" == "Unreal Tournament 3" ]||[ "${gamename}" == "TeamSpeak 3" ]||[ "${gamename}" == "Mumble" ]||[ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
+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}" == "Factorio" ]||[ "${gamename}" == "Minecraft" ]||[ "${gamename}" == "Quake 2" ]||[ "${gamename}" == "Quake 3: Arena" ]||[ "${gamename}" == "QuakeWorld" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "${gamename}" == "Unreal Tournament" ]||[ "${gamename}" == "Unreal Tournament 3" ]||[ "${gamename}" == "TeamSpeak 3" ]||[ "${gamename}" == "Mumble" ]||[ "${gamename}" == "Wolfenstein: Enemy Territory" ]; then
 	installer=1
 	install_server_files.sh
 elif [ -n "${appid}" ]; then

+ 2 - 0
lgsm/functions/command_update.sh

@@ -19,6 +19,8 @@ elif [ "${engine}" == "lwjgl2" ]; then
 	update_minecraft.sh
 elif [ "${gamename}" == "Mumble" ]; then
 	update_mumble.sh
+elif [ "${gamename}" == "Factorio" ]; then
+        update_factorio.sh
 else
 	update_steamcmd.sh
 fi

+ 10 - 0
lgsm/functions/core_functions.sh

@@ -450,6 +450,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+update_factorio.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 update_steamcmd.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_function
@@ -480,6 +485,11 @@ functionfile="${FUNCNAME}"
 fn_fetch_function
 }
 
+install_factorio_save.sh(){
+functionfile="${FUNCNAME}"
+fn_fetch_function
+}
+
 install_dst_token.sh(){
 functionfile="${FUNCNAME}"
 fn_fetch_function

+ 3 - 0
lgsm/functions/info_glibc.sh

@@ -38,6 +38,9 @@ elif [ "${gamename}" == "Double Action: Boogaloo" ]; then
 elif [ "${gamename}" == "Empires Mod" ]; then
 	glibcrequired="2.15"
 	glibcfix="yes"
+elif [ "${gamename}" == "Factorio" ]; then
+	glibcrequired="2.15"
+	glibcfix="yes"
 elif [ "${gamename}" == "Fistful of Frags" ]; then
 	glibcrequired="2.15"
 	glibcfix="yes"

+ 2 - 0
lgsm/functions/install_config.sh

@@ -261,6 +261,8 @@ elif [ "${gamename}" == "Double Action: Boogaloo" ]; then
 	fn_fetch_default_config
 	fn_default_config_remote
 	fn_set_config_vars
+elif [ "${gamename}" == "Factorio" ]; then
+	:
 elif [ "${gamename}" == "Fistful of Frags" ]; then
 	gamedirname="FistfulofFrags"
 	array_configs+=( server.cfg )

+ 15 - 0
lgsm/functions/install_factorio_save.sh

@@ -0,0 +1,15 @@
+#!/bin/bash
+# LGSM install_factorio_save.sh function
+# Author: Kristian Polso
+# Website: https://gameservermanagers.com
+# Description: Creates the initial save file for Factorio
+
+local commandname="INSTALL"
+local commandaction="Install"
+
+echo ""
+echo "Creating initial Factorio savefile"
+echo "================================="
+sleep 1
+${filesdir}/bin/x64/factorio --create ${filesdir}/save1
+cp ${filesdir}/data/server-settings.example.json ${filesdir}/data/server-settings.json

+ 3 - 0
lgsm/functions/install_server_files.sh

@@ -129,6 +129,9 @@ elif [ "${gamename}" == "Minecraft" ]; then
 	install_minecraft_eula.sh
 elif [ "${gamename}" == "Mumble" ]; then
 	update_mumble.sh
+elif [ "${gamename}" == "Factorio" ]; then
+  update_factorio.sh
+  install_factorio_save.sh
 elif [ -z "${appid}" ]||[ "${gamename}" == "GoldenEye: Source" ]; then
 	fn_install_server_files
 fi

+ 165 - 0
lgsm/functions/update_factorio.sh

@@ -0,0 +1,165 @@
+#!/bin/bash
+# LGSM update_factorio.sh function
+# Author: Daniel Gibbs
+# Contributor: Kristian Polso
+# Website: https://gameservermanagers.com
+# Description: Handles updating of Factorio servers.
+
+local commandname="UPDATE"
+local commandaction="Update"
+local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
+
+fn_update_factorio_dl(){
+	fn_fetch_file "https://www.factorio.com/get-download/${availablebuild}/headless/${factorioarch}" "${tmpdir}" "factorio_headless_${factorioarch}-${availablebuild}.tar.gz"
+	fn_dl_extract "${tmpdir}" "factorio_headless_${factorioarch}-${availablebuild}.tar.gz" "${tmpdir}"
+	echo -e "copying to ${filesdir}...\c"
+	fn_script_log "Copying to ${filesdir}"
+	cp -R "${tmpdir}/factorio/"* "${filesdir}"
+	local exitcode=$?
+	if [ ${exitcode} -eq 0 ]; then
+		fn_print_ok_eol_nl
+	else
+		fn_print_fail_eol_nl
+	fi
+}
+
+fn_update_factorio_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: Factorio.com"
+		sleep 1
+		fn_print_error_nl "Checking for update: Factorio.com: No logs with server version found"
+		fn_script_log_error "Checking for update: Factorio.com: No logs with server version found"
+		sleep 1
+		fn_print_info_nl "Checking for update: Factorio.com: Forcing server restart"
+		fn_script_log_info "Checking for update: Factorio.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: Factorio.com: Still No logs with server version found"
+			fn_script_log_fatal "Checking for update: Factorio.com: Still No logs with server version found"
+			core_exit.sh
+		fi
+	fi
+
+	# Get current build from logs
+	currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | grep -oP '(?<=Factorio ).*?(?= \()')
+	if [ -z "${currentbuild}" ]; then
+		fn_print_error_nl "Checking for update: Factorio.com: Current build version not found"
+		fn_script_log_error "Checking for update: Factorio.com: Current build version not found"
+		sleep 1
+		fn_print_info_nl "Checking for update: Factorio.com: Forcing server restart"
+		fn_script_log_info "Checking for update: Factorio.com: Forcing server restart"
+		exitbypass=1
+		command_stop.sh
+		exitbypass=1
+		command_start.sh
+		currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | grep -oP '(?<=Factorio ).*?(?= /)')
+		if [ -z "${currentbuild}" ]; then
+			fn_print_fail_nl "Checking for update: Factorio.com: Current build version still not found"
+			fn_script_log_fatal "Checking for update: Factorio.com: Current build version still not found"
+			core_exit.sh
+		fi
+	fi
+}
+
+fn_update_factorio_arch(){
+	# Factorio is linux64 only for now
+	factorioarch="linux64"
+}
+
+fn_update_factorio_availablebuild(){
+	# Gets latest build info.
+	availablebuild=$(curl -s https://www.factorio.com/download-headless/stable | grep 'headless/linux64' | head -n 1 | grep -oP '(?<=get-download/).*?(?=/)')
+	sleep 1
+
+	# Checks if availablebuild variable has been set
+	if [ -z "${availablebuild}" ]; then
+		fn_print_fail "Checking for update: Factorio.com"
+		sleep 1
+		fn_print_fail "Checking for update: Factorio.com: Not returning version info"
+		fn_script_log_fatal "Failure! Checking for update: Factorio.com: Not returning version info"
+		core_exit.sh
+	else
+		fn_print_ok "Checking for update: Factorio.com"
+		fn_script_log_pass "Checking for update: Factorio.com"
+		sleep 1
+	fi
+}
+
+fn_update_factorio_compare(){
+	# Removes dots so if can compare version numbers
+	currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
+	availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
+
+	if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
+		echo -e "\n"
+		echo -e "Update available:"
+		sleep 1
+		echo -e "	Current build: ${red}${currentbuild} ${factorioarch}${default}"
+		echo -e "	Available build: ${green}${availablebuild} ${factorioarch}${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: ${availablebuild}"
+		fn_script_log "${currentbuild} > ${availablebuild}"
+
+		unset updateonstart
+
+		check_status.sh
+		if [ "${status}" == "0" ]; then
+			fn_update_factorio_dl
+			exitbypass=1
+			command_start.sh
+			exitbypass=1
+			command_stop.sh
+		else
+			exitbypass=1
+			command_stop.sh
+			fn_update_factorio_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}${availablebuild}${default}"
+		echo -e ""
+		fn_print_ok_nl "No update available"
+		fn_script_log_info "Current build: ${currentbuild}"
+		fn_script_log_info "Available build: ${availablebuild}"
+	fi
+}
+
+
+fn_update_factorio_arch
+if [ "${installer}" == "1" ]; then
+	fn_update_factorio_availablebuild
+	fn_update_factorio_dl
+else
+	# Checks for server update from github.com
+	fn_print_dots "Checking for update: github.com"
+	fn_script_log_info "Checking for update: github.com"
+	sleep 1
+	fn_update_factorio_currentbuild
+	fn_update_factorio_availablebuild
+	fn_update_factorio_compare
+fi