Przeglądaj źródła

Moving checks to start of commands

Daniel Gibbs 10 lat temu
rodzic
commit
c2c5693047

+ 44 - 29
functions/check.sh

@@ -7,40 +7,55 @@ lgsm_version="271215"
 # Description: Overall function for managing checks.
 # Runs checks that will either halt on or fix an issue.
 
-fn_module_compare() {
-  local e
-  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
-  return 1
+array_contains () {
+    local seeking=$1; shift
+    local in=1
+    for element; do
+        if [ ${element} == ${seeking} ]; then
+            in=0
+            break
+        fi
+    done
+    return $in
 }
 
 
 check_root.sh
 
-if [ "${cmd}" != "install" ]; then
+if [ "${getopt}" != "install" ]||[ "${getopt}" != "auto-install" ]; then
 	check_systemdir.sh
 fi
 
-no_check_logs=( debug details install map-compressor )
-fn_module_compare "${cmd}" "${no_check_logs[@]}"
-if [ $? != 0 ]; then
-	check_logs.sh
-fi
-
-check_ip=( debug )
-fn_module_compare "${cmd}" "${no_check_logs[@]}"
-if [ $? != 0 ]; then
-	check_ip.sh
-fi
-
-check_ip=( debug )
-fn_module_compare "${cmd}" "${no_check_logs[@]}"
-if [ $? != 0 ]; then
-	check_steamuser.sh
-	check_steamcmd.sh
-fi
-
-check_ip=( start )
-fn_module_compare "${cmd}" "${no_check_logs[@]}"
-if [ $? != 0 ]; then
-	check_tmux.sh
-fi
+local allowed_commands_array=( backup console debug details map-compressor monitor start stop update validate )
+for allowed_command in "${allowed_commands_array[@]}"
+do
+	if [ "${allowed_command}" == "${getopt}" ]; then
+		echo "OK logs"
+		check_logs.sh
+	fi
+done
+
+local allowed_commands_array=( debug details monitor start stop )
+for allowed_command in "${allowed_commands_array[@]}"
+do
+	if [ "${allowed_command}" == "${getopt}" ]; then
+		check_ip.sh
+	fi
+done
+
+local allowed_commands_array=( debug install start stop update validate )
+for allowed_command in "${allowed_commands_array[@]}"
+do
+	if [ "${allowed_command}" == "${getopt}" ]; then
+		check_steamuser.sh
+		check_steamcmd.sh
+	fi
+done
+
+local allowed_commands_array=( console start stop )
+for allowed_command in "${allowed_commands_array[@]}"
+do
+	if [ "${allowed_command}" == "${getopt}" ]; then
+		check_tmux.sh
+	fi
+done

+ 24 - 20
functions/check_ip.sh

@@ -7,25 +7,29 @@ lgsm_version="271215"
 # Description: Automatically identifies the server interface IP.
 # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0".
 
-if [ ! -f "/bin/ip" ]; then
-	ipcommand="/sbin/ip"
-else
-	ipcommand="ip"
-fi
-getip=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
-getipwc=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
-
-if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
-	if [ "${getipwc}" -ge "2" ]; then
-		fn_printwarn "Multiple active network interfaces found.\n\n"
-		echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
-		echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
-		echo -en "${getip}\n"
-		echo -en ""
-		echo -en "http://gameservermanagers.com/network-interfaces"
-		echo -en ""
-		exit 1
+if [ "${gamename}" == "Teamspeak 3" ]; then
+	:
+elif 
+	if [ ! -f "/bin/ip" ]; then
+		ipcommand="/sbin/ip"
 	else
-		ip=${getip}
+		ipcommand="ip"
+	fi
+	getip=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0)
+	getipwc=$(${ipcommand} -o -4 addr|awk '{print $4}'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -vc 127.0.0)
+
+	if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
+		if [ "${getipwc}" -ge "2" ]; then
+			fn_printwarn "Multiple active network interfaces found.\n\n"
+			echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
+			echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
+			echo -en "${getip}\n"
+			echo -en ""
+			echo -en "http://gameservermanagers.com/network-interfaces"
+			echo -en ""
+			exit 1
+		else
+			ip=${getip}
+		fi
 	fi
-fi
+fi

+ 1 - 2
functions/command_backup.sh

@@ -7,8 +7,7 @@ lgsm_version="271215"
 # Description: Creates a .tar.gz file in the backup directory.
 
 local modulename="Backup"
