gameservergame-servergame-servershacktoberfestdedicated-game-serversgamelinuxgsmserverbashgaminglinuxmultiplayer-game-servershell
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
885 lines
24 KiB
885 lines
24 KiB
#!/bin/bash
|
|
# Unreal Tournament 2004
|
|
# Server Management Script
|
|
# Author: Daniel Gibbs
|
|
# Website: http://danielgibbs.co.uk
|
|
# Version: 121114
|
|
|
|
#### Variables ####
|
|
|
|
# Notification Email
|
|
# (on|off)
|
|
emailnotification="off"
|
|
email="[email protected]"
|
|
|
|
# Directories
|
|
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
selfname="$0"
|
|
lockselfname=$(echo ".${servicename}.lock")
|
|
filesdir="${rootdir}/serverfiles"
|
|
systemdir="${filesdir}/System"
|
|
executabledir="${systemdir}"
|
|
executable="./ucc-bin"
|
|
compressedmapsdir="${rootdir}/Maps-Compressed"
|
|
defaultcfg="${systemdir}/UT2004.ini"
|
|
backupdir="backups"
|
|
|
|
# Server Details
|
|
servicename="ut2k4-server"
|
|
gamename="Unreal Tournament 2004"
|
|
engine="unreal2"
|
|
ini="${servicename}.ini"
|
|
servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
|
|
ip="0.0.0.0"
|
|
|
|
# Logging
|
|
logdays="7"
|
|
gamelogdir="${rootdir}/log/server"
|
|
scriptlogdir="${rootdir}/log/script"
|
|
consolelogdir="${rootdir}/log/console"
|
|
|
|
gamelog="${gamelogdir}/${servicename}-game.log"
|
|
scriptlog="${scriptlogdir}/${servicename}-script.log"
|
|
consolelog="${consolelogdir}/${servicename}-console.log"
|
|
emaillog="${scriptlogdir}/${servicename}-email.log"
|
|
|
|
gamelogdate="${gamelogdir}/${servicename}-game-$(date '+%d-%m-%Y-%H-%M-%S').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"
|
|
|
|
# Start Variables
|
|
fn_parms(){
|
|
defaultmap="DM-Rankin"
|
|
parms="server ${defaultmap}?game=XGame.xDeathMatch -nohomedir ini=${ini} log=${gamelog}"
|
|
}
|
|
|
|
##### Script #####
|
|
# Do not edit
|
|
# unless you know
|
|
# what you are doing
|
|
|
|
fn_scriptlog(){
|
|
echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> ${scriptlog}
|
|
}
|
|
|
|
# [ FAIL ]
|
|
fn_printfail(){
|
|
echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
|
|
}
|
|
|
|
fn_printfailnl(){
|
|
echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
|
|
}
|
|
|
|
fn_printok(){
|
|
echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
|
|
}
|
|
|
|
# [ OK ]
|
|
fn_printoknl(){
|
|
echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
|
|
}
|
|
|
|
fn_printinfo(){
|
|
echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
|
|
}
|
|
|
|
fn_printinfonl(){
|
|
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
|
|
}
|
|
|
|
# [ INFO ]
|
|
fn_printokinfonl(){
|
|
echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
|
|
}
|
|
|
|
fn_printwarn(){
|
|
echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
|
|
}
|
|
|
|
fn_printwarnnl(){
|
|
echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
|
|
}
|
|
|
|
# [ .... ]
|
|
fn_printdots(){
|
|
echo -en "\r\033[K[ .... ] $@"
|
|
}
|
|
|
|
fn_rootcheck(){
|
|
if [ `whoami` = "root" ]; then
|
|
fn_printfailnl "Script will not run as root!"
|
|
exit
|
|
fi
|
|
}
|
|
|
|
fn_syscheck(){
|
|
if [ ! -e "${systemdir}" ]; then
|
|
fn_printfailnl "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)
|
|
getipwc=$(ip -o -4 addr|awk '{print $4 }'|grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}'|grep -v 127.0.0|wc -l)
|
|
if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then
|
|
if [ "${getipwc}" -ge "2" ]; then
|
|
fn_printwarn "Multiple active network interfaces.\n\n"
|
|
echo -en "Manually specify the IP you want to use within the ${selfname} script.\n"
|
|
echo -en "Set ip=\"0.0.0.0\" to one of the following:\n"
|
|
echo -en "${getip}\n"
|
|
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
|
|
fn_printdots "Starting log cleaner"
|
|
sleep 1
|
|
fn_printok "Starting log cleaner"
|
|
fn_scriptlog "Starting log cleaner"
|
|
sleep 1
|
|
echo -en "\n"
|
|
fn_printinfo "Removing logs older than ${logdays} days"
|
|
fn_scriptlog "Removing logs older than ${logdays} days"
|
|
sleep 1
|
|
echo -en "\n"
|
|
if [ "${engine}" == "unreal2" ]; then
|
|
find "${gamelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
|
|
fi
|
|
find "${scriptlogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
|
|
find "${consolelogdir}"/* -mtime +${logdays}|tee >> "${scriptlog}"
|
|
if [ "${engine}" == "unreal2" ]; then
|
|
gamecount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
|
|
fi
|
|
scriptcount=$(find "${scriptlogdir}"/* -mtime +${logdays}|wc -l)
|
|
consolecount=$(find "${consolelogdir}"/* -mtime +${logdays}|wc -l)
|
|
count=$((${scriptcount} + ${consolecount}))
|
|
if [ "${engine}" == "unreal2" ]; then
|
|
count=$((${scriptcount} + ${consolecount} + ${gamecount}))
|
|
else
|
|
count=$((${scriptcount} + ${consolecount}))
|
|
fi
|
|
if [ "${engine}" == "unreal2" ]; then
|
|
find "${gamelogdir}"/* -mtime +${logdays} -exec rm {} \;
|
|
fi
|
|
find "${scriptlogdir}"/* -mtime +${logdays} -exec rm {} \;
|
|
find "${consolelogdir}"/* -mtime +${logdays} -exec rm {} \;
|
|
fn_printok "Log cleaner removed ${count} log files"
|
|
fn_scriptlog "Log cleaner removed ${count} log files"
|
|
sleep 1
|
|
echo -en "\n"
|
|
fi
|
|
}
|
|
|
|
fn_debugserver(){
|
|
if [ ! -f ${rootdir}/functions/fn_debugserver ]; then
|
|
functionfile="fn_debugserver"
|
|
fn_fninstall
|
|
fi
|
|
source ${rootdir}/functions/fn_debugserver
|
|
}
|
|
|
|
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
|
|
fn_printdots "Starting ${servicename} console"
|
|
sleep 1
|
|
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -v failed|grep -E "^${servicename}:"|wc -l)
|
|
if [ ${tmuxwc} -eq 1 ]; then
|
|
fn_printoknl "Starting ${servicename} console"
|
|
fn_scriptlog "Console accessed"
|
|
sleep 1
|
|
tmux attach-session -t ${servicename}
|
|
else
|
|
fn_printfailnl "Starting ${servicename} console: ${servername} not running"
|
|
sleep 1
|
|
while true; do
|
|
read -p "Do you want to start the server? [y/N]" yn
|
|
case $yn in
|
|
[Yy]* ) fn_startserver; break;;
|
|
[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
|
|
fn_printdots "Starting backup ${servicename}: ${servername}"
|
|
sleep 1
|
|
fn_printok "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}"
|
|
fn_printinfo "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
|
|
fn_printfailnl "Email notification not enabled"
|
|
fn_scriptlog "Email notification not enabled"
|
|
fi
|
|
sleep 1
|
|
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))
|
|
elif [ "${engine}" == "realvirtuality" ]; then
|
|
port=${queryport}
|
|
fi
|
|
fn_printinfo "Monitoring ${servicename}: Detected gsquery.py"
|
|
fn_scriptlog "Detected gsquery.py"
|
|
sleep 1
|
|
fn_printdots "Monitoring ${servicename}: Querying port: ${ip}:${port}: QUERYING"
|
|
fn_scriptlog "Querying port: ${ip}:${port}: QUERYING"
|
|
sleep 1
|
|
serverquery=$(./gsquery.py -a ${ip} -p ${port} -e ${engine} 2>&1)
|
|
exitcode=$?
|
|
if [ "${exitcode}" == "1" ]||[ "${exitcode}" == "2" ]||[ "${exitcode}" == "3" ]||[ "${exitcode}" == "4" ]; then
|
|
fn_printfail "Monitoring ${servicename}: Querying port: ${ip}:${port}: ${serverquery}"
|
|
sleep 1
|
|
echo -en "\n"
|
|
fn_scriptlog "Querying port: ${ip}:${port}: ${serverquery}"
|
|
if [[ -z "${secondquery}" ]]; then
|
|
fn_printinfo "Monitoring ${servicename}: Waiting 30 seconds to re-query"
|
|
fn_scriptlog "Waiting 30 seconds to re-query"
|
|
sleep 30
|
|
secondquery=1
|
|
fn_serverquery
|
|
fi
|
|
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
|
|
fn_printok "Monitoring ${servicename}: Querying port: ${ip}:${port}: OK"
|
|
fn_scriptlog "Querying port: ${ip}:${port}: OK"
|
|
sleep 1
|
|
echo -en "\n"
|
|
exit
|
|
elif [ "${exitcode}" == "126" ]; then
|
|
fn_printfail "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
|
|
fn_printfail "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
|
|
fn_printdots "Monitoring ${servicename}: ${servername}"
|
|
fn_scriptlog "Monitoring ${servername}"
|
|
sleep 1
|
|
if [ ! -f ${lockselfname} ]; then
|
|
fn_printinfo "Monitoring ${servicename}: Monitor disabled: No lock file found"
|
|
fn_scriptlog "Monitor disabled: No lock file found"
|
|
sleep 1
|
|
echo -en "\n"
|
|
echo "To enable monitor run ${selfname} start"
|
|
exit
|
|
fi
|
|
updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l)
|
|
if [ "${updatecheck}" = "0" ]; then
|
|
fn_printdots "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
|
|
fn_printok "Monitoring ${servicename}: Checking session: OK"
|
|
fn_scriptlog "Checking session: OK"
|
|
sleep 1
|
|
echo -en "\n"
|
|
fn_serverquery
|
|
exit
|
|
else
|
|
fn_printfail "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
|
|
fn_printinfonl "Monitoring ${servicename}: Detected SteamCMD is checking for updates"
|
|
fn_scriptlog "Detected SteamCMD is checking for updates"
|
|
sleep 1
|
|
fn_printinfonl "Monitoring ${servicename}: When updates complete ${servicename} will start"
|
|
fn_scriptlog "When updates complete ${servicename} will start"
|
|
sleep 1
|
|
fi
|
|
}
|
|
|
|
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)
|
|
fn_printdots "Stopping ${servicename}: ${servername}"
|
|
fn_scriptlog "Stopping ${servername}"
|
|
sleep 1
|
|
if [ "${pid}" == "0" ]; then
|
|
fn_printfail "Stopping ${servicename}: ${servername} is already stopped"
|
|
fn_scriptlog "${servername} is already stopped"
|
|
else
|
|
tmux kill-session -t ${servicename}
|
|
fn_printok "Stopping ${servicename}: ${servername}"
|
|
fn_scriptlog "Stopped ${servername}"
|
|
fi
|
|
# Remove lock file
|
|
rm -f ${lockselfname}
|
|
sleep 1
|
|
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
|
|
fn_scriptlog "Rotating log files"
|
|
if [ "${engine}" == "unreal2" ]; then
|
|
mv "${gamelog}" "${gamelogdate}"
|
|
fi
|
|
mv "${scriptlog}" "${scriptlogdate}"
|
|
mv "${consolelog}" "${consolelogdate}"
|
|
fi
|
|
fn_printdots "Starting ${servicename}: ${servername}"
|
|
fn_scriptlog "Starting ${servername}"
|
|
sleep 1
|
|
if [ ${tmuxwc} -eq 1 ]; then
|
|
fn_printinfo "Starting ${servicename}: ${servername} is already running"
|
|
fn_scriptlog "${servername} is already running"
|
|
sleep 1
|
|
echo -en "\n"
|
|
exit
|
|
fi
|
|
# Create lock file
|
|
date > "${rootdir}/${lockselfname}"
|
|
cd "${executabledir}"
|
|
tmux new-session -d -s ${servicename} "${executable} ${parms}" 2> ${scriptlogdir}/.${servicename}-tmux-error.tmp
|
|
tmux pipe-pane -o -t ${servicename} "exec cat >> '${consolelog}'"
|
|
sleep 1
|
|
tmuxwc=$(tmux list-sessions 2>&1|awk '{print $1}'|grep -E "^${servicename}:"|wc -l)
|
|
if [ ${tmuxwc} -eq 0 ]; then
|
|
fn_printfailnl "Starting ${servicename}: Failed to start ${servername}"
|
|
echo -en " Check log files: ${rootdir}/log"
|
|
fn_scriptlog "failed to start ${servername}"
|
|
if [ -a ${scriptlogdir}/.${servicename}-tmux-error.tmp ]; then
|
|
fn_scriptlog "tmux returned the following error"
|
|
cat ${scriptlogdir}/.${servicename}-tmux-error.tmp >> ${scriptlog}
|
|
fi
|
|
else
|
|
fn_printok "Starting ${servicename}: ${servername}"
|
|
fn_scriptlog "Started ${servername}"
|
|
fi
|
|
rm ${scriptlogdir}/.${servicename}-tmux-error.tmp
|
|
sleep 1
|
|
echo -en "\n"
|
|
}
|
|
|
|
fn_details(){
|
|
if [ ! -f ${rootdir}/functions/fn_details ]; then
|
|
functionfile="fn_details"
|
|
fn_fninstall
|
|
fi
|
|
source ${rootdir}/functions/fn_details
|
|
}
|
|
|
|
fn_fninstall(){
|
|
cd ${rootdir}
|
|
if [ ! -d "functions" ]; then
|
|
mkdir functions
|
|
fi
|
|
echo ""
|
|
echo "loading ${functionfile}..."
|
|
cd functions
|
|
wget --no-check-certificate -nv -N https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile}
|
|
chmod +x ${functionfile}
|
|
cd ${rootdir}
|
|
sleep 1
|
|
echo ""
|
|
}
|
|
|
|
fn_ut2k4compressmaps(){
|
|
fn_rootcheck
|
|
clear
|
|
echo "${gamename} Map Compressor"
|
|
echo "============================"
|
|
echo "Will compress all maps in:"
|
|
echo ""
|
|
pwd
|
|
echo ""
|
|
echo "Compressed maps saved to:"
|
|
echo ""
|
|
echo "${compressedmapsdir}"
|
|
echo ""
|
|
while true; do
|
|
read -p "Start compression [y/N]" yn
|
|
case $yn in
|
|
[Yy]* ) break;;
|
|
[Nn]* ) echo Exiting; return 1;;
|
|
* ) echo "Please answer yes or no.";;
|
|
esac
|
|
done
|
|
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
|
|
else
|
|
./ucc-bin compress ../Maps/${map} --nohomedir
|
|
fi
|
|
done
|
|
mv -fv "${filesdir}/Maps/*.uz2" "${compressedmapsdir}"
|
|
}
|
|
|
|
#
|
|
## Installer
|
|
#
|
|
|
|
fn_header(){
|
|
clear
|
|
echo "================================="
|
|
echo "${gamename}"
|
|
echo "Linux Game Server Manager"
|
|
echo "by Daniel Gibbs"
|
|
echo "http://danielgibbs.co.uk"
|
|
echo "================================="
|
|
echo ""
|
|
}
|
|
|
|
fn_ut2k4filesdl(){
|
|
echo "Downloading Server Files"
|
|
echo "================================="
|
|
cd "${rootdir}"
|
|
mkdir -pv "${filesdir}"
|
|
cd "${filesdir}"
|
|
if [ ! -f dedicatedserver3339-bonuspack.zip ]; then
|
|
wget -nv -N http://downloads.unrealadmin.org/UT2004/Server/dedicatedserver3339-bonuspack.zip
|
|
else
|
|
echo "dedicatedserver3339-bonuspack.zip already downloaded!"
|
|
fi
|
|
echo "Running MD5 checksum to verify the file"
|
|
sleep 1
|
|
echo "MD5 checksum: d3f28c5245c4c02802d48e4f0ffd3e34"
|
|
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 -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
|
|
wget -nv -N http://downloads.unrealadmin.org/UT2004/Patches/Linux/ut2004-lnxpatch3369-2.tar.bz2
|
|
else
|
|
echo "ut2004-lnxpatch3369-2.tar.bz2 already downloaded!"
|
|
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;}')
|
|
echo "File returned: ${md5check}"
|
|
if [ "${md5check}" != "0fa447e05fe5a38e0e32adf171be405e" ]; then
|
|
echo "MD5 checksum: FAILED!"
|
|
read -p "Retry download? [y/N]" yn
|
|
case $yn in
|
|
[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}"
|
|
mkdir -pv "${gamelogdir}"
|
|
touch "${gamelog}"
|
|
sleep 1
|
|
echo ""
|
|
}
|
|
|
|
fn_getquery(){
|
|
echo "GameServerQuery"
|
|
echo "============================"
|
|
while true; do
|
|
read -p "Do you want to install GameServerQuery? [y/N]" yn
|
|
case $yn in
|
|
[Yy]* ) cd "${rootdir}"; wget -nv -N "http://danielgibbs.co.uk/dl/gsquery.py"; chmod +x gsquery.py; break;;
|
|
[Nn]* ) echo -e "Not installing GameServerQuery.";break;;
|
|
* ) echo "Please answer yes or no.";;
|
|
esac
|
|
done
|
|
echo ""
|
|
}
|
|
|
|
fn_retryinstall(){
|
|
while true; do
|
|
read -p "Retry install? [y/N]" yn
|
|
case $yn in
|
|
[Yy]* ) fn_install; exit;;
|
|
[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_ut2k4filesdl
|
|
fn_ut2k4install
|
|
fn_ut2k4key
|
|
fn_utloginstall
|
|
fn_getquery
|
|
echo "Configuring ${gamename} Server"
|
|
echo "================================="
|
|
sleep 1
|
|
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"
|
|
sed -i 's/none}/none;/g' "${filesdir}/Web/ServerAdmin/ut2003.css"
|
|
sed -i 's/underline}/underline;/g' "${filesdir}/Web/ServerAdmin/ut2003.css"
|
|
sleep 1
|
|
echo "Applying WebAdmin CharSet fix!"
|
|
echo "http://forums.tripwireinteractive.com/showpost.php?p=442340&postcount=1"
|
|
sed -i 's/CharSet="iso-8859-1"/CharSet="utf-8"/g' "${systemdir}/UWeb.int"
|
|
sleep 1
|
|
echo "Setting WebAdmin username and password"
|
|
sed -i 's/AdminName=/AdminName=admin/g' "${systemdir}/${ini}"
|
|
sed -i 's/AdminPassword=/AdminPassword=admin/g' "${systemdir}/${ini}"
|
|
sleep 1
|
|
echo "Enabling WebAdmin"
|
|
sed -i 's/bEnabled=False/bEnabled=True/g' "${systemdir}/${ini}"
|
|
sleep 1
|
|
echo "Setting WebAdmin port to 8077"
|
|
sed -i 's/ListenPort=80/ListenPort=8077/g' "${systemdir}/${ini}"
|
|
sleep 1
|
|
echo "Forcing server to start to get ports/server name to display correctly"
|
|
sleep 1
|
|
cd "${rootdir}"
|
|
${selfname} start
|
|
sleep 5
|
|
${selfname} restart
|
|
sleep 5
|
|
${selfname} stop
|
|
sleep 5
|
|
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;;
|
|
monitor)
|
|
fn_monitorserver;;
|
|
email-test)
|
|
fn_emailtest;;
|
|
details)
|
|
fn_details;;
|
|
backup)
|
|
fn_backupserver;;
|
|
console)
|
|
fn_console;;
|
|
debug)
|
|
fn_debugserver;;
|
|
install)
|
|
fn_install;;
|
|
map-compressor)
|
|
fn_ut2k4compressmaps;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
|
|
exit 1;;
|
|
esac
|
|
exit
|