Browse Source

Major Update 240114

Mainly updates to make it easier to merger server versions
Improved installer
Insurgency Server added
Fixed fn_autoip not functioning as excpected
various other fixes
pull/62/head
Daniel Gibbs 11 years ago
parent
commit
70d3bf7c7d
  1. 382
      CounterStrike/csserver
  2. 384
      CounterStrikeConditionZero/csczserver
  3. 357
      CounterStrikeGlobalOffensive/csgoserver
  4. 349
      CounterStrikeSource/cssserver
  5. 349
      DayOfDefeatSource/dodsserver
  6. 348
      HalfLife2Deathmatch/hl2dmserver
  7. 754
      Insurgency/insserver
  8. 371
      KillingFloor/kfserver
  9. 221
      Left4Dead2/l4d2server
  10. 378
      NaturalSelection2/ns2server
  11. 404
      NoMoreRoomInHell/nmrihserver
  12. 384
      RedOrchestra/roserver
  13. 35
      ServerQuery/serverquery.py
  14. 349
      TeamFortress2/tf2server
  15. 382
      UnrealTournament2004/ut2k4server
  16. 368
      UnrealTournament99/ut99server

382
CounterStrike/csserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -12,14 +12,20 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="de_aztec"
defaultmap="de_dust2"
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}"
}
#### Advanced Variables ####
@ -35,16 +41,21 @@ engine="goldsource"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/cstrike/${servicename}.cfg"
systemdir="${filesdir}/cstrike"
executabledir="${filesdir}"
executable="./hlds_run"
servercfg="${systemdir}/${servicename}.cfg"
defaultcfg="${systemdir}/server.cfg"
backupdir="backups"
steamclient="${filesdir}/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/cstrike/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -60,6 +71,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -68,8 +83,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -77,42 +92,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -120,6 +135,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -128,6 +144,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -140,11 +159,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./hlds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -170,7 +189,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -203,7 +222,7 @@ while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
@ -222,14 +241,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -255,7 +274,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -279,19 +298,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -299,7 +318,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -307,7 +326,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -317,23 +336,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -346,13 +365,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -370,11 +389,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -384,41 +403,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -428,14 +447,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -445,15 +464,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -463,65 +482,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./hlds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo "start parameters in ${selfname}."
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -529,11 +553,23 @@ echo ""
## Installer
#
fn_csappmanifest(){
echo "Downloading appmanifest files (app 90 fix)"
echo "================================="
sleep 1
mkdir -v "${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5"
cd "${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5"
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_10.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_70.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_90.acf
echo ""
}
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -541,19 +577,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -570,20 +660,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -597,62 +686,24 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
rm -f ${servercfg}
mkdir -v ${filesdir}
echo ""
echo "Downloading appmanifest files (app 90 fix)"
echo "================================="
sleep 2
mkdir -v ${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5
cd ${filesdir}/ec5da605084840d3d7b3ed355e48c098b28a1bd5
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_10.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_70.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrike/appmanifest/appmanifest_90.acf
echo "Downloading appmanifest files (app 90 fix)"
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_csappmanifest
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/cstrike/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/cstrike/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
touch ${filesdir}/cstrike/listip.cfg
touch ${filesdir}/cstrike/banned.cfg
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
touch "${systemdir}/listip.cfg"
touch "${systemdir}/banned.cfg"
{
echo -e "// Use this file to configure your DEDICATED server."
echo -e "// This config file is executed on server start."
@ -691,28 +742,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

384
CounterStrikeConditionZero/csczserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 060113
# Version: 240114
#### Variables ####
@ -12,14 +12,20 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="de_aztec"
defaultmap="de_dust2"
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}"
}
#### Advanced Variables ####
@ -35,16 +41,21 @@ engine="goldsource"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/czero/${servicename}.cfg"
systemdir="${filesdir}/czero"
executabledir="${filesdir}"
executable="./hlds_run"
servercfg="${systemdir}/${servicename}.cfg"
defaultcfg="${systemdir}/server.cfg"
backupdir="backups"
steamclient="${filesdir}/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/czero/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -60,6 +71,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -68,8 +83,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -77,42 +92,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -120,6 +135,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -128,6 +144,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -140,11 +159,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./hlds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -170,7 +189,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -203,7 +222,7 @@ while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
@ -222,14 +241,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -255,7 +274,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -279,19 +298,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -299,7 +318,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -307,7 +326,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -317,23 +336,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -346,13 +365,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -370,11 +389,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -384,41 +403,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -428,14 +447,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -445,15 +464,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -463,65 +482,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./hlds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo "start parameters in ${selfname}."
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -529,11 +553,24 @@ echo ""
## Installer
#
fn_csczappmanifest(){
echo "Downloading appmanifest files (app 90 fix)"
echo "================================="
sleep 1
mkdir -v "${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f"
cd "${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f"
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_10.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_70.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_80.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_90.acf
echo ""
}
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -541,19 +578,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -570,20 +661,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -597,63 +687,24 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
rm -f ${servercfg}
mkdir -v ${filesdir}
echo ""
echo "Downloading appmanifest files (app 90 fix)"
echo "================================="
sleep 2
mkdir -v ${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f
cd ${filesdir}/1ea271ace3aa6eb2cbade5b6f37851d19ffb9e6f
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_10.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_70.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_80.acf
wget https://raw.github.com/dgibbs64/linuxgameservers/master/CounterStrikeConditionZero/appmanifest/appmanifest_90.acf
echo "Downloading appmanifest files (app 90 fix)"
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall ;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_csczappmanifest
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/czero/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/czero/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
touch ${filesdir}/czero/listip.cfg
touch ${filesdir}/czero/banned.cfg
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
touch "${systemdir}/listip.cfg"
touch "${systemdir}/banned.cfg"
{
echo -e "// Use this file to configure your DEDICATED server."
echo -e "// This config file is executed on server start."
@ -692,28 +743,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

357
CounterStrikeGlobalOffensive/csgoserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -12,6 +12,10 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
# [Game Modes] game_mode game_type
# Classic Casual 0 0
@ -20,16 +24,28 @@ email="[email protected]"
# Demolition 1 1
gamemode="0"
gametype="0"
<<<<<<< HEAD
defaultmap="de_dust"
mapgroup="random_classic"
maxplayers="16"
=======
defaultmap="de_dust2"
mapgroup="random_classic"
>>>>>>> Major update 240114
port="27015"
sourcetvport="27020"
clientport="27005"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
<<<<<<< HEAD
# Change the parameter "-maxplayers" to "-maxplayers_override" for force the max player limit
parms="-game csgo -usercon +map ${defaultmap} +mapgroup ${defaultmap} +game_mode ${gamemode} +game_type ${gametype} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
=======
# 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}"
}
>>>>>>> Major update 240114
#### Advanced Variables ####
@ -45,16 +61,21 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/csgo/cfg/${servicename}.cfg"
systemdir="${filesdir}/csgo"
executabledir="${filesdir}"
executable="./srcds_run"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/csgo/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -70,6 +91,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -78,8 +103,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -87,42 +112,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -130,6 +155,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -138,6 +164,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -150,11 +179,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./srcds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -180,7 +209,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -213,7 +242,7 @@ while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
@ -232,14 +261,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -265,7 +294,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -289,19 +318,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -309,7 +338,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -317,7 +346,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -327,23 +356,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -356,13 +385,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -380,11 +409,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -394,41 +423,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -438,14 +467,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -455,15 +484,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -473,65 +502,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo "start parameters in ${selfname}."
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -543,7 +577,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -551,19 +585,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -580,20 +668,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -607,44 +694,21 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/csgo/cfg/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/csgo/cfg/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
@ -661,28 +725,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

349
CounterStrikeSource/cssserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -12,15 +12,21 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="de_dust"
defaultmap="de_dust2"
port="27015"
sourcetvport="27020"
clientport="27005"
maxplayers="16"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
fn_parms(){
parms="-game cstrike +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}"
}
#### Advanced Variables ####
@ -36,16 +42,21 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/cstrike/cfg/${servicename}.cfg"
systemdir="${filesdir}/cstrike"
executabledir="${filesdir}"
executable="./srcds_run"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/cstrike/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -61,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -69,8 +84,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -78,42 +93,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -121,6 +136,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -129,6 +145,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -141,11 +160,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./srcds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -171,7 +190,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -223,14 +242,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -256,7 +275,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -280,19 +299,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -300,7 +319,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -308,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -318,23 +337,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -347,13 +366,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -371,11 +390,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -385,41 +404,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -429,14 +448,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -446,15 +465,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -464,65 +483,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo "start parameters in ${selfname}."
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -534,7 +558,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -542,19 +566,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -571,20 +649,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -598,44 +675,21 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/cstrike/cfg/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/cstrike/cfg/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
@ -652,28 +706,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

349
DayOfDefeatSource/dodsserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -12,6 +12,10 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="dod_Anzio"
port="27015"
@ -20,7 +24,9 @@ clientport="27005"
maxplayers="16"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
fn_parms(){
parms="-game dod +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}"
}
#### Advanced Variables ####
@ -36,16 +42,21 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/dod/cfg/${servicename}.cfg"
systemdir="${filesdir}/dod"
executabledir="${filesdir}"
executable="./srcds_run"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/dod/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -61,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -69,8 +84,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -78,42 +93,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -121,6 +136,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -129,6 +145,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -141,11 +160,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./srcds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -171,7 +190,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -204,7 +223,7 @@ while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
@ -223,14 +242,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -256,7 +275,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -280,19 +299,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -300,7 +319,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -308,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -318,23 +337,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -347,13 +366,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -371,11 +390,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -385,41 +404,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -429,14 +448,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -446,15 +465,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -464,65 +483,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo "start parameters in ${selfname}."
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -534,7 +558,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -542,19 +566,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -571,20 +649,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -598,44 +675,21 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/dod/cfg/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/dod/cfg/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
@ -652,28 +706,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

348
HalfLife2Deathmatch/hl2dmserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -12,6 +12,10 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="dm_lockdown"
port="27015"
@ -20,7 +24,9 @@ clientport="27005"
maxplayers="16"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
parms="-game hl2mp +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
fn_parms(){
parms="-game hl2mp +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}"
}
#### Advanced Variables ####
@ -29,7 +35,6 @@ appid="232370"
# Server Details
servicename="hl2dm-server"
gamename="Half Life 2: Deathmatch"
engine="source"
@ -37,16 +42,21 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/hl2mp/cfg/${servicename}.cfg"
systemdir="${filesdir}/hl2mp"
executabledir="${filesdir}"
executable="./srcds_run"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/hl2mp/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -62,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -70,8 +84,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -79,42 +93,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -122,6 +136,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -130,6 +145,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -142,11 +160,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./srcds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -172,7 +190,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -224,14 +242,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -257,7 +275,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -281,19 +299,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -301,7 +319,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -309,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -319,23 +337,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -348,13 +366,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -372,11 +390,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -386,41 +404,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -430,14 +448,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -447,15 +465,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -465,65 +483,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo "start parameters in ${selfname}."
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -535,7 +558,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -543,19 +566,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -572,20 +649,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -599,44 +675,21 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/hl2mp/cfg/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/hl2mp/cfg/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
@ -653,28 +706,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

754
Insurgency/insserver

@ -0,0 +1,754 @@
#!/bin/bash
# Insurgency
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 240114
#### Variables ####
# Notification Email
# (on|off)
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="username"
steampass="password"
# Start Variables
defaultmap="ministry"
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}"
}
#### Advanced Variables ####
# Steam
appid="237410"
# Server Details
servicename="ins-server"
gamename="Insurgency"
engine="source"
# Directorys
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}/insurgency"
executabledir="${filesdir}"
executable="./srcds_linux"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/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')
# Logging
logdays="7"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
scriptlog="${scriptlogdir}/${servicename}-script.log"
consolelog="${consolelogdir}/${servicename}-console.log"
emaillog="${scriptlogdir}/${servicename}-email.log"
scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
##### Script #####
# Do not edit
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] 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"
exit
fi
}
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
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_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
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)
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_scriptlog "Log cleaner removed ${count} log files"
fi
}
fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
echo ""
echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
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_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
fn_rootcheck
fn_syscheck
echo ""
echo "${gamename} Console"
echo "============================"
echo ""
echo "Press \"CTRL+b d\" to exit console"
echo -e "\e[0;31mWARNING!\e[0;39m Do NOT press CTRL+c to exit"
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
echo -en "\r\033[K[ .... ] Starting ${servicename} console"
sleep 0.5
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"
sleep 1
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
while true; do
read -p "Do you want to start the server? [y/N]" yn
case $yn in
[Yy]* ) fn_startserver;break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
}
fn_backupserver(){
fn_rootcheck
fn_syscheck
backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
echo ""
echo "${gamename} Backup"
echo "============================"
echo ""
echo "The following backup will be created."
echo ""
echo "${backupdir}/${backupname}.tar.gz"
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 1 ]; then
echo -e "\e[0;31mWARNING!\e[0;39m ${servicename} is currently running"
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;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
echo -en "\r\033[K[ .... ] 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"
sleep 1
echo -en "\n"
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
fn_scriptlog "Backup complete"
}
fn_distro(){
arch=$(uname -m)
kernel=$(uname -r)
if [ -f /etc/lsb-release ]; then
os=$(lsb_release -s -d)
elif [ -f /etc/debian_version ]; then
os="Debian $(cat /etc/debian_version)"
elif [ -f /etc/redhat-release ]; then
os=$(cat /etc/redhat-release)
else
os="$(uname -s) $(uname -r)"
fi
}
fn_uptime(){
uptime=$(</proc/uptime)
uptime=${uptime%%.*}
minutes=$(( uptime/60%60 ))
hours=$(( uptime/60/60%24 ))
days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
fn_distro
fn_uptime
fn_load
{
echo -e "========================================\n${servicename} details\n========================================\n"
echo -e "Service: ${servicename}"
echo -e "Server: ${servername}"
echo -e "Game: ${gamename}"
echo -e "Failure reason: ${failurereason}"
echo -e "Action Taken: ${actiontaken}\n"
echo -e "========================================\nServer details\n========================================\n"
echo -e "Date: $(date)"
echo -e "Distro: ${os}"
echo -e "Arch: ${arch}"
echo -e "Kernel: ${kernel}"
echo -e "Hostname: $HOSTNAME"
echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m"
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
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}"
sleep 1
echo -en "\n"
}
fn_emailtest(){
fn_rootcheck
fn_syscheck
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
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_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
}
fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
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}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="Failed to query ${servicename}: ${serverquery}"
actiontaken="restarted ${servicename}"
fn_emailnotification
fi
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_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"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
chmod +x -v gsquery.py
exitcode=$?
if [ "${exitcode}" == "0" ]; then
fn_serverquery
else
echo -en "\nUnable to resolve automatically. Please manually fix permissions\n"
owner=$(ls -al gsquery.py|awk '{ print $3 }')
echo "As user ${owner} or root run the following command"
whoami=$(whoami)
echo -en "\nchown ${whoami}:${whoami} gsquery.py\n\n"
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"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
fi
fi
}
fn_monitorserver(){
fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
fn_scriptlog "Monitoring ${servername}"
sleep 1
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_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
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
fn_scriptlog "Monitor is starting ${servername}"
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"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: When updates complete ${servicename} will start"
fn_scriptlog "When updates complete ${servicename} will start"
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_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
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_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_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_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
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
echo -en "\n"
exit
fi
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "============================"
echo "Ports the server is currently using."
echo ""
echo "DIRECTION DESCRIPTION PORT"
echo "INBOUND Game/RCON port ${port}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}."
echo ""
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
#
## Installer
#
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_steamdl(){
echo "Installing SteamCMD"
echo "================================="
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit;;
* ) echo "Please answer yes or no.";;
esac
done
}
fn_install(){
fn_rootcheck
fn_header
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
echo "Install Directory:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steamdl
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
echo -e ""
echo -e "// rcon passsword"
echo -e "rcon_password \"${rconpass}\""
echo -e ""
echo -e "// Server password"
echo -e "sv_password \"\""
echo -e ""
echo -e "// server logging"
echo -e "log on"
echo -e "sv_logbans 1"
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""
echo "To start server type:"
echo "${selfname} start"
echo ""
}
case "$1" in
start)
fn_startserver;;
stop)
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
email-test)
fn_emailtest;;
details)
fn_details;;
backup)
fn_backupserver;;
console)
fn_console;;
debug)
fn_debugserver;;
install)
fn_install;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}"
exit 1;;
esac
exit