-check_root.sh
-check_systemdir.sh
+check.sh
 backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
 echo ""
 echo "${gamename} Backup"

+ 1 - 3
functions/command_console.sh

@@ -7,8 +7,7 @@ lgsm_version="271215"
 # Description: Gives access to the server tmux console.
 
 local modulename="Console"
-check_root.sh
-check_systemdir.sh
+check.sh
 echo ""
 echo "${gamename} Console"
 echo "============================"
@@ -26,7 +25,6 @@ esac
 done
 fn_printdots "Starting"
 sleep 1
-check_tmux.sh
 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
 if [ "${tmuxwc}" -eq 1 ]; then
 	fn_printoknl "Starting"

+ 1 - 4
functions/command_debug.sh

@@ -7,10 +7,7 @@ lgsm_version="271215"
 # Description: Runs the server without tmux. Runs direct from the terminal.
 
 local modulename="Debug"
-check_root.sh
-check_systemdir.sh
-check_ip.sh
-check_logs.sh
+check.sh
 info_distro.sh
 fn_parms
 echo ""

+ 23 - 148
functions/command_details.sh

@@ -106,7 +106,7 @@ printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
 	# online status
 	if [ "${gamename}" == "Teamspeak 3" ]; then
 		info_ts3status.sh
-		if [ "${ts3status}" = "Server seems to have died" ] || [ "${ts3status}"	= "No server running (ts3server.pid is missing)" ]; then
+		if [ "${ts3status}" = "Server seems to have died" ]||[ "${ts3status}"	= "No server running (ts3server.pid is missing)" ]; then
 			echo -e "\e[34mStatus:\t\e[0;31mOFFLINE\e[0m"
 		else
 			echo -e "\e[34mStatus:\t\e[0;32mONLINE\e[0m"
