1 changed files with 132 additions and 75 deletions
@ -3,60 +3,109 @@ |
|||
# Server Management Script |
|||
# Author: Daniel Gibbs |
|||
# Website: http://gameservermanagers.com |
|||
if [ -f ".dev-debug" ]; then |
|||
exec 5>dev-debug.log |
|||
BASH_XTRACEFD="5" |
|||
set -x |
|||
fi |
|||
|
|||
version="271215" |
|||
version="110116" |
|||
|
|||
#### Variables #### |
|||
|
|||
# Notification Email |
|||
# (on|off) |
|||
emailnotification="off" |
|||
email="[email protected]" |
|||
|
|||
# Steam login |
|||
steamuser="anonymous" |
|||
steampass="" |
|||
|
|||
# Start Variables |
|||
defaultmap="ministry" |
|||
maxplayers="16" |
|||
tickrate="64" |
|||
port="27015" |
|||
sourcetvport="27020" |
|||
clientport="27005" |
|||
ip="0.0.0.0" |
|||
updateonstart="off" |
|||
# The name of this script file, used to show the LGSM link properly |
|||
selfname=$(basename $(readlink -f "${BASH_SOURCE[0]}")) |
|||
|
|||
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server |
|||
fn_parms(){ |
|||
parms="-game insurgency -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}" |
|||
} |
|||
# Directories |
|||
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
|||
scriptcfgdir="${rootdir}/cfg/servers" |
|||
|
|||
# Debugging, if debugflag exists send output to $debuglog |
|||
debugflag="${rootdir}/.dev-debug" |
|||
debuglog="${rootdir}/dev-debug.log" |
|||
if [ -f "${debugflag}" ]; then |
|||
exec 5>${debuglog} |
|||
BASH_XTRACEFD="5" |
|||
set -x |
|||
fi |
|||
|
|||
#### Advanced Variables #### |
|||
# Settings to get before config parsing begins |
|||
engine="source" |
|||
# Game name for file paths |
|||
game="insurgency" |
|||
# Name for subdirectory in GitHub repo |
|||
gamename="Insurgency" |
|||
# Name of this service (for symlinked instances) |
|||
servicename="$(basename $0)" |
|||
|
|||
# File fetching settings |
|||
# Github Branch Select |
|||
# Allows for the use of different function files |
|||
# from a different repo and/or branch. |
|||
githubuser="dgibbs64" |
|||
githubuser="jaredballou" |
|||
githubrepo="linuxgsm" |
|||
githubbranch="master" |
|||
|
|||
# Steam |
|||
appid="237410" |
|||
#ipaddr=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
|
|||
# Config files |
|||
cfg_default="${scriptcfgdir}/_default.cfg" |
|||
cfg_common="${scriptcfgdir}/_common.cfg" |
|||
cfg_instance="${scriptcfgdir}/${servicename}.cfg" |
|||
|
|||
#If config directory does not exist, create it |
|||
if [ ! -e $scriptcfgdir ]; then mkdir -p "$scriptcfgdir"; fi |
|||
|
|||
# If default config does not exist, create it. This should come from Git, and will be overwritten by updates. |
|||
# Rather than try to wget it from Github or other fancy ways to get it, the simplest way to ensure it works is to simply create it here. |
|||
fn_create_default_config(){ |
|||
cat <<'EOF' >> $cfg_default |
|||
# Default config - Changes will be overwritten by updates. |
|||
# Your settings for all servers go in _common.cfg |
|||
# Server-specific settings go into $SERVER.cfg |
|||
appid="237410" |
|||
beta="" #To enable beta, use " -beta beta" |
|||
clientport="27005" |
|||
defaultmap="ministry" |
|||
defaultmode="checkpoint" |
|||
email="[email protected]" |
|||
emailnotification="off" # (on|off) |
|||
ip="0.0.0.0" |
|||
lgsm_version="${version}" |
|||
logdays="7" |
|||
mapcyclefile="mapcycle.txt" |
|||
maxplayers="16" |
|||
playlist="custom" |
|||
port="27015" |
|||
sourcetvport="27020" |
|||
srcds_parms="" |
|||
steampass="" |
|||
steamuser="anonymous" |
|||
updateonstart="off" |
|||
EOF |
|||
} |
|||
if [ ! -f $cfg_default ] |
|||
then |
|||
fn_create_default_config |
|||
fi |
|||
|
|||
# Server Details |
|||
servicename="ins-server" |
|||
gamename="Insurgency" |
|||
engine="source" |
|||
# Load defaults |
|||
source $cfg_default |
|||
|
|||
# If defaults are from an older version, overwrite the file |
|||
# TODO: Perhaps pull this from Git instead? |
|||
if [ "${lgsm_version}" != "${version}" ]; then fn_create_default_config; fi |
|||
|
|||
# Load sitewide common settings (so that Git updates can safely overwrite default.cfg) |
|||
if [ ! -f $cfg_common ]; then touch $cfg_common; else source $cfg_common; fi |
|||
|
|||
# Load instance specific settings |
|||
if [ ! -f $cfg_instance ]; then touch $cfg_instance; else source $cfg_instance; fi |
|||
|
|||
# Set the paramaters to send to srcds |
|||
# https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server |
|||
fn_parms(){ |
|||
#TODO: Put in some conditional logic to handle generating the parm string so we can make this a little less game specific |
|||
parms="-game ${game} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +sv_playlist ${playlist} +mapcyclefile ${mapcyclefile}+servercfgfile ${servercfg} +map ${defaultmap} ${defaultmode} -maxplayers ${maxplayers} ${srcds_parms}" |
|||
} |
|||
|
|||
#### Advanced Variables #### |
|||
# Directories |
|||
rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))" |
|||
selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" |
|||
lockselfname=".${servicename}.lock" |
|||
filesdir="${rootdir}/serverfiles" |
|||
systemdir="${filesdir}/insurgency" |
|||
@ -68,8 +117,10 @@ servercfgfullpath="${servercfgdir}/${servercfg}" |
|||
servercfgdefault="${servercfgdir}/lgsm-default.cfg" |
|||
backupdir="${rootdir}/backups" |
|||
|
|||
#In the event that you have library issues after an update, this may resolve it. |
|||
#export LD_LIBRARY_PATH="${filesdir}:${filesdir}/bin:${LD_LIBRARY_PATH}" |
|||
|
|||
# Logging |
|||
logdays="7" |
|||
gamelogdir="${systemdir}/logs" |
|||
scriptlogdir="${rootdir}/log/script" |
|||
consolelogdir="${rootdir}/log/console" |
|||
@ -84,43 +135,49 @@ consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M- |
|||
##### Script ##### |
|||
# Do not edit |
|||
|
|||
# fn_getgithubfile filename [exec] [url] |
|||
# Download file from Github |
|||
# Parameters: |
|||
# filename: The path of the file in reference to the repository root |
|||
# exec: Optional, set to 1 to make file executable |
|||
# url: Optional, set to full path under repository root if different than filename |
|||
fn_getgithubfile(){ |
|||
filename=$1 |
|||
exec=$2 |
|||
fileurl=${3:-$filename} |
|||
filepath="${rootdir}/${filename}" |
|||
filedir=$(dirname "${filepath}") |
|||
# If the function file is missing, then download |
|||
if [ ! -f "${filepath}" ]; then |
|||
if [ ! -d "${filedir}" ]; then |
|||
mkdir "${filedir}" |
|||
filename=$1 |
|||
exec=$2 |
|||
fileurl=${3:-$filename} |
|||
filepath="${rootdir}/${filename}" |
|||
filedir=$(dirname "${filepath}") |
|||
# If the function file is missing, then download |
|||
if [ ! -f "${filepath}" ]; then |
|||
if [ ! -d "${filedir}" ]; then |
|||
mkdir "${filedir}" |
|||
fi |
|||
githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}" |
|||
echo -e " fetching ${filename}...\c" |
|||
if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then |
|||
: |
|||
else |
|||
echo -e "\e[0;31mFAIL\e[0m\n" |
|||
echo "Curl is not installed!" |
|||
echo -e "" |
|||
exit |
|||
fi |
|||
curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1) |
|||
if [ $? -ne 0 ]; then |
|||
echo -e "\e[0;31mFAIL\e[0m\n" |
|||
echo "${curl}" |
|||
echo -e "${githuburl}\n" |
|||
exit |
|||
else |
|||
echo -e "\e[0;32mOK\e[0m" |
|||
fi |
|||
if [ "${exec}" ]; then |
|||
chmod +x "${filepath}" |
|||
fi |
|||
fi |
|||
githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}" |
|||
echo -e " fetching ${filename}...\c" |
|||
if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then |
|||
: |
|||
else |
|||
echo -e "\e[0;31mFAIL\e[0m\n" |
|||
echo "Curl is not installed!" |
|||
echo -e "" |
|||
exit |
|||
fi |
|||
curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1) |
|||
if [ $? -ne 0 ]; then |
|||
echo -e "\e[0;31mFAIL\e[0m\n" |
|||
echo "${curl}" |
|||
echo -e "${githuburl}\n" |
|||
exit |
|||
else |
|||
echo -e "\e[0;32mOK\e[0m" |
|||
fi |
|||
if [ "${exec}" ]; then |
|||
chmod +x "${filepath}" |
|||
source "${filepath}" |
|||
fi |
|||
fi |
|||
if [ "${exec}" ]; then |
|||
source "${filepath}" |
|||
fi |
|||
} |
|||
|
|||
fn_runfunction(){ |
|||
@ -128,9 +185,9 @@ fn_runfunction(){ |
|||
} |
|||
|
|||
core_functions.sh(){ |
|||
# Functions are defined in core_functions.sh. |
|||
functionfile="${FUNCNAME}" |
|||
fn_runfunction |
|||
# Functions are defined in core_functions.sh. |
|||
functionfile="${FUNCNAME}" |
|||
fn_runfunction |
|||
} |
|||
|
|||
core_functions.sh |
|||
|
Loading…
Reference in new issue