From 556d10178178b0e3b652f3a67ec1ce4e3f318a6a Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Thu, 6 Feb 2014 01:05:52 +0000 Subject: [PATCH] major update 050214 * Fixed insserver. Now works on Debian and CentOS * Added validate feature now 4 options update, update-restart, validate, validate-restart * Improved consistency of error messages thanks to wrelam * Fixed bug with fn_logmanager * Added steam_appid.txt file to fix an error where the server would crash --- CounterStrike/csserver | 231 ++++++++++++++------- CounterStrikeConditionZero/csczserver | 231 ++++++++++++++------- CounterStrikeGlobalOffensive/csgoserver | 259 ++++++++++++++++-------- CounterStrikeSource/cssserver | 232 ++++++++++++++------- DayOfDefeat/dodserver | 240 ++++++++++++++-------- DayOfDefeatSource/dodsserver | 232 ++++++++++++++------- HalfLife2Deathmatch/hl2dmserver | 232 ++++++++++++++------- HalfLifeDeathmatchClassic/hldmcserver | 235 ++++++++++++++------- Insurgency/insserver | 244 +++++++++++++++------- KillingFloor/kfserver | 239 +++++++++++++++------- Left4Dead2/l4d2server | 234 ++++++++++++++------- NaturalSelection2/ns2server | 236 ++++++++++++++------- NoMoreRoomInHell/nmrihserver | 231 ++++++++++++++------- RedOrchestra/roserver | 232 ++++++++++++++------- TeamFortress2/tf2server | 234 ++++++++++++++------- TeamFortressClassic/tfcserver | 231 ++++++++++++++------- UnrealTournament2004/ut2k4server | 220 ++++++++++++-------- UnrealTournament99/ut99server | 209 ++++++++++++------- 18 files changed, 2838 insertions(+), 1364 deletions(-) diff --git a/CounterStrike/csserver b/CounterStrike/csserver index 58538e3cc..f148ab4df 100644 --- a/CounterStrike/csserver +++ b/CounterStrike/csserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,13 +18,14 @@ steampass="" # Start Variables defaultmap="de_dust2" +maxplayers="16" port="27015" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 fn_parms(){ -parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game cstrike -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -77,16 +78,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -158,11 +211,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -186,21 +239,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -411,24 +465,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -453,12 +508,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -472,18 +547,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -640,8 +715,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -792,8 +867,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -810,7 +893,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/CounterStrikeConditionZero/csczserver b/CounterStrikeConditionZero/csczserver index 525f3c368..b7ae5a4a5 100644 --- a/CounterStrikeConditionZero/csczserver +++ b/CounterStrikeConditionZero/csczserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,13 +18,14 @@ steampass="" # Start Variables defaultmap="de_dust2" +maxplayers="16" port="27015" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 fn_parms(){ -parms="-game czero +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game czero -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -77,16 +78,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -158,11 +211,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -186,21 +239,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -411,24 +465,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -453,12 +508,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -472,18 +547,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -646,8 +721,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -802,8 +877,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -820,7 +903,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/CounterStrikeGlobalOffensive/csgoserver b/CounterStrikeGlobalOffensive/csgoserver index f34795195..b5d4a6037 100644 --- a/CounterStrikeGlobalOffensive/csgoserver +++ b/CounterStrikeGlobalOffensive/csgoserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -17,27 +17,33 @@ steamuser="anonymous" steampass="" # Start Variables -# [Game Modes] game_mode game_type +# https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server +# [Game Modes] gametype gamemode +# Arms Race 1 0 # Classic Casual 0 0 # Classic Competitive 0 1 -# Arms Race 1 0 # Demolition 1 1 +# Deathmatch 1 2 gamemode="0" gametype="0" -defaultmap="de_dust" -mapgroup="random_classic" -maxplayers="16" defaultmap="de_dust2" mapgroup="random_classic" +maxplayers="16" +tickrate="64" port="27015" sourcetvport="27020" clientport="27005" ip="0.0.0.0" +# Optional: Workshop Parameters +# https://developer.valvesoftware.com/wiki/CSGO_Workshop_For_Server_Operators +# To get an authkey visit - http://steamcommunity.com/dev/apikey +# authkey="" +# wscollectionid="" +# wsstartmap="" # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server -# https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server fn_parms(){ -parms="-game csgo -usercon +map ${defaultmap} +mapgroup ${mapgroup} +game_mode ${gamemode} +game_type ${gametype} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game csgo -usercon -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers_override ${maxplayers} +mapgroup ${mapgroup} +game_mode ${gamemode} +game_type ${gametype} +host_workshop_collection ${wh_collection_id} +workshop_start_map ${wh_start_map} -authkey ${authkey}" } #### Advanced Variables #### @@ -90,16 +96,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -111,7 +161,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -128,20 +178,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -150,6 +208,7 @@ fn_debugserver(){ fn_rootcheck fn_syscheck fn_autoip +fn_csgoappidfix fn_parms echo "" echo "${gamename} Debug" @@ -171,11 +230,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -199,21 +258,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -247,17 +306,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -324,10 +383,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -340,10 +399,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -357,23 +416,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -386,15 +446,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -410,10 +470,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -424,24 +484,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -455,10 +515,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -466,12 +527,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -485,18 +566,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -504,6 +585,7 @@ fn_startserver(){ fn_rootcheck fn_syscheck fn_autoip +fn_csgoappidfix fn_parms fn_logmanager tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) @@ -511,14 +593,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -526,13 +608,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -571,6 +653,17 @@ fi echo "" } +fn_csgoappidfix(){ +if [ ! -f "${filesdir}/steam_appid.txt" ]; then + fn_printdots "Applying 730 steam_appid.txt Fix." + sleep 1 + fn_printinfo "Applying 730 steam_appid.txt Fix." + sleep 1 + echo -en "\n" + echo -n "730" >> ${filesdir}/steam_appid.txt +fi +} + # ## Installer # @@ -631,8 +724,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -750,8 +843,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -768,7 +869,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/CounterStrikeSource/cssserver b/CounterStrikeSource/cssserver index 021845a0b..69b9c472a 100644 --- a/CounterStrikeSource/cssserver +++ b/CounterStrikeSource/cssserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,14 +18,16 @@ steampass="" # Start Variables defaultmap="de_dust2" +maxplayers="16" +tickrate="64" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}" +parms="-game cstrike -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +80,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +213,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +241,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +467,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +510,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +549,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -619,8 +695,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -738,8 +814,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -756,7 +840,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/DayOfDefeat/dodserver b/DayOfDefeat/dodserver index 31a01d5aa..63de63619 100644 --- a/DayOfDefeat/dodserver +++ b/DayOfDefeat/dodserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,13 +18,14 @@ steampass="" # Start Variables defaultmap="dod_Anzio" +maxplayers="16" port="27015" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 fn_parms(){ -parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game dod -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -77,16 +78,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -158,11 +211,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -186,17 +239,17 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in @@ -240,11 +293,11 @@ if [ ${tmuxwc} -eq 1 ]; then esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -411,24 +465,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -453,12 +508,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -472,18 +547,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -574,18 +649,18 @@ if [ ${pass} == 1 ]; then sleep 2 rm -f appmanifest_10.acf appmanifest_70.acf appmanifest_90.acf elif [ ${pass} == 2 ]; then - echo "Downloading firstpass appmanifest files. (app 90 fix)" + echo "Downloading HLDS appmanifest files. (app 90 fix)" sleep 2 cd "${appdir}" - wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/firstpass/appmanifest_10.acf - wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/firstpass/appmanifest_70.acf - wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/firstpass/appmanifest_90.acf + wget https://raw.github.com/dgibbs64/linuxgameservers/master/appmanifest/appmanifest_10.acf + wget https://raw.github.com/dgibbs64/linuxgameservers/master/appmanifest/appmanifest_70.acf + wget https://raw.github.com/dgibbs64/linuxgameservers/master/appmanifest/appmanifest_90.acf elif [ ${pass} == 3 ]; then - echo "Downloading secondpass appmanifest files. (app 90 fix)" + echo "Downloading ${gamename} appmanifest files. (app 90 fix)" sleep 2 cd "${appdir}" rm -f appmanifest_90.acf - wget https://raw2.github.com/dgibbs64/linuxgameservers/master/DayOfDefeat/appmanifest/secondpass/appmanifest_90.acf + wget https://raw2.github.com/dgibbs64/linuxgameservers/master/appmanifest/dod/appmanifest_90.acf fi } @@ -646,8 +721,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -711,7 +786,6 @@ while true; do done fn_header fn_steamdl - echo "Installing ${gamename} Server" echo "=================================" pass=1 @@ -803,8 +877,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -821,7 +903,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/DayOfDefeatSource/dodsserver b/DayOfDefeatSource/dodsserver index 873d57b1a..6ac981489 100644 --- a/DayOfDefeatSource/dodsserver +++ b/DayOfDefeatSource/dodsserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,14 +18,16 @@ steampass="" # Start Variables defaultmap="dod_Anzio" +maxplayers="16" +tickrate="64" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game dod -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +80,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +213,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +241,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +467,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +510,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +549,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -619,8 +695,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -738,8 +814,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -756,7 +840,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/HalfLife2Deathmatch/hl2dmserver b/HalfLife2Deathmatch/hl2dmserver index a4ba33b51..84c6b62ab 100644 --- a/HalfLife2Deathmatch/hl2dmserver +++ b/HalfLife2Deathmatch/hl2dmserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,14 +18,16 @@ steampass="" # Start Variables defaultmap="dm_lockdown" +maxplayers="16" +tickrate="64" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="-game hl2mp +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game hl2mp -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +80,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +213,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +241,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +467,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +510,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +549,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -619,8 +695,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -738,8 +814,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -756,7 +840,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/HalfLifeDeathmatchClassic/hldmcserver b/HalfLifeDeathmatchClassic/hldmcserver index b957815cc..024ebcfc6 100644 --- a/HalfLifeDeathmatchClassic/hldmcserver +++ b/HalfLifeDeathmatchClassic/hldmcserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,13 +18,14 @@ steampass="" # Start Variables defaultmap="crossfire" +maxplayers="16" port="27015" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 fn_parms(){ -parms="-game valve +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game valve -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -52,8 +53,8 @@ backupdir="backups" steamclient="${rootdir}/steamcmd/linux32/steamclient.so" # Server Details -servername=$(grep -s hostname "${servercfg}"|sed 's/hostname //g'|sed 's/"//g') -rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g') +servername=$(grep -s hostname "${servercfgfullpath}"|sed 's/hostname //g'|sed 's/"//g') +rcon=$(grep -s rcon_password "${servercfgfullpath}"|sed 's/rcon_password //g'|sed 's/"//g') # Logging logdays="7" @@ -77,16 +78,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -158,11 +211,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -186,21 +239,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -411,24 +465,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -453,12 +508,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -472,18 +547,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -640,8 +715,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -792,8 +867,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -810,7 +893,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/Insurgency/insserver b/Insurgency/insserver index 720f51d09..1bc3ed862 100644 --- a/Insurgency/insserver +++ b/Insurgency/insserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,14 +18,15 @@ steampass="password" # Start Variables defaultmap="ministry" +maxplayers="16" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="24" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +79,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +144,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +161,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +212,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +240,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +288,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +365,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +381,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +398,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +428,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +452,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +466,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +497,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +509,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +548,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +574,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +589,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -563,6 +638,18 @@ echo "" ## Installer # +fn_inshdeps(){ +echo "Downloading libm.so.6" +echo "=================================" +sleep 1 +cd "${filesdir}/bin" +wget https://github.com/dgibbs64/linuxgameservers/raw/master/Insurgency/dependencies/libc.so.6 +wget https://github.com/dgibbs64/linuxgameservers/raw/master/Insurgency/dependencies/libpthread.so.0 +wget https://github.com/dgibbs64/linuxgameservers/raw/master/Insurgency/dependencies/librt.so.1 +sleep 1 +echo "" +} + fn_header(){ clear echo "=================================" @@ -619,8 +706,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -687,6 +774,7 @@ fn_steamdl fn_steaminstall fn_steamfix fn_loginstall +fn_inshdeps echo "Configuring ${gamename} Server" echo "=================================" sleep 1 @@ -738,8 +826,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -756,7 +852,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/KillingFloor/kfserver b/KillingFloor/kfserver index 42a4e253d..453961c93 100644 --- a/KillingFloor/kfserver +++ b/KillingFloor/kfserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -69,16 +69,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -90,7 +134,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -107,20 +151,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -150,11 +202,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} @@ -178,21 +230,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -226,17 +278,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -303,10 +355,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -319,10 +371,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -336,23 +388,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -365,15 +418,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -389,10 +442,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -403,24 +456,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -434,10 +487,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -445,12 +499,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -464,18 +538,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -490,14 +564,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -505,13 +579,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -532,14 +606,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/ echo "" echo "${gamename} Server Details" echo "============================" -echo "" echo "Server name: ${servername}" echo "Server IP: ${ip}:${gameport}" echo "Config file: ${systemdir}/${ini}" echo "" echo "${servername} Ports" -echo "=======================" -echo "Ports the server is currently using" +echo "============================" +echo "Ports the server is currently using." echo "" echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" @@ -664,6 +737,17 @@ done echo "" } +fn_steamfix(){ +echo "Applying steamclient.so fix" +echo "=================================" +sleep 1 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" +cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" +sleep 1 +echo "" +} + fn_loginstall(){ echo "Creating log directorys" echo "=================================" @@ -723,6 +807,7 @@ done fn_header fn_steamdl fn_steaminstall +fn_steamfix fn_loginstall echo "Configuring ${gamename} Server" echo "=================================" @@ -775,8 +860,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -795,7 +888,7 @@ case "$1" in map-compressor) fn_kfcompressmaps;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|map-compressor}" exit 1;; esac exit \ No newline at end of file diff --git a/Left4Dead2/l4d2server b/Left4Dead2/l4d2server index f5b1314f1..bd657aca4 100644 --- a/Left4Dead2/l4d2server +++ b/Left4Dead2/l4d2server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -17,15 +17,17 @@ steamuser="anonymous" steampass="" # Start Variables -defaultmap="c5m1_waterfront" +defaultmap="de_dust2" +maxplayers="8" +tickrate="64" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="8" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="-game left4dead2 +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game left4dead2 -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +80,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +213,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +241,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +467,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +510,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +549,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -619,8 +695,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -738,8 +814,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -756,7 +840,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/NaturalSelection2/ns2server b/NaturalSelection2/ns2server index 6e046b40c..167e035a4 100644 --- a/NaturalSelection2/ns2server +++ b/NaturalSelection2/ns2server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -72,16 +72,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -93,7 +137,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -110,20 +154,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -153,14 +205,14 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" -${executable} ${parms} +${executable} ${parms} -debug } fn_console(){ @@ -181,21 +233,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -229,17 +281,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -306,10 +358,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -322,10 +374,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -339,23 +391,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -368,15 +421,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -392,10 +445,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -406,24 +459,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -437,10 +490,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -448,12 +502,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -467,18 +541,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -493,14 +567,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -508,13 +582,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -529,11 +603,11 @@ echo "Server name: ${servername}" echo "Server IP: ${ip}:${port}" echo "" echo "${servername} Ports" -echo "=======================" -echo "Ports the server is currently using" +echo "============================" +echo "Ports the server is currently using." echo "" echo "DIRECTION DESCRIPTION PORT" -echo "INBOUND Game/RCON Port ${port}" +echo "INBOUND Game/RCON port ${port}" echo "INBOUND Query Port ${queryport}" echo "INBOUND WebAdmin ${webadminport}" echo "" @@ -544,7 +618,7 @@ echo "WebAdmin Username: ${webadminuser}" echo "WebAdmin Password: ${webadminpass}" echo "" echo "You can change various parameters by editing the" -echo "start parameters in ${selfname}" +echo "start parameters in ${selfname}." echo "" if [ "${pid}" == "0" ]; then echo -e "Status:\e[0;31m OFFLINE\e[0;39m" @@ -624,8 +698,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -713,8 +787,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -731,7 +813,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/NoMoreRoomInHell/nmrihserver b/NoMoreRoomInHell/nmrihserver index ba6855f9a..cc25a1178 100644 --- a/NoMoreRoomInHell/nmrihserver +++ b/NoMoreRoomInHell/nmrihserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,14 +18,15 @@ steampass="password" # Start Variables defaultmap="nmo_broadway" +maxplayers="8" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="8" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +79,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +144,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +161,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +212,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +240,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +288,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +365,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +381,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +398,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +428,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +452,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +466,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +497,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +509,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +548,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +574,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +589,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -629,8 +704,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -749,8 +824,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -767,7 +850,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/RedOrchestra/roserver b/RedOrchestra/roserver index 3b857a70e..fa298fd10 100644 --- a/RedOrchestra/roserver +++ b/RedOrchestra/roserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -65,16 +65,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -86,7 +130,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -103,20 +147,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -146,11 +198,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} @@ -174,21 +226,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -222,17 +274,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -299,10 +351,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -315,10 +367,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -332,23 +384,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -361,15 +414,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -385,10 +438,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -399,24 +452,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -430,10 +483,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -441,12 +495,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -460,18 +534,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -486,14 +560,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -501,13 +575,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -528,14 +602,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/ echo "" echo "${gamename} Server Details" echo "============================" -echo "" echo "Server name: ${servername}" echo "Server IP: ${ip}:${gameport}" echo "Config file: ${systemdir}/${ini}" echo "" echo "${servername} Ports" -echo "=======================" -echo "Ports the server is currently using" +echo "============================" +echo "Ports the server is currently using." echo "" echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" @@ -664,8 +737,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -730,6 +803,7 @@ done fn_header fn_steamdl fn_steaminstall +fn_steamfix fn_loginstall echo "Configuring ${gamename} Server" echo "=================================" @@ -782,8 +856,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -802,7 +884,7 @@ case "$1" in map-compressor) fn_kfcompressmaps;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|map-compressor}" exit 1;; esac exit \ No newline at end of file diff --git a/TeamFortress2/tf2server b/TeamFortress2/tf2server index e5559c496..66b203354 100644 --- a/TeamFortress2/tf2server +++ b/TeamFortress2/tf2server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -17,15 +17,17 @@ steamuser="anonymous" steampass="" # Start Variables -defaultmap="ctf_2fort" +defaultmap="de_dust2" +maxplayers="16" +tickrate="64" port="27015" sourcetvport="27020" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server fn_parms(){ -parms="-game tf +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game tf -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -78,16 +80,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -99,7 +145,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -116,20 +162,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -159,11 +213,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -187,21 +241,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -235,17 +289,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -312,10 +366,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -328,10 +382,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -345,23 +399,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -374,15 +429,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -398,10 +453,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -412,24 +467,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -443,10 +498,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -454,12 +510,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -473,18 +549,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -499,14 +575,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -514,13 +590,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -619,8 +695,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -738,8 +814,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -756,7 +840,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/TeamFortressClassic/tfcserver b/TeamFortressClassic/tfcserver index 55b3b9ed6..7d5c5978d 100644 --- a/TeamFortressClassic/tfcserver +++ b/TeamFortressClassic/tfcserver @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -18,13 +18,14 @@ steampass="" # Start Variables defaultmap="dustbowl" +maxplayers="16" port="27015" clientport="27005" -maxplayers="16" ip="0.0.0.0" + # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2 fn_parms(){ -parms="-game tfc +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} -maxplayers ${maxplayers} +servercfgfile ${servercfg}" +parms="-game tfc -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" } #### Advanced Variables #### @@ -77,16 +78,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -98,7 +143,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -115,20 +160,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -158,11 +211,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} -debug @@ -186,21 +239,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -234,17 +287,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -311,10 +364,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -327,10 +380,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -344,23 +397,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -373,15 +427,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -397,10 +451,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -411,24 +465,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -442,10 +496,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -453,12 +508,32 @@ fi fn_updateserver(){ fn_rootcheck fn_syscheck -echo -en "\r\033[K[ .... ] Updating ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}" +fn_printdots "Updating ${servicename}: ${servername}" +sleep 1 +fn_printok "Updating ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Updating ${servername}" cd "${rootdir}" cd "steamcmd" +./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} +quit|tee -a "${scriptlog}" +} + +fn_validateserver(){ +fn_rootcheck +fn_syscheck +fn_printwarn "Validating may overwrite some customised files." +sleep 1 +echo -en "\n" +echo -en "https://developer.valvesoftware.com/wiki/SteamCMD#Validate" +sleep 5 +echo -en "\n" +fn_printdots "Validating ${servicename}: ${servername}" +sleep 1 +fn_printok "Validating ${servicename}: ${servername}" +sleep 1 +fn_scriptlog "Validating ${servername}" +cd "${rootdir}" +cd "steamcmd" ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}" } @@ -472,18 +547,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -498,14 +573,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -513,13 +588,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -646,8 +721,8 @@ fn_steamfix(){ echo "Applying steamclient.so fix" echo "=================================" sleep 1 -mkdir -pv ${HOME}/.steam -mkdir -pv ${HOME}/.steam/sdk32 +mkdir -pv "${HOME}/.steam" +mkdir -pv "${HOME}/.steam/sdk32" cp -v "${steamclient}" "${HOME}/.steam/sdk32/steamclient.so" sleep 1 echo "" @@ -802,8 +877,16 @@ case "$1" in restart) fn_restartserver;; update) + fn_updateserver;; + update-restart) fn_stopserver fn_updateserver + fn_startserver;; + validate) + fn_validateserver;; + validate-restart) + fn_stopserver + fn_validateserver fn_startserver;; monitor) fn_monitorserver;; @@ -820,7 +903,7 @@ case "$1" in install) fn_install;; *) - echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}" + echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install}" exit 1;; esac exit \ No newline at end of file diff --git a/UnrealTournament2004/ut2k4server b/UnrealTournament2004/ut2k4server index 46a5f0943..e2b825730 100644 --- a/UnrealTournament2004/ut2k4server +++ b/UnrealTournament2004/ut2k4server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -59,16 +59,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -80,7 +124,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -97,20 +141,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -140,15 +192,14 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" -if [ `getconf LONG_BIT` = "64" ] -then +if [ `getconf LONG_BIT` = "64" ]; then ${executable64} ${parms} else ${executable} ${parms} @@ -173,21 +224,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -221,17 +272,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -298,10 +349,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -314,10 +365,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -331,23 +382,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -360,15 +412,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -384,10 +436,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -398,24 +450,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -429,10 +481,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -447,18 +500,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -473,19 +526,18 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" -if [ `getconf LONG_BIT` = "64" ] -then +if [ `getconf LONG_BIT` = "64" ]; then tmux new-session -d -s ${servicename} "${executable64} ${parms}|tee -a '${consolelog}'" else tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'" @@ -493,13 +545,13 @@ fi sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -520,14 +572,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/ echo "" echo "${gamename} Server Details" echo "============================" -echo "" echo "Server name: ${servername}" echo "Server IP: ${ip}:${gameport}" echo "Config file: ${systemdir}/${ini}" echo "" echo "${servername} Ports" -echo "=======================" -echo "Ports the server is currently using" +echo "============================" +echo "Ports the server is currently using." echo "" echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" @@ -591,8 +642,7 @@ mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1 rm -rfv "${filesdir}/Maps/*.uz2" cd "${systemdir}" for map in `ls "${filesdir}/Maps"`; do - if [ `getconf LONG_BIT` = "64" ] - then + if [ `getconf LONG_BIT` = "64" ]; then ./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir else ./ucc-bin compress ../Maps/${map} --nohomedir @@ -678,7 +728,7 @@ echo "" echo "Once you have the key enter it below" echo -n "KEY: " read CODE -echo ""\""CDKey"\""="\""${CODE}"\""" > ${systemdir}/cdkey +echo ""\""CDKey"\""="\""${CODE}"\""" > "${systemdir}/cdkey" echo "" } @@ -705,7 +755,7 @@ done while true; do read -p "Remove ut2004-lnxpatch3369-2.tar.bz2? [y/N]" yn case $yn in - [Yy]* ) rm -fv ut2004-lnxpatch3369-2.tar.bz2;break;; + [Yy]* ) rm -fv ut2004-lnxpatch3369-2.tar.bz2; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -713,7 +763,7 @@ done while true; do read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn case $yn in - [Yy]* ) rm -fv dedicatedserver3339-bonuspack.zip;break;; + [Yy]* ) rm -fv dedicatedserver3339-bonuspack.zip; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -785,22 +835,22 @@ echo "=================================" sleep 1 echo "Applying WebAdmin ut2003.css fix!" echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13" - sed -i 's/none}/none;/g' ${filesdir}/Web/ServerAdmin/ut2003.css - sed -i 's/underline}/underline;/g' ${filesdir}/Web/ServerAdmin/ut2003.css + sed -i 's/none}/none;/g' "${filesdir}/Web/ServerAdmin/ut2003.css" + sed -i 's/underline}/underline;/g' "${filesdir}/Web/ServerAdmin/ut2003.css" sleep 1 echo "Applying WebAdmin CharSet fix!" echo "http://forums.tripwireinteractive.com/showpost.php?p=442340&postcount=1" - sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' ${systemdir}/UWeb.int + sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' "${systemdir}/UWeb.int" sleep 1 echo "Setting WebAdmin username and password" - sed -i 's/AdminName=/AdminName=admin/g' ${systemdir}/${ini} - sed -i 's/AdminPassword=/AdminPassword=admin/g' ${systemdir}/${ini} + sed -i 's/AdminName=/AdminName=admin/g' "${systemdir}/${ini}" + sed -i 's/AdminPassword=/AdminPassword=admin/g' "${systemdir}/${ini}" sleep 1 echo "Enabling WebAdmin" - sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini} + sed -i 's/bEnabled=False/bEnabled=True/g' "${systemdir}/${ini}" sleep 1 echo "Setting WebAdmin port to 8077" - sed -i 's/ListenPort=80/ListenPort=8077/g' ${systemdir}/${ini} + sed -i 's/ListenPort=80/ListenPort=8077/g' "${systemdir}/${ini}" sleep 1 echo "Forcing server to start to get ports/server name to display correctly" sleep 1 diff --git a/UnrealTournament99/ut99server b/UnrealTournament99/ut99server index acd8e0074..7aedb1a44 100644 --- a/UnrealTournament99/ut99server +++ b/UnrealTournament99/ut99server @@ -3,7 +3,7 @@ # Server Management Script # Author: Daniel Gibbs # Website: http://danielgibbs.co.uk -# Version: 010214 +# Version: 050214 #### Variables #### @@ -58,16 +58,60 @@ fn_scriptlog(){ echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog} } +# [ FAIL ] +fn_printfail(){ + echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printfailnl(){ + echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@" +} + +fn_printok(){ + echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +# [ OK ] +fn_printoknl(){ + echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@" +} + +fn_printinfo(){ + echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +# [ INFO ] +fn_printokinfonl(){ + echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@" +} + +fn_printwarn(){ + echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +fn_printwarnnl(){ + echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@" +} + +# [ .... ] +fn_printdots(){ + echo -en "\r\033[K[ .... ] $@" +} + fn_rootcheck(){ if [ `whoami` = "root" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!" + fn_printfailnl "Script will not run as root!" exit fi } fn_syscheck(){ if [ ! -e "${systemdir}" ]; then - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory" + fn_printfailnl "Cannot access ${systemdir}: No such directory" exit fi } @@ -79,7 +123,7 @@ getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|gre getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1|wc -l) if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then if [ "${getipwc}" -ge "2" ]; then - echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n" + fn_printwarn "Multiple active network interfaces.\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" @@ -96,20 +140,28 @@ if [ ! -e "${consolelog}" ]; then fi # log manager will active if finds logs older than ${logdays} if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner" + fn_printdots "Starting log cleaner" + sleep 1 + fn_printok "Starting log cleaner" + sleep 1 fn_scriptlog "Starting log cleaner" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days" + echo -en "\n" + fn_printinfo "Removing logs older than ${logdays} days" + sleep 1 + echo -en "\n" fn_scriptlog "Removing logs older than ${logdays} days" sleep 1 find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}" - scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l) - consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l) + scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l) + consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l) count=$((${scriptcount} + ${consolecount})) find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \; find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \; - echo -e "[\e[0;36m INFO \e[0;39m] Log cleaner removed ${count} log files" + fn_printok "Log cleaner removed ${count} log files" + sleep 1 + echo -en "\n" fn_scriptlog "Log cleaner removed ${count} log files" fi } @@ -139,11 +191,11 @@ while true; do esac done fn_stopserver -echo -en "\r\033[K[ .... ] Starting debug mode ${servicename}: ${servername}" -sleep 0.5 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting debug mode ${servicename}: ${servername}" +fn_printdots "Starting debug mode ${servicename}: ${servername}" +sleep 1 +fn_printok "Starting debug mode ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Started debug mode ${servername}" -sleep 0.5 echo -en "\n" cd "${executabledir}" ${executable} ${parms} @@ -167,21 +219,21 @@ while true; do * ) echo "Please answer yes or no.";; esac done -echo -en "\r\033[K[ .... ] Starting ${servicename} console" -sleep 0.5 +fn_printdots "Starting ${servicename} console" +sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename} console" - fn_scriptlog "Console accessed" + fn_printoknl "Starting ${servicename} console" sleep 1 + fn_scriptlog "Console accessed" tmux attach-session -t ${servicename} else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename} console: ${servername} not running" - sleep 0.5 + fn_printfailnl "Starting ${servicename} console: ${servername} not running" + sleep 1 while true; do read -p "Do you want to start the server? [y/N]" yn case $yn in - [Yy]* ) fn_startserver;break;; + [Yy]* ) fn_startserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -215,17 +267,17 @@ if [ ${tmuxwc} -eq 1 ]; then while true; do read -p "Would you like to stop ${servicename} while running the backup? [y/N]" yn case $yn in - [Yy]* ) fn_stopserver;break;; + [Yy]* ) fn_stopserver; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done fi -echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}" +fn_printdots "Starting backup ${servicename}: ${servername}" sleep 1 -echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}" -fn_scriptlog "Backup started" +fn_printok "Starting backup ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Backup started" echo -en "\n" cd "${rootdir}" mkdir -pv "${backupdir}" > /dev/null 2>&1 @@ -292,10 +344,10 @@ if [ ! -z "${gamelogdir}" ]; then tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}" fi mail -s "${subject}" ${email} < "${emaillog}" -echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}" -fn_scriptlog "Sent email notification to ${email}" +fn_printinfo "Sent email notification to ${email}" sleep 1 echo -en "\n" +fn_scriptlog "Sent email notification to ${email}" } fn_emailtest(){ @@ -308,10 +360,10 @@ if [ "${emailnotification}" = "on" ]; then actiontaken="Sent test email...hello is this thing on?" fn_emailnotification else - echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled" + fn_printfailnl "Email notification not enabled" fn_scriptlog "Email notification not enabled" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -325,23 +377,24 @@ if [ -f gsquery.py ]; then elif [ "${engine}" == "spark" ]; then port=$((${port} + 1)) fi - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected gsquery.py" + fn_printinfo "Monitoring ${servicename}: Detected gsquery.py" + sleep 1 fn_scriptlog "Detected gsquery.py" - sleep 1 - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: QUERYING" serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1) exitcode=$? - sleep 1 if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" - fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}" if [[ -z "${secondquery}" ]]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Waiting 30 seconds to re-query" + fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query" + sleep 1 fn_scriptlog "Waiting 30 seconds to re-query" - sleep 30 + sleep 29 secondquery=1 fn_serverquery fi @@ -354,15 +407,15 @@ if [ -f gsquery.py ]; then fn_restartserver exit elif [ "${exitcode}" == "0" ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK" + sleep 1 fn_scriptlog "Querying port: ${ip}:${port}: OK" - sleep 1 echo -en "\n" exit elif [ "${exitcode}" == "126" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" - fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ERROR: ./gsquery.py: Permission denied" sleep 1 + fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" echo -en "\n" echo "Attempting to resolve automatically" chmod +x -v gsquery.py @@ -378,10 +431,10 @@ if [ -f gsquery.py ]; then exit fi else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" - fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" + fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" sleep 1 echo -en "\n" + fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR" ./gsquery.py -a ${ip} -p ${port} -e ${engine} exit fi @@ -392,24 +445,24 @@ fn_monitorserver(){ fn_rootcheck fn_syscheck fn_autoip -echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}" -fn_scriptlog "Monitoring ${servername}" +fn_printdots "Monitoring ${servicename}: ${servername}" sleep 1 +fn_scriptlog "Monitoring ${servername}" updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) if [ "${updatecheck}" = "0" ]; then - echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Checking session: CHECKING" + fn_printdots "Monitoring ${servicename}: Checking session: CHECKING" + sleep 1 fn_scriptlog "Checking session: CHECKING" - sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Checking session: OK" - fn_scriptlog "Checking session: OK" - sleep 1 + fn_printok "Monitoring ${servicename}: Checking session: OK" + sleep 1 echo -en "\n" + fn_scriptlog "Checking session: OK" fn_serverquery exit else - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL" + fn_printfail "Monitoring ${servicename}: Checking session: FAIL" fn_scriptlog "Checking session: FAIL" sleep 1 echo -en "\n" @@ -423,10 +476,11 @@ if [ "${updatecheck}" = "0" ]; then fn_startserver fi else - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates" - fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates" sleep 1 - echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start" + fn_scriptlog "Detected SteamCMD is checking for updates" + fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start" + sleep 1 fn_scriptlog "When updates complete ${servicename} will start" fi } @@ -441,18 +495,18 @@ fn_stopserver(){ fn_rootcheck fn_syscheck pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) -echo -en "\r\033[K[ .... ] Stopping ${servicename}: ${servername}" +fn_printdots "Stopping ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Stopping ${servername}" -sleep 0.5 if [ "${pid}" == "0" ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Stopping ${servicename}: ${servername} is already stopped" + fn_printfail "Stopping ${servicename}: ${servername} is already stopped" fn_scriptlog "${servername} is already stopped" else tmux kill-session -t ${servicename} - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Stopping ${servicename}: ${servername}" + fn_printok "Stopping ${servicename}: ${servername}" fn_scriptlog "Stopped ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -467,14 +521,14 @@ if [ ${tmuxwc} -eq 0 ]; then mv "${scriptlog}" "${scriptlogdate}" mv "${consolelog}" "${consolelogdate}" fi -echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}" +fn_printdots "Starting ${servicename}: ${servername}" +sleep 1 fn_scriptlog "Starting ${servername}" -sleep 0.5 if [ ${tmuxwc} -eq 1 ]; then - echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] Starting ${servicename}: ${servername} is already running" - fn_scriptlog "${servername} is already running" - sleep 0.5 + fn_printinfo "Starting ${servicename}: ${servername} is already running" + sleep 1 echo -en "\n" + fn_scriptlog "${servername} is already running" exit fi cd "${executabledir}" @@ -482,13 +536,13 @@ tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolel sleep 1 tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l) if [ ${tmuxwc} -eq 0 ]; then - echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Starting ${servicename}: Failed to start ${servername}" + fn_printfail "Starting ${servicename}: Failed to start ${servername}" fn_scriptlog "failed to start ${servername}" else - echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}" + fn_printok "Starting ${servicename}: ${servername}" fn_scriptlog "Started ${servername}" fi -sleep 0.5 +sleep 1 echo -en "\n" } @@ -509,14 +563,13 @@ webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=/ echo "" echo "${gamename} Server Details" echo "============================" -echo "" echo "Server name: ${servername}" echo "Server IP: ${ip}:${gameport}" echo "Config file: ${systemdir}/${ini}" echo "" echo "${servername} Ports" -echo "=======================" -echo "Ports the server is currently using" +echo "============================" +echo "Ports the server is currently using." echo "" echo "DIRECTION DESCRIPTION PORT INI VARIABLE" echo "INBOUND Game Port ${gameport} UDP Port=${gameport}" @@ -614,7 +667,7 @@ fi echo "Running MD5 checksum to verify the file" sleep 1 echo "MD5 checksum: 10cd7353aa9d758a075c600a6dd193fd" -md5check=$(md5sum ut-server-436.tar.gz| awk '{print $1;}') +md5check=$(md5sum ut-server-436.tar.gz|awk '{print $1;}') echo "File returned: ${md5check}" if [ "${md5check}" != "10cd7353aa9d758a075c600a6dd193fd" ]; then echo "MD5 checksum: FAILED!" @@ -635,7 +688,7 @@ fi echo "Running MD5 checksum to verify the file" sleep 1 echo "MD5 checksum: 77a735a78b1eb819042338859900b83b" -md5check=$(md5sum UTPGPatch451.tar.bz2| awk '{print $1;}') +md5check=$(md5sum UTPGPatch451.tar.bz2|awk '{print $1;}') echo "File returned: ${md5check}" if [ "${md5check}" != "77a735a78b1eb819042338859900b83b" ]; then echo "MD5 checksum: FAILED!" @@ -675,7 +728,7 @@ done while true; do read -p "Remove ut-server-436.tar.gz? [y/N]" yn case $yn in - [Yy]* ) rm -fv ut-server-436.tar.gz;break;; + [Yy]* ) rm -fv ut-server-436.tar.gz; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac @@ -750,7 +803,7 @@ echo "Configuring ${gamename} Server" echo "=================================" sleep 1 echo "Copying "${defaultcfg}" to ${systemdir}/${ini}" - tr -d '\r' < "${defaultcfg}" > ${systemdir}/${ini} + tr -d '\r' < "${defaultcfg}" > "${systemdir}/${ini}" sleep 1 echo "Enabling UdpServerUplink" { @@ -760,19 +813,19 @@ echo "=================================" echo "MasterServerAddress=unreal.epicgames.com" echo "MasterServerPort=27900" echo "Region=0" - }|tee -a ${systemdir}/${ini} > /dev/null 2>&1 + }|tee -a "${systemdir}/${ini}" > /dev/null 2>&1 sleep 1 echo "Removing dead mplayer.com master server" - sed -i '/master.mplayer.com/d' ${systemdir}/${ini} + sed -i '/master.mplayer.com/d' "${systemdir}/${ini}" sleep 1 echo "Inserting qtracker.com master server" - sed -i '66i\ServerActors=IpServer.UdpServerUplink MasterServerAddress=master.qtracker.com MasterServerPort=27900' ${systemdir}/${ini} + sed -i '66i\ServerActors=IpServer.UdpServerUplink MasterServerAddress=master.qtracker.com MasterServerPort=27900' "${systemdir}/${ini}" sleep 1 echo "Enabling WebAdmin" - sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini} + sed -i 's/bEnabled=False/bEnabled=True/g' "${systemdir}/${ini}" sleep 1 echo "Setting WebAdmin port to 8076" - sed -i '467i\ListenPort=8076' ${systemdir}/${ini} + sed -i '467i\ListenPort=8076' "${systemdir}/${ini}" sleep 1 fn_header