@@ -184,7 +184,7 @@ fn_details_backup(){
 echo -e ""
 echo -e "\e[92mBackups\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
-if [ ! -d "${backupdir}" ] || [ "${backupcount}" == "0" ]; then
+if [ ! -d "${backupdir}" ]||[ "${backupcount}" == "0" ]; then
 	echo -e "No Backups created"
 else
 	{
@@ -207,7 +207,7 @@ echo -e "${executable} ${parms}"
 fn_details_statusbottom(){
 echo -e ""
 if [ "${gamename}" == "Teamspeak 3" ]; then
-	if [ "${ts3status}" = "Server seems to have died" ] || [ "${ts3status}"	= "No server running (ts3server.pid is missing)" ]; then
+	if [ "${ts3status}" = "Server seems to have died" ]||[ "${ts3status}"	= "No server running (ts3server.pid is missing)" ]; then
         echo -e "\e[34mStatus: \e[0;31mOFFLINE\e[0m"
 	else
 		echo -e "\e[34mStatus: \e[0;32mONLINE\e[0m"
@@ -226,14 +226,6 @@ echo -e ""
 # Engine Specific details
 
 fn_details_avalanche(){
-check_ip.sh
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -252,14 +244,6 @@ fn_details_statusbottom
 }
 
 fn_details_dontstarve(){
-check_ip.sh
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -278,14 +262,6 @@ fn_details_statusbottom
 }
 
 fn_details_projectzomboid(){
-check_ip.sh
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -305,16 +281,6 @@ fn_details_statusbottom
 
 
 fn_details_realvirtuality(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -324,7 +290,7 @@ echo -e ""
 echo -e "Useful port diagnostic command:"
 echo -e "netstat -atunp | grep arma3server"
 echo -e ""
-if [ -z "${port}" ] || [ -z "${queryport}" ] || [ -z "${masterport}" ]; then
+if [ -z "${port}" ]||[ -z "${queryport}" ]||[ -z "${masterport}" ]; then
 	echo -e "\e[0;31mERROR!\e[0m Missing/commented ports in ${servercfg}."
 	echo -e ""
 fi
@@ -339,16 +305,6 @@ fn_details_statusbottom
 }
 
 fn_details_seriousengine35(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -368,16 +324,6 @@ fn_details_statusbottom
 }
 
 fn_details_source(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -400,16 +346,6 @@ fn_details_statusbottom
 }
 
 fn_details_spark(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -438,16 +374,6 @@ fn_details_statusbottom
 }
 
 fn_details_starbound(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -469,14 +395,6 @@ fn_details_statusbottom
 }
 
 fn_details_teamspeak3(){
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -497,16 +415,6 @@ fn_details_statusbottom
 }
 
 fn_details_teeworlds(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -525,16 +433,6 @@ fn_details_statusbottom
 }
 
 fn_details_terraria(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -555,16 +453,6 @@ fn_details_statusbottom
 }
 
 fn_details_sdtd(){
-fn_check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -602,16 +490,6 @@ fn_details_statusbottom
 }
 
 fn_details_hurtworld(){
-check_ip.sh
-fn_parms
-fn_details_config
-fn_details_distro
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -633,16 +511,6 @@ fn_details_statusbottom
 }
 
 fn_details_unreal(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -690,16 +558,6 @@ fn_details_statusbottom
 }
 
 fn_details_ark(){
-check_ip.sh
-fn_parms
-info_config.sh
-info_distro.sh
-fn_details_os
-fn_details_performance
-fn_details_disk
-fn_details_gameserver
-fn_details_backup
-fn_details_commandlineparms
 echo -e ""
 echo -e "\e[92mPorts\e[0m"
 printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' =
@@ -718,6 +576,10 @@ echo -e ""
 fn_details_statusbottom
 }
 
+
+# Run checks and gathers details to display.
+check.sh 
+
 if [ ! -e "${servercfgfullpath}" ]; then
 	if [ "${gamename}" != "Hurtworld" ]; then
 		echo ""
@@ -734,8 +596,21 @@ if [ ! -e "${servercfgfullpath}" ]; then
 	fi
 fi
 
+info_config.sh
+info_distro.sh
 info_glibc.sh
+fn_details_os
+fn_details_performance
+fn_details_gameserver
+fn_details_backup
+# Some game servers do not have parms.
+if [ "${gamename}" != "Teamspeak 3" ]||[ "${engine}" != "avalanche" ]||[ "${engine}" != "dontstarve" ]||[ "${engine}" == "projectzomboid" ]; then
+	fn_parms
+	fn_details_commandlineparms
+fi
+
 
+# Display details depending on game or engine.
 if [ "${engine}" == "avalanche" ]; then
 	fn_details_avalanche
 elif [ "${engine}" == "dontstarve" ]; then
@@ -746,7 +621,7 @@ elif [ "${engine}" == "realvirtuality" ]; then
 	fn_details_realvirtuality
 elif [ "${engine}" == "seriousengine35" ]; then
 	fn_details_seriousengine35
-elif [ "${engine}" == "source" ] || [ "${engine}" == "goldsource" ]; then
+elif [ "${engine}" == "source" ]||[ "${engine}" == "goldsource" ]; then
 	fn_details_source
 elif [ "${engine}" == "spark" ]; then
 	fn_details_spark
@@ -756,7 +631,7 @@ elif [ "${engine}" == "teeworlds" ]; then
 	fn_details_teeworlds
 elif [ "${engine}" == "terraria" ]; then
 	fn_details_terraria
-elif [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
+elif [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
 	fn_details_unreal
 elif [ "${gamename}" == "ARK: Survivial Evolved" ]; then
 	fn_details_ark

+ 0 - 0
functions/dev_debug.sh → functions/command_dev_debug.sh


+ 1 - 2
functions/dev_detect_deps.sh → functions/command_dev_detect_deps.sh

@@ -7,8 +7,7 @@ lgsm_version="271215"
 # Description: Detects dependencies the server binary requires.
 
 local modulename="Backup"
-check_root.sh
-check_systemdir.sh
+check.sh
 cd "${executabledir}"
 if [ "${executable}" ==  "./hlds_run" ]; then
 	executable=hlds_linux

+ 1 - 1
functions/command_install.sh

@@ -4,7 +4,7 @@
 # Website: http://gameservermanagers.com
 lgsm_version="271215"
 
-check_root.sh
+check.sh
 install_header.sh
 install_serverdir.sh
 

+ 2 - 5
functions/command_monitor.sh

@@ -10,8 +10,7 @@ lgsm_version="271215"
 local modulename="Monitor"
 
 fn_monitor_teamspeak3(){
-check_root.sh
-check_systemdir.sh
+check.sh
 logs.sh
 fn_printdots "${servername}"
 fn_scriptlog "${servername}"
@@ -54,9 +53,7 @@ fn_restart
 }
 
 fn_monitor_tmux(){
-check_root.sh
-check_systemdir.sh
-check_ip.sh
+check.sh
 info_config.sh
 fn_printdots "${servername}"
 fn_scriptlog "${servername}"

+ 1 - 3
functions/command_start.sh

@@ -9,9 +9,7 @@ lgsm_version="271215"
 local modulename="Starting"
 
 fn_start_teamspeak3(){
-check_root.sh
-check_systemdir.sh
-check_logs.sh
+check.sh
 info_ts3status.sh
 
 if [ "${ts3status}" != "Server is running" ]; then

+ 2 - 6
functions/command_stop.sh

@@ -29,8 +29,7 @@ sdtd_telnet(){
 }
 
 fn_stop_teamspeak3(){
-check_root.sh
-check_systemdir.sh
+check.sh
 fn_printdots "${servername}"
 fn_scriptlog "${servername}"
 sleep 1
@@ -50,13 +49,11 @@ echo -en "\n"
 }
 
 fn_stop_tmux(){
-check_root.sh
-check_systemdir.sh
+check.sh
 info_config.sh
 fn_printdots "${servername}"
 fn_scriptlog "${servername}"
 sleep 1
-check_tmux.sh
 
 if [ "${gamename}" == "7 Days To Die" ] ; then
     # if game is 7 Days To Die, we need special, graceful shutdown via telnet connection.
@@ -70,7 +67,6 @@ if [ "${gamename}" == "7 Days To Die" ] ; then
     # If failed using localhost will use servers ip
     refused=$(echo -en "\n ${sdtdshutdown}"| grep "Timeout or EOF")
     if [ -n "${refused}" ]; then
-        check_ip.sh
         telnetip=${ip}
         fn_printwarn "Attempting graceful shutdown via telnet: localhost failed"
         fn_scriptlog "Warning! Attempting graceful shutdown failed using localhost"

+ 1 - 4
functions/command_validate.sh

@@ -9,8 +9,6 @@ lgsm_version="271215"
 local modulename="Validate"
 
 fn_validation(){
-check_steamcmd.sh
-check_steamuser.sh	
 fn_printwarn "Validating may overwrite some customised files."
 sleep 1
 echo -en "\n"
@@ -42,8 +40,7 @@ fi
 fn_scriptlog "Checking complete"
 }
 
-check_root.sh
-check_systemdir.sh
+check.sh
 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -Ec "^${servicename}:")
 if [ "${tmuxwc}" -eq 1 ]; then
     command_stop.sh

+ 1 - 1
functions/compress_unreal2_maps.sh

@@ -4,7 +4,7 @@
 # Website: http://gameservermanagers.com
 lgsm_version="271215"
 
-check_root.sh
+check.sh
 clear
 echo "${gamename} Map Compressor"
 echo "============================"

+ 1 - 1
functions/compress_ut99_maps.sh

@@ -4,7 +4,7 @@
 # Website: http://gameservermanagers.com
 lgsm_version="271215"
 
-check_root.sh
+check.sh
 clear
 echo "${gamename} Map Compressor"
 echo "============================"

+ 1 - 1
functions/install_serverfiles.sh

@@ -5,7 +5,7 @@
 lgsm_version="271215"
 
 fn_steaminstallcommand(){
-check_steamuser.sh
+check.sh
 counter="0"
 while [ "${counter}" == "0" ]||[ "$(grep -wc 0x402 .finstall_serverfiles.sh.tmp)" -ge "1" ]||[ "$(grep -wc 0x406 .finstall_serverfiles.sh.tmp)" -ge "1" ]||[ "$(grep -wc 0x6 .finstall_serverfiles.sh.tmp)" -ge "1" ]||[ "$(grep -wc 0x106 .finstall_serverfiles.sh.tmp)" -ge "1" ]; do
 	counter=$((counter+1))

+ 1 - 2
functions/update_check.sh

@@ -102,8 +102,7 @@ fi
 }
 
 fn_steamcmdcheck(){
-check_steamcmd.sh
-check_steamuser.sh
+check.sh
 fn_appmanifestcheck
 # Checks for server update from SteamCMD
 fn_printdots "Checking for update: SteamCMD"

+ 2 - 4
functions/update_dl.sh

@@ -9,8 +9,7 @@ lgsm_version="271215"
 local modulename="Update"
 
 fn_steamcmd_dl(){
-check_root.sh
-check_systemdir.sh
+check.sh
 info_config.sh
 fn_printdots "Updating ${servername}"
 sleep 1
@@ -39,8 +38,7 @@ fi
 }
 
 fn_teamspeak3_dl(){
-check_root.sh
-check_systemdir.sh
+check.sh
 info_config.sh
 fn_printdots "Updating ${servername}"
 sleep 1