371
KillingFloor/kfserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -24,7 +24,10 @@ rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}/System"
executabledir="${systemdir}"
executable="./ucc-bin"
compressedmapsdir="${rootdir}/Maps-Compressed"
defaultcfg="${systemdir}/Default.ini"
backupdir="backups"
# Server Details
@ -32,7 +35,7 @@ servicename="kf-server"
gamename="Killing Floor"
engine="unreal2"
ini="${servicename}.ini"
servername=$(grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g')
servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
ip="0.0.0.0"
# Logging
@ -48,18 +51,24 @@ scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S'
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
# Start Variables
fn_parms(){
defaultmap="KF-BioticsLab.rom"
parms="server ${defaultmap}?game=KFmod.KFGameType?VACSecured=true -nohomedir ini=${ini} log=${logfile}"
# Start Variables for Objective mode
#defaultmap="KFO-Steamland"
#parms="server ${defaultmap}?Game=KFStoryGame.KFStoryGame?VACSecured=true -nohomedir ini=${ini} log=${logfile}"
}
##### Script #####
# Do not edit
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -68,8 +77,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -77,42 +86,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -120,6 +129,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -128,6 +138,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -140,11 +153,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${systemdir}
./ucc-bin ${parms}
cd "${executabledir}"
${executable} ${parms}
}
fn_console(){
@ -170,7 +183,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -222,14 +235,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -255,7 +268,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -279,19 +292,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -299,7 +312,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -307,7 +320,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -317,23 +330,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -346,13 +359,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -370,11 +383,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -384,41 +397,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -428,21 +441,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile}
fi
fi
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -452,15 +458,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -470,32 +476,33 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${systemdir}
tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -503,23 +510,28 @@ echo -en "\n"
fn_utdetails(){
fn_autoip
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
gameport=$(grep Port= "${systemdir}/${ini}"|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= "${systemdir}/${ini}"|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= "${systemdir}/${ini}"|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= "${systemdir}/${ini}"|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= "${systemdir}/${ini}"|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=//g')
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 "======================="
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g')
echo "Ports the server is currently using"
echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
@ -547,16 +559,19 @@ echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}"
echo ""
echo "${servername} WebAdmin"
echo "======================="
echo "WebAdmin URL: http://{$ip}:${webadminport}"
echo "WebAdmin URL: http://${ip}:${webadminport}"
echo "WebAdmin Username: ${webadminuser}"
echo "WebAdmin Password: ${webadminpass}"
echo ""
echo "Config file"
echo "${systemdir}/${ini}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
fn_compressmaps(){
fn_kfcompressmaps(){
fn_rootcheck
clear
echo "${gamename} Map Compressor"
@ -577,52 +592,13 @@ while true; do
* ) echo "Please answer yes or no.";;
esac
done
mkdir ${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
./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir
else
./ucc-bin compress ../Maps/${map} --nohomedir
fi
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
rm -rfv "${filesdir}/Maps/*.uz2"
cd "${systemdir}"
for map in `ls "${filesdir}/Maps"`; do
./ucc-bin compress ../Maps/${map} --nohomedir
done
mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir}
}
fn_steamguard(){
fn_rootcheck
fn_syscheck
clear
fn_header
fn_steamdl
clear
fn_header
echo "If you are gettng an error:"
echo ""
echo "Login Failure: Account Logon Denied Failed."
echo ""
echo "You should now get an email from Steam with a Steam Guard code"
echo ""
read -p "Press [Enter] key to when you have the code..."
clear
fn_header
echo "Please enter Steam Guard Code"
echo "=============================="
echo -n "Code: "
read CODE
touch guard.txt
chmod 0600 guard.txt
echo "set_steam_guard_code $CODE" > guard.txt
echo "login ${steamuser} ${steampass}" >> guard.txt
echo "quit" >> guard.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt
rm guard.txt
cd ../
echo "=============================="
echo "Complete!"
cd ${rootdir}
mv -fv "${filesdir}/Maps/*.uz2" "${compressedmapsdir}"
}
#
@ -633,7 +609,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -641,19 +617,62 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
}
fn_loginstall(){
echo "Creating log directorys"
echo "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -670,20 +689,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${systemdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -697,41 +715,13 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login ${steamuser} ${steampass}" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
echo "Copying ${systemdir}/default.ini to ${systemdir}/${ini}"
cp ${systemdir}/Default.ini ${systemdir}/${ini}
sleep 1
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
echo "Copying "${defaultcfg}" to ${systemdir}/${ini}"
cp "${defaultcfg}" "${systemdir}/${ini}"
sleep 1
echo "Applying WebAdmin ROOst.css fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13"
@ -744,14 +734,14 @@ echo "================================="
sleep 1
echo "Setting WebAdmin username and password"
sed -i 's/AdminName=/AdminName=admin/g' ${systemdir}/${ini}
sed -i 's/AdminPassword=/AdminPassword=kfpass/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}
sleep 1
echo "Forcing server to start to get ports/server name to display correctly"
sleep 1
cd ${rootdir}
cd "${rootdir}"
${selfname} start
sleep 5
${selfname} restart
@ -759,7 +749,9 @@ echo "================================="
${selfname} stop
sleep 5
fn_header
sleep 1
fn_utdetails
sleep 1
echo "================================="
echo "Install Complete!"
echo ""
@ -794,12 +786,9 @@ case "$1" in
install)
fn_install;;
map-compressor)
fn_compressmaps;;
steam-auth)
fn_updateserver
fn_steamguard;;
fn_kfcompressmaps;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor|steam-auth}"
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor}"
exit 1;;
esac
exit

