lgsm local mirror
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.
 
 

137 lines
4.1 KiB

#!/bin/bash
# Insurgency
# Server Management Script
# Author: Daniel Gibbs
# Website: http://gameservermanagers.com
version="061115"
#### Variables ####
engine="source"
game="insurgency"
gamename="Insurgency"
#File fetching settings
githubuser="jaredballou"
githubrepo="linuxgsm"
githubbranch="master"
# The name of this script file, used to show the LGSM link properly
selfname=$(basename $(readlink -f "${BASH_SOURCE[0]}"))
servicename="$(basename $0)"
# Directories
rootdir="$(dirname "${selfname}")"
scriptcfgdir="${rootdir}/cfg/servers"
# Settings to get before config parsing begins
#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
#### Advanced Variables ####
# Directories
lockselfname=".${servicename}.lock"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}/insurgency"
executabledir="${filesdir}"
executable="./srcds_linux"
servercfg="${servicename}.cfg"
servercfgdir="${systemdir}/cfg"
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
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"
# 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} -maxplayers ${maxplayers} ${srcds_parms} +clientport ${clientport} +tv_port ${sourcetvport} +sv_playlist ${playlist} +mapcyclefile ${mapcyclefile} +servercfgfile ${servercfg} +map ${defaultmap} ${defaultmode}"
}
##### Script #####
# Do not edit
fn_getgithubfile() {
filename=$1
exec=$2
fileurl=${3:-$filename}
filepath="${rootdir}/${filename}"
filedir=$(dirname "${filepath}")
download=0
# If file is missing, then download
if [ ! -f "${filepath}" ]
then
download=1
else
# Get the lgsm_version from the file, and download if out of date
script_version=$(grep lgsm_version "${filepath}" 2>&1 | cut -d'=' -f2 | sed -e 's/"//g')
if [ "${script_version}" != "" ] && [ "${script_version}" != "${version}" ]
then
echo $script_version
download=1
fi
fi
if [ $download -gt 0 ]
then
if [ ! -d "${filedir}" ]; then
mkdir -p "${filedir}"
fi
url="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
echo -e " fetching ${filename} (${url})...\c"
wget -N /dev/null "${url}" -O "${filepath}" 2>&1 | grep -F HTTP | cut -c45-
if [ "$exec" ]
then
chmod +x "${filepath}"
fi
fi
if [ "$exec" ]
then
source "${filepath}"
fi
}
# If default config does not exist, create it. This should come from Git, and will be overwritten by updates.
fn_getgithubfile "cfg/servers/_default.cfg" 1 "${gamename}/cfg/servers/_default.cfg"
# 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
fn_runfunction(){
fn_getgithubfile "functions/${functionfile}" 1
}
fn_functions(){
# Functions are defined in fn_functions.
functionfile="${FUNCNAME}"
fn_runfunction
}
fn_functions
getopt=$1
fn_getopt