221
Left4Dead2/l4d2server

@ -3,7 +3,11 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
<<<<<<< HEAD
# Version: 251214
=======
# Version: 240114
>>>>>>> Major update 240114
#### Variables ####
@ -12,6 +16,10 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="c5m1_waterfront"
port="27015"
@ -20,7 +28,9 @@ clientport="27005"
maxplayers="16"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
parms="-game left4dead2 +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
fn_parms(){
parms="-game left4dead2 +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}"
}
#### Advanced Variables ####
@ -36,16 +46,26 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/left4dead2/cfg/${servicename}.cfg"
systemdir="${filesdir}/left4dead2"
executabledir="${filesdir}"
executable="./srcds_run"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/steamclient.so"
# Server Details
<<<<<<< HEAD
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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
>>>>>>> Major update 240114
# Logging
logdays="7"
gamelogdir="${filesdir}/left4dead2/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -73,8 +93,13 @@ fi
}
fn_syscheck(){
<<<<<<< HEAD
if [ ! -e "${filesdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
=======
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
>>>>>>> Major update 240114
exit
fi
}
@ -82,12 +107,17 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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
<<<<<<< HEAD
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
=======
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
>>>>>>> Major update 240114
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
@ -102,15 +132,24 @@ if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
<<<<<<< HEAD
if [ `find "${scriptlogdir}"/* -mtime +${logdays} |wc -l` -ne "0" ]; then
=======
if [ `find "${scriptlogdir}"/* -mtime +${logdays}|wc -l` -ne "0" ]; then
>>>>>>> Major update 240114
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] Starting log cleaner"
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
fn_scriptlog "Removing logs older than ${logdays} days"
sleep 1
<<<<<<< HEAD
find "${scriptlogdir}"/* -mtime +${logdays} |tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays} |tee >> "${scriptlog}"
=======
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
>>>>>>> Major update 240114
scriptcount=$(find "${scriptlogdir}/*" -mtime +${logdays}|wc -l)
consolecount=$(find "${consolelogdir}/*" -mtime +${logdays}|wc -l)
count=$((${scriptcount} + ${consolecount}))
@ -125,6 +164,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -133,6 +173,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -145,11 +188,19 @@ 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}"
<<<<<<< HEAD
fn_scriptlog "Started debug mode ${servername} "
sleep 0.5
echo -en "\n"
cd "${filesdir}"
./srcds_run "${parms}" -debug
=======
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd "${executabledir}"
${executable} ${parms} -debug
>>>>>>> Major update 240114
}
fn_console(){
@ -231,7 +282,11 @@ fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd "${rootdir}"
<<<<<<< HEAD
mkdir -p "${backupdir}" > /dev/null 2>&1
=======
mkdir -pv "${backupdir}" > /dev/null 2>&1
>>>>>>> Major update 240114
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
fn_scriptlog "Backup complete"
@ -260,7 +315,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -292,7 +347,11 @@ if [ ! -z "${consolelog}" ]; then
fi
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
<<<<<<< HEAD
tail "${gamelogdir}"/* | grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
=======
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
>>>>>>> Major update 240114
fi
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
@ -322,20 +381,28 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
<<<<<<< HEAD
fn_scriptlog "Detected gsquery.py "
=======
fn_scriptlog "Detected gsquery.py"
>>>>>>> Major update 240114
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
<<<<<<< HEAD
sleep 1
=======
sleep 1
>>>>>>> Major update 240114
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}"
@ -379,7 +446,7 @@ if [ -f gsquery.py ]; then
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -408,7 +475,11 @@ if [ "${updatecheck}" = "0" ]; then
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
fn_scriptlog "Checking session: FAIL"
sleep 1
<<<<<<< HEAD
echo -en "\n"
=======
echo -en "\n"
>>>>>>> Major update 240114
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
@ -416,7 +487,11 @@ if [ "${updatecheck}" = "0" ]; then
fn_emailnotification
fi
fn_scriptlog "Monitor is starting ${servername}"
<<<<<<< HEAD
fn_startserver
=======
fn_startserver
>>>>>>> Major update 240114
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
@ -435,8 +510,13 @@ sleep 0.5
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Updating ${servicename}: ${servername}"
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
<<<<<<< HEAD
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir "${filesdir}" +app_update ${appid} validate +quit |tee -a "${scriptlog}"
=======
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
>>>>>>> Major update 240114
}
fn_restartserver(){
@ -468,6 +548,7 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
@ -484,8 +565,13 @@ if [ ${tmuxwc} -eq 1 ]; then
echo -en "\n"
exit
fi
<<<<<<< HEAD
cd "${filesdir}"
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a '${consolelog}'"
=======
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
>>>>>>> Major update 240114
sleep 1
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
@ -500,33 +586,44 @@ echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
<<<<<<< HEAD
echo "======================="
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')
echo "Ports the server is currently using"
=======
echo "============================"
echo "Ports the server is currently using."
>>>>>>> Major update 240114
echo ""
echo "DIRECTION DESCRIPTION PORT"
echo "INBOUND Game/Rcon Port ${port}"
echo "INBOUND Game/RCON port ${port}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo "start parameters in ${selfname}."
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -538,7 +635,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -546,19 +643,78 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd "${rootdir}"
<<<<<<< HEAD
mkdir -p steamcmd
cd steamcmd
=======
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
>>>>>>> Major update 240114
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -582,13 +738,12 @@ if [ -d "${filesdir}" ]; then
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -602,6 +757,7 @@ while true; do
done
fn_header
fn_steamdl
<<<<<<< HEAD
echo ""
echo "Installing ${gamename} Server"
echo "================================="
@ -629,11 +785,18 @@ echo "================================="
esac
done
fn_header
=======
fn_steaminstall
fn_steamfix
fn_loginstall
>>>>>>> Major update 240114
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
<<<<<<< HEAD
echo ""
echo "Creating server.cfg"
touch "${filesdir}/left4dead2/cfg/server.cfg"
@ -642,6 +805,13 @@ echo "================================="
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
=======
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating ${servicename}.cfg config file."
>>>>>>> Major update 240114
touch "${servercfg}"
{
echo -e "// server name"
@ -662,6 +832,7 @@ echo "================================="
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
<<<<<<< HEAD
echo "Creating log directorys"
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
@ -679,8 +850,12 @@ echo "================================="
mkdir -pv ${HOME}/.steam/sdk32
cp -v "${filesdir}/bin/steamclient.so" "${HOME}/.steam/sdk32/steamclient.so"
sleep 1
=======
>>>>>>> Major update 240114
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

378
NaturalSelection2/ns2server

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -13,21 +13,23 @@ emailnotification="off"
email="[email protected]"
# Steam login
steamuser="username"
steampass="password"
steamuser="dgibbsserver"
steampass="Roundabout1"
# Start Variables
servername="NS2 Server"
defaultmap="ns2_summit"
port="27015"
webdomain="127.0.0.1"
maxplayers="24"
ip="0.0.0.0"
servername="NS2 Server"
webadminuser="admin"
webadminpass="test123"
webadminpass="admin"
webadminport="8080"
maxplayers="24"
password=""
parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${webdomain} -webuser ${webadminuser} -webpassword ${webadminpass} -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -password ${password}"
fn_parms(){
parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${ip} -webuser ${webadminuser} -webpassword ${webadminpass} -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -password ${password}"
}
#### Advanced Variables ####
# Steam
@ -37,17 +39,20 @@ appid="4940"
servicename="ns2-server"
gamename="Natural Selection 2"
engine="spark"
ip="0.0.0.0"
# Directorys
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}"
executabledir="${filesdir}"
executable="./server_linux32"
backupdir="backups"
steamclient="${filesdir}/steamclient.so"
# Logging
logdays="7"
gamelogdir="${filesdir}/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -63,6 +68,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -71,8 +80,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -80,42 +89,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -123,6 +132,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -131,6 +141,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -143,11 +156,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./server_linux32 ${parms}
cd "${executabledir}"
${executable} ${parms}
}
fn_console(){
@ -173,7 +186,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -225,14 +238,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -258,7 +271,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -282,19 +295,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -302,7 +315,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -310,7 +323,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -320,23 +333,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -349,13 +362,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -373,11 +386,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -387,41 +400,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -431,21 +444,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile}
fi
fi
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -455,15 +461,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -473,32 +479,33 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./server_linux32 ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -507,73 +514,58 @@ echo -en "\n"
fn_ns2details(){
fn_autoip
queryport=$((${port} + 1))
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo ""
echo "${servername} Ports"
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 ""
echo "${servername} WebAdmin"
echo "======================="
echo "WebAdmin URL: http://${ip}:${webadminport}"
echo "WebAdmin URL: http://${ip}:${webadminport}/index.html"
echo "WebAdmin Username: ${webadminuser}"
echo "WebAdmin Password: ${webadminpass}"
echo ""
echo "You can change various parameters by editing the"
echo "start parameters in ${selfname}"
echo ""
}
fn_steamguard(){
fn_rootcheck
fn_syscheck
clear
fn_header
fn_steamdl
clear
fn_header
echo "If you are gettng an error:"
echo ""
echo "Login Failure: Account Logon Denied Failed."
echo ""
echo "You should now get an email from Steam with a Steam Guard code"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
read -p "Press [Enter] key to when you have the code..."
clear
fn_header
echo "Please enter Steam Guard Code"
echo "=============================="
echo -n "Code: "
read CODE
touch guard.txt
chmod 0600 guard.txt
echo "set_steam_guard_code $CODE" > guard.txt
echo "login ${steamuser} ${steampass}" >> guard.txt
echo "quit" >> guard.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt
rm guard.txt
cd ../
echo "=============================="
echo "Complete!"
cd ${rootdir}
}
#
## Installer
#
fn_ns2deps(){
echo "Downloading libm.so.6 and libstdc++.so.6"
echo "================================="
cd "${filesdir}"
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libm.so.6
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libstdc++.so.6
sleep 1
echo ""
}
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -581,19 +573,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -610,20 +656,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -637,58 +682,14 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login ${steamuser} ${steampass}" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
echo "Downloading libm.so.6 and libstdc++.so.6"
echo "================================="
cd ${filesdir}
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libm.so.6
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NaturalSelection2/dependencies/libstdc++.so.6
sleep 2
fn_header
fn_header
echo "Configuring ${gamename} Server"
echo "================================="
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_steaminstall
fn_steamfix
fn_loginstall
fn_ns2deps
fn_header
sleep 1
fn_ns2details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""
@ -722,11 +723,8 @@ case "$1" in
fn_debugserver;;
install)
fn_install;;
steam-auth)
fn_updateserver
fn_steamguard;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|steam-auth}"
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}"
exit 1;;
esac
exit

404
NoMoreRoomInHell/nmrihserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -24,7 +24,7 @@ clientport="27005"
maxplayers="8"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
parms="+map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}"
#### Advanced Variables ####
@ -40,16 +40,21 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/nmrih/cfg/${servicename}.cfg"
systemdir="${filesdir}/nmrih"
executabledir="${filesdir}/srcds"
executable="./srcds_nmrih"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/srcds/bin/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/nmrih/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -65,6 +70,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -73,8 +82,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -82,42 +91,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -125,6 +134,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -133,6 +143,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -145,11 +158,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}/srcds
./srcds_nmrih ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -175,7 +188,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -227,14 +240,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -260,7 +273,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -284,19 +297,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -304,7 +317,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -312,7 +325,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -322,23 +335,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -351,13 +364,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -375,11 +388,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -389,41 +402,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -433,21 +446,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile}
fi
fi
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -457,15 +463,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -475,111 +481,92 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}/srcds
tmux new-session -d -s ${servicename} "./srcds_nmrih ${parms} -debug|tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo ""
echo "Config file:"
echo "${servercfg}"
echo ""
}
fn_steamguard(){
fn_rootcheck
fn_syscheck
clear
fn_header
fn_steamdl
clear
fn_header
echo "If you are gettng an error:"
echo ""
echo "Login Failure: Account Logon Denied Failed."
echo "start parameters in ${selfname}."
echo ""
echo "You should now get an email from Steam with a Steam Guard code"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
read -p "Press [Enter] key to when you have the code..."
clear
fn_header
echo "Please enter Steam Guard Code"
echo "=============================="
echo -n "Code: "
read CODE
touch guard.txt
chmod 0600 guard.txt
echo "set_steam_guard_code $CODE" > guard.txt
echo "login ${steamuser} ${steampass}" >> guard.txt
echo "quit" >> guard.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt
rm guard.txt
cd ../
echo "=============================="
echo "Complete!"
cd ${rootdir}
}
#
## Installer
#
fn_nmrihdeps(){
echo "Downloading libm.so.6"
echo "================================="
sleep 1
cd "${filesdir}/srcds"
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NoMoreRoomInHell/dependencies/libm.so.6
sleep 1
echo ""
}
fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -587,19 +574,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -616,20 +657,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -643,50 +683,22 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login ${steamuser} ${steampass}" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Downloading libm.so.6"
echo "================================="
cd ${filesdir}/srcds
wget https://github.com/dgibbs64/linuxgameservers/raw/master/NoMoreRoomInHell/dependencies/libm.so.6
sleep 2
fn_header
fn_steaminstall
fn_steamfix
fn_loginstall
fn_nmrihdeps
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/nmrih/cfg/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/nmrih/cfg/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
@ -703,28 +715,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/srcds/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""
@ -758,11 +755,8 @@ case "$1" in
fn_debugserver;;
install)
fn_install;;
steam-auth)
fn_updateserver
fn_steamguard;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|steam-auth}"
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install}"
exit 1;;
esac
exit

384
RedOrchestra/roserver

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -24,7 +24,10 @@ rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}/system"
executabledir="${systemdir}"
executable="./ucc-bin"
compressedmapsdir="${rootdir}/Maps-Compressed"
defaultcfg="${systemdir}/default.ini"
backupdir="backups"
# Server Details
@ -32,7 +35,7 @@ servicename="ro-server"
gamename="Red Orchestra: Ostfront 41-45"
engine="unreal2"
ini="${servicename}.ini"
servername=$(grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g')
servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
ip="0.0.0.0"
# Logging
@ -48,14 +51,20 @@ scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S'
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
# Start Variables
fn_parms(){
defaultmap="RO-Arad.rom"
parms="server ${defaultmap}?game=ROGame.ROTeamGame?VACSecured=true -nohomedir ini=${ini} log=${logfile}"
}
##### Script #####
# Do not edit
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -64,8 +73,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${systemdir} ];then
echo -e "[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -73,42 +82,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -116,6 +125,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -124,6 +134,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -136,11 +149,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${systemdir}
./ucc-bin ${parms}
cd "${executabledir}"
${executable} ${parms}
}
fn_console(){
@ -166,7 +179,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -218,14 +231,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -251,7 +264,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -275,19 +288,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -295,7 +308,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -303,7 +316,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -313,23 +326,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -342,13 +355,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -366,11 +379,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -380,41 +393,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -424,21 +437,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${logfile}
if [ $(grep Denied ${logfile}|wc -l) -ge 1 ];then
echo -e "[\e[0;31m FAIL \e[0;39m] ${servicename}: STEAMAUTH error detected!: Server update failed"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: STEAMAUTH error detected!: Server update failed" >> ${logfile}
if [ "${emailnotification}" = "on" ];then
mail -s "${servername}: Steam Auth Failure" ${email}< ${logfile}
fi
fi
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -448,15 +454,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -466,32 +472,33 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${systemdir}
tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -499,23 +506,28 @@ echo -en "\n"
fn_utdetails(){
fn_autoip
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
gameport=$(grep Port= "${systemdir}/${ini}"|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= "${systemdir}/${ini}"|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= "${systemdir}/${ini}"|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= "${systemdir}/${ini}"|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= "${systemdir}/${ini}"|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=//g')
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 "======================="
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g')
echo "Ports the server is currently using"
echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
@ -543,16 +555,19 @@ echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}"
echo ""
echo "${servername} WebAdmin"
echo "======================="
echo "WebAdmin URL: http://{$ip}:${webadminport}"
echo "WebAdmin URL: http://${ip}:${webadminport}"
echo "WebAdmin Username: ${webadminuser}"
echo "WebAdmin Password: ${webadminpass}"
echo ""
echo "Config file"
echo "${systemdir}/${ini}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
fn_compressmaps(){
fn_kfcompressmaps(){
fn_rootcheck
clear
echo "${gamename} Map Compressor"
@ -573,52 +588,13 @@ while true; do
* ) echo "Please answer yes or no.";;
esac
done
mkdir ${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
./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir
else
./ucc-bin compress ../Maps/${map} --nohomedir
fi
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
rm -rfv "${filesdir}/Maps/*.uz2"
cd "${systemdir}"
for map in `ls "${filesdir}/Maps"`; do
./ucc-bin compress ../Maps/${map} --nohomedir
done
mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir}
}
fn_steamguard(){
fn_rootcheck
fn_syscheck
clear
fn_header
fn_steamdl
clear
fn_header
echo "If you are gettng an error:"
echo ""
echo "Login Failure: Account Logon Denied Failed."
echo ""
echo "You should now get an email from Steam with a Steam Guard code"
echo ""
read -p "Press [Enter] key to when you have the code..."
clear
fn_header
echo "Please enter Steam Guard Code"
echo "=============================="
echo -n "Code: "
read CODE
touch guard.txt
chmod 0600 guard.txt
echo "set_steam_guard_code $CODE" > guard.txt
echo "login ${steamuser} ${steampass}" >> guard.txt
echo "quit" >> guard.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript guard.txt
rm guard.txt
cd ../
echo "=============================="
echo "Complete!"
cd ${rootdir}
mv -fv "${filesdir}/Maps/*.uz2" "${compressedmapsdir}"
}
#
@ -629,7 +605,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -637,19 +613,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -666,20 +696,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${systemdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -693,41 +722,13 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login ${steamuser} ${steampass}" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
echo "Copying ${systemdir}/default.ini to ${systemdir}/${ini}"
cp ${systemdir}/default.ini ${systemdir}/${ini}
sleep 1
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
echo "Copying "${defaultcfg}" to ${systemdir}/${ini}"
cp "${defaultcfg}" "${systemdir}/${ini}"
sleep 1
echo "Applying WebAdmin ROOst.css fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13"
@ -736,18 +737,18 @@ echo "================================="
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=kfpass/g' ${systemdir}/${ini}
sed -i 's/AdminPassword=/AdminPassword=ropass/g' ${systemdir}/${ini}
sleep 1
echo "Enabling WebAdmin"
sed -i 's/bEnabled=False/bEnabled=True/g' ${systemdir}/${ini}
sleep 1
echo "Forcing server to start to get ports/server name to display correctly"
sleep 1
cd ${rootdir}
cd "${rootdir}"
${selfname} start
sleep 5
${selfname} restart
@ -755,7 +756,9 @@ echo "================================="
${selfname} stop
sleep 5
fn_header
sleep 1
fn_utdetails
sleep 1
echo "================================="
echo "Install Complete!"
echo ""
@ -790,12 +793,9 @@ case "$1" in
install)
fn_install;;
map-compressor)
fn_compressmaps;;
steam-auth)
fn_updateserver
fn_steamguard;;
fn_kfcompressmaps;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor|steam-auth}"
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor}"
exit 1;;
esac
exit

35
ServerQuery/serverquery.py

@ -1,35 +0,0 @@
#!/usr/bin/python
# serverquery.py part of
# Server Management Script
#
# Website: http://danielgibbs.co.uk
# Version: 010813
import errno
import sys
import socket
import re
if __name__ == "__main__":
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.settimeout(0.5)
ip = sys.argv[1]
port = sys.argv[2]
try:
sock.connect((ip, int(port)))
except socket.error:
sys.exit("ERROR 1")
sock.send("\xFF\xFF\xFF\xFFTSource Engine Query\0")
data = ""
try:
data = sock.recv(1024)
except socket.error:
sys.exit("ERROR 2")
sock.close()
if(len(data) > 10):
sys.exit("OK")
sys.exit("ERROR 3")

349
TeamFortress2/tf2server

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -12,6 +12,10 @@
emailnotification="off"
email="[email protected]"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
defaultmap="ctf_2fort"
port="27015"
@ -20,7 +24,9 @@ clientport="27005"
maxplayers="16"
ip="0.0.0.0"
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
parms="-game tf +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +tv_port ${sourcetvport} +clientport ${clientport} -maxplayers ${maxplayers}"
fn_parms(){
parms="-game tf +map ${defaultmap} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -maxplayers ${maxplayers}"
}
#### Advanced Variables ####
@ -36,16 +42,21 @@ engine="source"
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
servercfg="${filesdir}/tf/cfg/${servicename}.cfg"
systemdir="${filesdir}/tf"
executabledir="${filesdir}"
executable="./srcds_run"
servercfg="${systemdir}/cfg/${servicename}.cfg"
defaultcfg="${systemdir}/cfg/server.cfg"
backupdir="backups"
steamclient="${filesdir}/bin/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 "${servercfg}"|sed 's/hostname //g'|sed 's/"//g')
rcon=$(grep -s rcon_password "${servercfg}"|sed 's/rcon_password //g'|sed 's/"//g')
# Logging
logdays="7"
gamelogdir="${filesdir}/tf/logs"
gamelogdir="${systemdir}/logs"
scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
@ -61,6 +72,10 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -69,8 +84,8 @@ fi
}
fn_syscheck(){
if [ ! -e ${filesdir} ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${filesdir}: No such directory"
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
}
@ -78,42 +93,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -121,6 +136,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -129,6 +145,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -141,11 +160,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${filesdir}
./srcds_run ${parms} -debug
cd "${executabledir}"
${executable} ${parms} -debug
}
fn_console(){
@ -171,7 +190,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -204,7 +223,7 @@ while true; do
read -p "Continue? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
@ -223,14 +242,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -256,7 +275,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -280,19 +299,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -300,7 +319,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -308,7 +327,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -318,23 +337,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -347,13 +366,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -371,11 +390,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -385,41 +404,41 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
@ -429,14 +448,14 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Updating ${servername}" >> ${scriptlog}
cd ${rootdir}
cd steamcmd
./steamcmd.sh +login anonymous +force_install_dir ${filesdir} +app_update ${appid} validate +quit |tee -a ${scriptlog}
fn_scriptlog "Updating ${servername}"
cd "${rootdir}"
cd "steamcmd"
./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit|tee -a "${scriptlog}"
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -446,15 +465,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -464,65 +483,70 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${filesdir}
tmux new-session -d -s ${servicename} "./srcds_run ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
}
fn_details(){
fn_autoip
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')
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
echo ""
echo "${gamename} Server Details"
echo "============================"
echo "Server name: ${servername}"
echo "Server IP: ${ip}:${port}"
echo "RCON password: ${rcon}"
echo "Config file: ${servercfg}"
echo ""
echo "${servername} Ports"
echo "======================="
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')
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}"
if [ "${engine}" = "source" ]; then
echo "INBOUND SourceTV Port ${sourcetvport}"
echo "INBOUND SourceTV port ${sourcetvport}"
fi
echo "OUTBOUND Client Port ${clientport}"
echo "OUTBOUND Client port ${clientport}"
echo ""
echo "You can change ports by editing the"
echo "start parameters in ${selfname}"
echo "start parameters in ${selfname}."
echo ""
echo "${servername} Details"
echo "======================="
echo "Server name: ${servername}"
echo "Rcon Password: ${rcon}"
echo ""
echo "Config file:"
echo "${servercfg}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
@ -534,7 +558,7 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
@ -542,19 +566,73 @@ echo ""
}
fn_steamdl(){
echo "Installing Steam"
echo "Installing SteamCMD"
echo "================================="
cd ${rootdir}
mkdir steamcmd
cd steamcmd
cd "${rootdir}"
mkdir -pv "steamcmd"
sleep 1
cd "steamcmd"
if [ ! -f steamcmd.sh ]; then
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar --verbose -zxf steamcmd_linux.tar.gz
rm -v steamcmd_linux.tar.gz
chmod +x steamcmd.sh
sleep 1
else
echo ""
echo "Steam already installed!"
fi
sleep 1
echo ""
}
fn_steaminstall(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${rootdir}/steamcmd"
STEAMEXE=steamcmd ./steamcmd.sh +login ${steamuser} ${steampass} +force_install_dir "${filesdir}" +app_update ${appid} validate +quit
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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 "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
if [ ! -h ${rootdir}/log/server ]; then
ln -sv "${gamelogdir}" "${rootdir}/log/server"
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
}
fn_retryinstall(){
@ -571,20 +649,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${filesdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -598,44 +675,21 @@ while true; do
done
fn_header
fn_steamdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
cd ${rootdir}/steamcmd
mkdir -v ${filesdir}
touch install.txt
chmod 0600 install.txt
echo "login anonymous" > install.txt
echo "force_install_dir ${filesdir}" >> install.txt
echo "app_update ${appid} validate" >> install.txt
echo "quit" >> install.txt
STEAMEXE=steamcmd ./steamcmd.sh +runscript install.txt
rm install.txt
echo ""
echo "================================="
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
fn_header
fn_steaminstall
fn_steamfix
fn_loginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
read -p "Enter server name: " servername
read -p "Enter rcon password: " rconpass
sleep 1
echo ""
echo "Creating server.cfg"
touch ${filesdir}/tf/cfg/server.cfg
echo "exec ${servicename}.cfg" > ${filesdir}/tf/cfg/server.cfg
echo "Creating server.cfg."
touch "${defaultcfg}"
echo "exec ${servicename}.cfg" > "${defaultcfg}"
sleep 1
echo "Creating default config file:"
sleep 0.5
echo "${servercfg}"
touch ${servercfg}
echo "Creating ${servicename}.cfg config file."
touch "${servercfg}"
{
echo -e "// server name"
echo -e "hostname \"${servername}\""
@ -652,28 +706,13 @@ echo "================================="
echo -e "sv_logecho 1"
echo -e "sv_logfile 1"
echo -e "sv_log_onefile 0"
}|tee ${servercfg} > /dev/null 2>&1
}|tee "${servercfg}" > /dev/null 2>&1
sleep 1
echo ""
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
if [ ! -h ${rootdir}/log/server ]; then
ln -sv ${gamelogdir} ${rootdir}/log/server
else
echo "Symbolic link ${gamelogdir} => ${rootdir}/log/server already exists!"
fi
sleep 1
echo ""
echo "Applying steamclient.so fix"
mkdir -v ${HOME}/.steam
mkdir -v ${HOME}/.steam/sdk32
cp -v ${filesdir}/bin/steamclient.so ${HOME}/.steam/sdk32/steamclient.so
sleep 1
fn_header
sleep 1
fn_details
sleep 1
echo "================================="
echo "Install Complete!"
echo ""

382
UnrealTournament2004/ut2k4server

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -17,7 +17,11 @@ rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}/System"
executabledir="${systemdir}"
executable="./ucc-bin"
executable64="./ucc-bin-linux-amd64"
compressedmapsdir="${rootdir}/Maps-Compressed"
defaultcfg="${systemdir}/UT2004.ini"
backupdir="backups"
# Server Details
@ -25,7 +29,7 @@ servicename="ut2k4-server"
gamename="Unreal Tournament 2004"
engine="unreal2"
ini="${servicename}.ini"
servername=$(grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g')
servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
ip="0.0.0.0"
# Logging
@ -41,14 +45,20 @@ scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S'
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
# Start Variables
fn_parms(){
defaultmap="DM-Rankin"
parms="server ${defaultmap}?game=XGame.xDMGame -nohomedir ini=${ini} log=${logfile}"
}
##### Script #####
# Do not edit
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -57,7 +67,7 @@ fi
}
fn_syscheck(){
if [ ! -e ${systemdir} ]; then
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
@ -66,42 +76,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -109,6 +119,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -117,6 +128,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -129,15 +143,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${systemdir}
cd "${executabledir}"
if [ `getconf LONG_BIT` = "64" ]
then
./ucc-bin-linux-amd64 ${parms}
${executable64} ${parms}
else
./ucc-bin ${parms}
${executable} ${parms}
fi
}
@ -164,7 +178,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -216,14 +230,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -249,7 +263,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -273,19 +287,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -293,7 +307,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -301,7 +315,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -311,23 +325,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -340,13 +354,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -364,11 +378,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -378,46 +392,46 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -427,15 +441,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -445,37 +459,38 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${systemdir}
cd "${executabledir}"
if [ `getconf LONG_BIT` = "64" ]
then
tmux new-session -d -s ${servicename} "./ucc-bin-linux-amd64 ${parms} |tee -a ${consolelog}"
tmux new-session -d -s ${servicename} "${executable64} ${parms}|tee -a '${consolelog}'"
else
tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -483,23 +498,28 @@ echo -en "\n"
fn_utdetails(){
fn_autoip
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
gameport=$(grep Port= "${systemdir}/${ini}"|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= "${systemdir}/${ini}"|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= "${systemdir}/${ini}"|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= "${systemdir}/${ini}"|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= "${systemdir}/${ini}"|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=//g')
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 "======================="
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g')
echo "Ports the server is currently using"
echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
@ -527,16 +547,19 @@ echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}"
echo ""
echo "${servername} WebAdmin"
echo "======================="
echo "WebAdmin URL: http://{$ip}:${webadminport}"
echo "WebAdmin URL: http://${ip}:${webadminport}"
echo "WebAdmin Username: ${webadminuser}"
echo "WebAdmin Password: ${webadminpass}"
echo ""
echo "Config file"
echo "${systemdir}/${ini}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
fn_compressmaps(){
fn_ut2k4compressmaps(){
fn_rootcheck
clear
echo "${gamename} Map Compressor"
@ -557,10 +580,10 @@ while true; do
* ) echo "Please answer yes or no.";;
esac
done
mkdir ${compressedmapsdir} > /dev/null 2>&1
rm -rfv ${filesdir}/Maps/*.uz2
cd ${systemdir}
for map in `ls ${filesdir}/Maps`; do
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
./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir
@ -568,7 +591,7 @@ for map in `ls ${filesdir}/Maps`; do
./ucc-bin compress ../Maps/${map} --nohomedir
fi
done
mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir}
mv -fv "${filesdir}/Maps/*.uz2" "${compressedmapsdir}"
}
#
@ -579,20 +602,19 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_filesdl(){
echo ""
fn_ut2k4filesdl(){
echo "Downloading Server Files"
echo "============================"
cd ${rootdir}
mkdir ${filesdir}
cd ${filesdir}
echo "================================="
cd "${rootdir}"
mkdir -pv "${filesdir}"
cd "${filesdir}"
if [ ! -f dedicatedserver3339-bonuspack.zip ]; then
wget http://downloads.unrealadmin.org/UT2004/Server/dedicatedserver3339-bonuspack.zip
else
@ -601,20 +623,20 @@ fi
echo "Running MD5 checksum to verify the file"
sleep 1
echo "MD5 checksum: d3f28c5245c4c02802d48e4f0ffd3e34"
md5check=$(md5sum dedicatedserver3339-bonuspack.zip| awk '{print $1;}')
md5check=$(md5sum dedicatedserver3339-bonuspack.zip|awk '{print $1;}')
echo "File returned: ${md5check}"
if [ "${md5check}" != "d3f28c5245c4c02802d48e4f0ffd3e34" ]; then
echo "MD5 checksum: FAILED!"
read -p "Retry download? [y/N]" yn
case $yn in
[Yy]* ) rm -f dedicatedserver3339-bonuspack.zip; fn_filesdl;;
[Yy]* ) rm -fv dedicatedserver3339-bonuspack.zip; fn_ut2k4filesdl;;
[Nn]* ) echo Exiting; exit;;
* ) echo "Please answer yes or no.";;
esac
else
echo "MD5 checksum: PASSED"
fi
if [ ! -f ut2004-lnxpatch3369-2.tar.bz2 ];then
if [ ! -f ut2004-lnxpatch3369-2.tar.bz2 ]; then
wget http://downloads.unrealadmin.org/UT2004/Patches/Linux/ut2004-lnxpatch3369-2.tar.bz2
else
echo "ut2004-lnxpatch3369-2.tar.bz2 already downloaded!"
@ -622,19 +644,87 @@ fi
echo "Running MD5 checksum to verify the file"
sleep 1
echo "MD5 checksum: 0fa447e05fe5a38e0e32adf171be405e"
md5check=$(md5sum ut2004-lnxpatch3369-2.tar.bz2| awk '{print $1;}')
md5check=$(md5sum ut2004-lnxpatch3369-2.tar.bz2|awk '{print $1;}')
echo "File returned: ${md5check}"
if [ "${md5check}" != "0fa447e05fe5a38e0e32adf171be405e" ];then
if [ "${md5check}" != "0fa447e05fe5a38e0e32adf171be405e" ]; then
echo "MD5 checksum: FAILED!"
read -p "Retry download? [y/N]" yn
case $yn in
[Yy]* ) rm -f ut2004-lnxpatch3369-2.tar.bz2; fn_filesdl;;
[Yy]* ) rm -fv ut2004-lnxpatch3369-2.tar.bz2; fn_ut2k4filesdl;;
[Nn]* ) echo Exiting; exit;;
* ) echo "Please answer yes or no.";;
esac
else
echo "MD5 checksum: PASSED"
fi
echo ""
}
fn_ut2k4key(){
echo "Enter ${gamename} CD Key"
echo "================================="
sleep 1
echo "To get your server listed on the Master Server list"
echo "you must get a free CD key. Get a key here:"
echo "http://www.unrealtournament.com/ut2004server/cdkey.php"
echo ""
echo "Once you have the key enter it below"
echo -n "KEY: "
read CODE
echo ""\""CDKey"\""="\""${CODE}"\""" > ${systemdir}/cdkey
echo ""
}
fn_ut2k4install(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${filesdir}"
echo "Extracting dedicatedserver3339-bonuspack.zip"
sleep 1
unzip dedicatedserver3339-bonuspack.zip
echo "Extracting ut2004-lnxpatch3369-2.tar.bz2"
sleep 1
tar -xvjf ut2004-lnxpatch3369-2.tar.bz2 UT2004-Patch/ --strip-components=1
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn
case $yn in
[Yy]* ) rm -fv dedicatedserver3339-bonuspack.zip;break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
}
fn_utloginstall(){
echo "Creating log directorys"
echo "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
sleep 1
echo ""
}
fn_retryinstall(){
@ -651,20 +741,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${systemdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -677,68 +766,15 @@ while true; do
esac
done
fn_header
fn_filesdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -v ${filesdir}
cd ${filesdir}
echo "Extracting dedicatedserver3339-bonuspack.zip"
sleep 1
unzip dedicatedserver3339-bonuspack.zip
echo "ut2004-lnxpatch3369-2.tar.bz2"
sleep 1
tar -xvjf ut2004-lnxpatch3369-2.tar.bz2 UT2004-Patch/ --strip-components=1
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Remove ut2004-lnxpatch3369-2.tar.bz2? [y/N]" yn
case $yn in
[Yy]* ) rm -iv ut2004-lnxpatch3369-2.tar.bz2 ; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Remove dedicatedserver3339-bonuspack.zip? [y/N]" yn
case $yn in
[Yy]* ) rm -iv dedicatedserver3339-bonuspack.zip ; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
echo "Enter ${gamename} CD Key"
echo "================================="
sleep 1
echo "To get your server listed on the Master Server list"
echo "you must get a free CD key. Get a key here:"
echo "http://www.unrealtournament.com/ut2004server/cdkey.php"
echo ""
echo "Once you have the key enter it below"
echo -n "KEY: "
read CODE
echo ""\""CDKey"\""="\""${CODE}"\""" > ${systemdir}/cdkey
fn_header
fn_ut2k4filesdl
fn_ut2k4install
fn_ut2k4key
fn_utloginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
echo "Copying ${systemdir}/ut2004.ini to ${systemdir}/${ini}"
cp ${systemdir}/UT2004.ini ${systemdir}/${ini}
sleep 1
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
echo "Copying "${defaultcfg}" to ${systemdir}/${ini}"
cp "${defaultcfg}" "${systemdir}/${ini}"
sleep 1
echo "Applying WebAdmin ut2003.css fix!"
echo "http://forums.tripwireinteractive.com/showpost.php?p=585435&postcount=13"
@ -751,7 +787,7 @@ echo "================================="
sleep 1
echo "Setting WebAdmin username and password"
sed -i 's/AdminName=/AdminName=admin/g' ${systemdir}/${ini}
sed -i 's/AdminPassword=/AdminPassword=utpass/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}
@ -761,7 +797,7 @@ echo "================================="
sleep 1
echo "Forcing server to start to get ports/server name to display correctly"
sleep 1
cd ${rootdir}
cd "${rootdir}"
${selfname} start
sleep 5
${selfname} restart
@ -769,7 +805,9 @@ echo "================================="
${selfname} stop
sleep 5
fn_header
sleep 1
fn_utdetails
sleep 1
echo "================================="
echo "Install Complete!"
echo ""
@ -800,7 +838,7 @@ case "$1" in
install)
fn_install;;
map-compressor)
fn_compressmaps;;
fn_ut2k4compressmaps;;
*)
echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
exit 1;;

368
UnrealTournament99/ut99server

@ -3,7 +3,7 @@
# Server Management Script
# Author: Daniel Gibbs
# Website: http://danielgibbs.co.uk
# Version: 251213
# Version: 240114
#### Variables ####
@ -17,7 +17,10 @@ rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
selfname="$0"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}/System"
executabledir="${systemdir}"
executable="./ucc-bin"
compressedmapsdir="${rootdir}/Maps-Compressed"
defaultcfg="${systemdir}/Default.ini"
backupdir="backups"
# Server Details
@ -25,7 +28,7 @@ servicename="ut99-server"
gamename="Unreal Tournament 99"
engine="unreal"
ini="${servicename}.ini"
servername=$(grep -s ServerName= ${systemdir}/${ini} | sed 's/ServerName=//g')
servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
ip="0.0.0.0"
# Logging
@ -41,14 +44,20 @@ scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S'
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
# Start Variables
fn_parms(){
defaultmap="DM-Deck16]["
parms="server ${defaultmap}.unr ini=${systemdir}/${ini}"
}
##### Script #####
# Do not edit
# unless you know
# what you are doing
fn_scriptlog(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: '$1'" >> ${scriptlog}
}
fn_rootcheck(){
if [ `whoami` = "root" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Script will not run as root!"
@ -57,7 +66,7 @@ fi
}
fn_syscheck(){
if [ ! -e ${systemdir} ]; then
if [ ! -e "${systemdir}" ]; then
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Cannot access ${systemdir}: No such directory"
exit
fi
@ -66,42 +75,42 @@ fi
fn_autoip(){
# Identifies the server interface IP
# If multiple interfaces this will need to be set manually
getip=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1)
getipwc=$(/sbin/ifconfig | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'|grep -v 127.0.0.1|wc -l)
getip=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0.1)
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 interfaces.\n\n"
echo -en "Manually specify the IP in ${selfname}\n"
echo -en "[\e[1;33m WARN \e[0;39m] Multiple active network interfaces.\n\n"
echo -en "Manually specify the IP you want to use in ${selfname}.\n"
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
echo -en "${getip}\n"
exit
else
else
ip=${getip}
fi
fi
}
fn_logmanager(){
if [ ! -e ${consolelog} ]; then
touch ${consolelog}
if [ ! -e "${consolelog}" ]; then
touch "${consolelog}"
fi
# log manager will active if finds logs older than ${logdays}
if [ `find ${scriptlogdir}/* -mtime +${logdays} |wc -l` -ne "0" ]; then
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting log cleaner" >> ${scriptlog}
fn_scriptlog "Starting log cleaner"
sleep 1
echo -e "[\e[0;36m INFO \e[0;39m] Removing logs older than ${logdays} days"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Removing logs older than ${logdays} days" >> ${scriptlog}
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)
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)
count=$((${scriptcount} + ${consolecount}))
find ${scriptlogdir}/* -mtime +${logdays} -exec rm {} \;
find ${consolelogdir}/* -mtime +${logdays} -exec rm {} \;
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Log cleaner removed ${count} log files" >> ${scriptlog}
fn_scriptlog "Log cleaner removed ${count} log files"
fi
}
@ -109,6 +118,7 @@ fn_debugserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
echo ""
echo "${gamename} Debug"
echo "============================"
@ -117,6 +127,9 @@ echo -e "Use for identifying server issues only!"
echo -e "Press CTRL+c to drop out of debug mode"
echo -e "\e[0;31mWARNING!\e[0;39m If ${servicename} is already running it will be stopped"
echo ""
echo "Start parameters:"
echo ${parms}
echo ""
while true; do
read -p "Continue? [y/N]" yn
case $yn in
@ -129,11 +142,11 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started debug mode ${servername} " >> ${scriptlog}
fn_scriptlog "Started debug mode ${servername}"
sleep 0.5
echo -en "\n"
cd ${systemdir}
./ucc-bin ${parms}
cd "${executabledir}"
${executable} ${parms}
}
fn_console(){
@ -159,7 +172,7 @@ sleep 0.5
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Console accessed" >> ${scriptlog}
fn_scriptlog "Console accessed"
sleep 1
tmux attach-session -t ${servicename}
else
@ -211,14 +224,14 @@ fi
echo -en "\r\033[K[ .... ] Starting backup ${servicename}: ${servername}"
sleep 1
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting backup ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup started" >> ${scriptlog}
fn_scriptlog "Backup started"
sleep 1
echo -en "\n"
cd ${rootdir}
mkdir ${backupdir} > /dev/null 2>&1
tar -cvzf ${backupdir}/${backupname}.tar.gz --exclude ${backupdir} *
cd "${rootdir}"
mkdir -pv "${backupdir}" > /dev/null 2>&1
tar -cvzf "${backupdir}/${backupname}.tar.gz" --exclude "${backupdir}" *
echo -en "\r\033[K${servicename} Backup complete"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Backup complete" >> ${scriptlog}
fn_scriptlog "Backup complete"
}
fn_distro(){
@ -244,7 +257,7 @@ days=$(( uptime/60/60/24 ))
}
fn_load(){
load=$(uptime | awk -F 'load average' '{ print $2 }')
load=$(uptime|awk -F 'load average' '{ print $2 }')
}
fn_emailnotification(){
@ -268,19 +281,19 @@ fn_load
echo -e "Avg Load${load}\n"
echo -e "========================================\nLogs\n========================================\n"
echo -e "Script log\n===================\n"
}|tee ${scriptlogdir}/${servicename}-email.log > /dev/null 2>&1
tail -25 ${scriptlog} >> ${emaillog}
if [ ! -z ${consolelog} ]; then
echo -e "\n\nConsole log\n====================\n" >> ${emaillog}
tail -25 ${consolelog} >> ${emaillog}
}|tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
tail -25 "${scriptlog}" >> "${emaillog}"
if [ ! -z "${consolelog}" ]; then
echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
tail -25 "${consolelog}" >> "${emaillog}"
fi
if [ ! -z ${gamelogdir} ]; then
echo -e "\n\nServer log\n====================\n" >> ${emaillog}
tail ${gamelogdir}/*|grep -v "==>"|sed '/^$/d'|tail -25 >> ${emaillog}
if [ ! -z "${gamelogdir}" ]; then
echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
tail "${gamelogdir}"/*|grep -v "==>"|sed '/^$/d'|tail -25 >> "${emaillog}"
fi
mail -s "${subject}" ${email} < ${emaillog}
mail -s "${subject}" ${email} < "${emaillog}"
echo -en "[\e[0;36m INFO \e[0;39m] Sent email notification to ${email}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Sent email notification to ${email}" >> ${scriptlog}
fn_scriptlog "Sent email notification to ${email}"
sleep 1
echo -en "\n"
}
@ -288,7 +301,7 @@ echo -en "\n"
fn_emailtest(){
fn_rootcheck
fn_syscheck
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Emailing test notification" >> ${scriptlog}
fn_scriptlog "Emailing test notification"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Email Test Notification - Testing ${servername}"
failurereason="Testing ${servicename} email notification"
@ -296,7 +309,7 @@ if [ "${emailnotification}" = "on" ]; then
fn_emailnotification
else
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] Email notification not enabled"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Email notification not enabled" >> ${scriptlog}
fn_scriptlog "Email notification not enabled"
fi
sleep 0.5
echo -en "\n"
@ -306,23 +319,23 @@ fn_serverquery(){
# uses gsquery.py to directly query the server
# detects if the server locks up
if [ -f gsquery.py ]; then
if [ "${engine}" == "unreal" ] || [ "${engine}" == "unreal2" ]; then
if [ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
port=$((${gameport} + 1))
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected gsquery.py " >> ${scriptlog}
fn_scriptlog "Detected gsquery.py"
sleep 1
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: QUERYING" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
exitcode=$?
sleep 1
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ${serverquery}" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
sleep 1
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
@ -335,13 +348,13 @@ if [ -f gsquery.py ]; then
exit
elif [ "${exitcode}" == "0" ]; then
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: OK" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: ./gsquery.py: Permission denied" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: ./gsquery.py: Permission denied"
sleep 1
echo -en "\n"
echo "Attempting to resolve automatically"
@ -359,11 +372,11 @@ if [ -f gsquery.py ]; then
fi
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Querying port: ${ip}:${port}: UNKNOWN ERROR" >> ${scriptlog}
fn_scriptlog "Querying port: ${ip}:${port}: UNKNOWN ERROR"
sleep 1
echo -en "\n"
./gsquery.py -a ${ip} -p ${port} -e ${engine}
exit
exit
fi
fi
}
@ -373,46 +386,46 @@ fn_rootcheck
fn_syscheck
fn_autoip
echo -en "\r\033[K[ .... ] Monitoring ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitoring ${servername}" >> ${scriptlog}
fn_scriptlog "Monitoring ${servername}"
sleep 1
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: CHECKING" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: OK" >> ${scriptlog}
fn_scriptlog "Checking session: OK"
sleep 1
echo -en "\n"
fn_serverquery
exit
else
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] Monitoring ${servicename}: Checking session: FAIL"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Checking session: FAIL" >> ${scriptlog}
fn_scriptlog "Checking session: FAIL"
sleep 1
echo -en "\n"
echo -en "\n"
if [ "${emailnotification}" = "on" ]; then
subject="${servicename} Monitor - Starting ${servername}"
failurereason="${servicename} process not running"
actiontaken="${servicename} has been restarted"
fn_emailnotification
fi
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Monitor is starting ${servername}" >> ${scriptlog}
fn_startserver
fn_scriptlog "Monitor is starting ${servername}"
fn_startserver
fi
else
echo -e "[\e[0;36m INFO \e[0;39m] Monitoring ${servicename}: Detected SteamCMD is checking for updates"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Detected SteamCMD is checking for updates" >> ${scriptlog}
fn_scriptlog "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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: When updates complete ${servicename} will start" >> ${scriptlog}
fn_scriptlog "When updates complete ${servicename} will start"
fi
}
fn_restartserver(){
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Restarting ${servername}" >> ${scriptlog}
fn_scriptlog "Restarting ${servername}"
fn_stopserver
fn_startserver
}
@ -422,15 +435,15 @@ 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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopping ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already stopped" >> ${scriptlog}
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Stopped ${servername}" >> ${scriptlog}
fn_scriptlog "Stopped ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -440,32 +453,33 @@ fn_startserver(){
fn_rootcheck
fn_syscheck
fn_autoip
fn_parms
fn_logmanager
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
if [ ${tmuxwc} -eq 0 ]; then
mv ${scriptlog} ${scriptlogdate}
mv ${consolelog} ${consolelogdate}
mv "${scriptlog}" "${scriptlogdate}"
mv "${consolelog}" "${consolelogdate}"
fi
echo -en "\r\033[K[ .... ] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Starting ${servername}" >> ${scriptlog}
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"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${servername} is already running" >> ${scriptlog}
fn_scriptlog "${servername} is already running"
sleep 0.5
echo -en "\n"
exit
fi
cd ${systemdir}
tmux new-session -d -s ${servicename} "./ucc-bin ${parms} |tee -a ${consolelog}"
cd "${executabledir}"
tmux new-session -d -s ${servicename} "${executable} ${parms}|tee -a '${consolelog}'"
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}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: failed to start ${servername}" >> ${scriptlog}
fn_scriptlog "failed to start ${servername}"
else
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] Starting ${servicename}: ${servername}"
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: Started ${servername}" >> ${scriptlog}
fn_scriptlog "Started ${servername}"
fi
sleep 0.5
echo -en "\n"
@ -473,23 +487,28 @@ echo -en "\n"
fn_utdetails(){
fn_autoip
pid=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
gameport=$(grep Port= "${systemdir}/${ini}"|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= "${systemdir}/${ini}"|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= "${systemdir}/${ini}"|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= "${systemdir}/${ini}"|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= "${systemdir}/${ini}"|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= "${systemdir}/${ini}"|sed 's/\AdminPassword=//g')
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 "======================="
gameport=$(grep Port= ${systemdir}/${ini}|grep -v Master|grep -v LAN|grep -v Proxy|grep -v Listen|sed 's/\Port=//g')
queryport=$((${gameport} + 1))
gsqueryport=$(grep OldQueryPortNumber= ${systemdir}/${ini}|sed 's/\OldQueryPortNumber=//g')
udplinkport=$((${gameport} + 2))
webadminport=$(grep ListenPort= ${systemdir}/${ini}|sed 's/\ListenPort=//g')
if [ "${engine}" == "unreal" ]; then
webadminuser=$(grep AdminUsername= ${systemdir}/${ini}|sed 's/\AdminUsername=//g')
else
webadminuser=$(grep AdminName= ${systemdir}/${ini}|sed 's/\AdminName=//g')
fi
webadminpass=$(grep AdminPassword= ${systemdir}/${ini}|sed 's/\AdminPassword=//g')
echo "Ports the server is currently using"
echo ""
echo "DIRECTION DESCRIPTION PORT INI VARIABLE"
@ -517,16 +536,19 @@ echo "INBOUND WebAdmin ${webadminport} TCP ListenPort=${webadminport}"
echo ""
echo "${servername} WebAdmin"
echo "======================="
echo "WebAdmin URL: http://{$ip}:${webadminport}"
echo "WebAdmin URL: http://${ip}:${webadminport}"
echo "WebAdmin Username: ${webadminuser}"
echo "WebAdmin Password: ${webadminpass}"
echo ""
echo "Config file"
echo "${systemdir}/${ini}"
if [ "${pid}" == "0" ]; then
echo -e "Status:\e[0;31m OFFLINE\e[0;39m"
else
echo -e "Status:\e[0;32m ONLINE\e[0;39m"
fi
echo ""
}
fn_compressmaps(){
fn_ut99compressmaps(){
fn_rootcheck
clear
echo "${gamename} Map Compressor"
@ -547,18 +569,13 @@ while true; do
* ) echo "Please answer yes or no.";;
esac
done
mkdir ${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
./ucc-bin-linux-amd64 compress ../Maps/${map} --nohomedir
else
./ucc-bin compress ../Maps/${map} --nohomedir
fi
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
rm -rfv "${filesdir}/Maps/*.unr.uz"
cd "${systemdir}"
for map in `ls "${filesdir}/Maps"`; do
./ucc-bin compress ../Maps/${map} --nohomedir
done
mv -fv ${filesdir}/Maps/*.uz2 ${compressedmapsdir}
mv -fv "${filesdir}/Maps/*.unr.uz" "${compressedmapsdir}"
}
#
@ -569,26 +586,25 @@ fn_header(){
clear
echo "================================="
echo "${gamename}"
echo "Server Linux Installer"
echo "Linux Game Server Manager"
echo "by Daniel Gibbs"
echo "http://danielgibbs.co.uk"
echo "================================="
echo ""
}
fn_filesdl(){
echo ""
fn_ut99filesdl(){
echo "Downloading Server Files"
echo "============================"
cd ${rootdir}
mkdir ${filesdir}
cd ${filesdir}
echo "================================="
cd "${rootdir}"
mkdir -pv "${filesdir}"
cd "${filesdir}"
if [ ! -f ut-server-436.tar.gz ]; then
wget http://danielgibbs.co.uk/wp-content/uploads/ut-server-436.tar.gz
else
echo "ut-server-436.tar.gz already downloaded!"
fi
echo "Running MD5 checksum to verify ut-server-436.tar.gz"
echo "Running MD5 checksum to verify the file"
sleep 1
echo "MD5 checksum: 10cd7353aa9d758a075c600a6dd193fd"
md5check=$(md5sum ut-server-436.tar.gz| awk '{print $1;}')
@ -597,19 +613,19 @@ if [ "${md5check}" != "10cd7353aa9d758a075c600a6dd193fd" ]; then
echo "MD5 checksum: FAILED!"
read -p "Retry download? [y/N]" yn
case $yn in
[Yy]* ) rm -f ut-server-436.tar.gz; fn_filesdl;;
[Yy]* ) rm -fv ut-server-436.tar.gz; fn_filesdl;;
[Nn]* ) echo Exiting; exit;;
* ) echo "Please answer yes or no.";;
esac
else
echo "MD5 checksum: PASSED"
fi
echo "MD5 checksum: PASSED"
echo ""
if [ ! -f UTPGPatch451.tar.bz2 ]; then
wget http://danielgibbs.co.uk/wp-content/uploads/UTPGPatch451.tar.bz2
else
echo "UTPGPatch451.tar.bz2 already downloaded!"
fi
echo "Running MD5 checksum to verify UTPGPatch451.tar.bz2"
echo "Running MD5 checksum to verify the file"
sleep 1
echo "MD5 checksum: 77a735a78b1eb819042338859900b83b"
md5check=$(md5sum UTPGPatch451.tar.bz2| awk '{print $1;}')
@ -618,12 +634,66 @@ if [ "${md5check}" != "77a735a78b1eb819042338859900b83b" ]; then
echo "MD5 checksum: FAILED!"
read -p "Retry download? [y/N]" yn
case $yn in
[Yy]* ) rm -f UTPGPatch451.tar.bz2; fn_filesdl;;
[Nn]* ) echo Exiting; exit ;;
[Yy]* ) rm -fv UTPGPatch451.tar.bz2; fn_filesdl;;
[Nn]* ) echo Exiting; exit;;
* ) echo "Please answer yes or no.";;
esac
else
echo "MD5 checksum: PASSED"
fi
echo "MD5 checksum: PASSED"
echo ""
}
fn_ut99install(){
echo "Installing ${gamename} Server"
echo "================================="
sleep 1
mkdir -pv "${filesdir}"
cd "${filesdir}"
echo "Extracting ut-server-436.tar.gz"
sleep 1
tar -zxvf ut-server-436.tar.gz ut-server/ --strip-components=1
echo "Extracting UTPGPatch451.tar.bz2"
sleep 1
tar -jxvf UTPGPatch451.tar.bz2
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
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;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Remove UTPGPatch451.tar.bz2? [y/N]" yn
case $yn in
[Yy]* ) rm -fv UTPGPatch451.tar.bz2; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
}
fn_utloginstall(){
echo "Creating log directorys"
echo "================================="
sleep 1
mkdir -pv "${rootdir}/log"
mkdir -pv "${scriptlogdir}"
touch "${scriptlog}"
mkdir -pv "${consolelogdir}"
touch "${consolelog}"
sleep 1
echo ""
}
@ -632,7 +702,7 @@ while true; do
read -p "Retry install? [y/N]" yn
case $yn in
[Yy]* ) fn_install;;
[Nn]* ) echo Exiting; exit ;;
[Nn]* ) echo Exiting; exit;;
* ) echo "Please answer yes or no.";;
esac
done
@ -641,20 +711,19 @@ done
fn_install(){
fn_rootcheck
fn_header
if [ -d ${systemdir} ]; then
if [ -d "${filesdir}" ]; then
echo "${gamename} Server is already installed here:"
pwd
echo ""
while true; do
read -p "Continue [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo Exiting; return 1 ;;
[Yy]* ) fn_header; break;;
[Nn]* ) echo Exiting; return 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fn_header
echo "Install Directory:"
pwd
echo ""
@ -667,46 +736,14 @@ while true; do
esac
done
fn_header
fn_filesdl
echo ""
echo "Installing ${gamename} Server"
echo "================================="
mkdir -v ${filesdir}
cd ${filesdir}
tar -zxvf ut-server-436.tar.gz ut-server/ --strip-components=1
tar -jxvf UTPGPatch451.tar.bz2
cd ${systemdir}
while true; do
read -p "Was the install successful? [y/N]" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) fn_retryinstall;;
* ) echo "Please answer yes or no.";;
esac
done
cd ${filesdir}
while true; do
read -p "Remove ut-server-436.tar.gz? [y/N]" yn
case $yn in
[Yy]* ) rm -iv ut-server-436.tar.gz; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
while true; do
read -p "Remove UTPGPatch451.tar.bz2? [y/N]" yn
case $yn in
[Yy]* ) rm -iv UTPGPatch451.tar.bz2; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
echo ""
fn_ut99filesdl
fn_ut99install
fn_utloginstall
echo "Configuring ${gamename} Server"
echo "================================="
sleep 1
echo "Copying ${systemdir}/Default.ini to ${systemdir}/${ini}"
tr -d '\r' < ${systemdir}/Default.ini > ${systemdir}/${ini}
echo "Copying "${defaultcfg}" to ${systemdir}/${ini}"
tr -d '\r' < "${defaultcfg}" > ${systemdir}/${ini}
sleep 1
echo "Enabling UdpServerUplink"
{
@ -730,15 +767,11 @@ echo "================================="
echo "Setting WebAdmin port to 8076"
sed -i '467i\ListenPort=8076' ${systemdir}/${ini}
sleep 1
echo "Creating log directorys"
mkdir -v ${rootdir}/log
mkdir -v ${scriptlogdir}
mkdir -v ${consolelogdir}
touch ${consolelog}
fn_header
sleep 1
fn_utdetails
sleep 1
fn_header
fn_details
echo "================================="
echo "Install Complete!"
echo ""
@ -754,10 +787,6 @@ case "$1" in
fn_stopserver;;
restart)
fn_restartserver;;
update)
fn_stopserver
fn_updateserver
fn_startserver;;
monitor)
fn_monitorserver;;
email-test)
@ -773,12 +802,9 @@ case "$1" in
install)
fn_install;;
map-compressor)
fn_compressmaps;;
steam-auth)
fn_updateserver
fn_steamguard;;
fn_ut2k4compressmaps;;
*)
echo "Usage: $0 {start|stop|restart|update|monitor|email-test|details|backup|console|debug|install|map-compressor|steam-auth}"
echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
exit 1;;
esac
exit
Loading…
Cancel
Save