Skip to content

Instantly share code, notes, and snippets.

@RobChiocchio
Created March 4, 2017 07:22
Show Gist options
  • Select an option

  • Save RobChiocchio/a1b252da184daae171f31ea52a4fe7e7 to your computer and use it in GitHub Desktop.

Select an option

Save RobChiocchio/a1b252da184daae171f31ea52a4fe7e7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# By Rob Chiocchio - http://steamcommunity.com/profiles/76561198069792788
#####################
### Configuration ###
#####################
steamuser="username" # You must sign in with an account, you cannot use "anonymous". It is reccomended that you make a new account for this because it requires you to have Steam guard disabled
steampass="password"
appid="17520"
branch=""
depotid="17523"
defaultmap="d1_trainstation_01"
maxplayers="10"
port="27017" # default="27015"
sourcetvport="27022" # default="27020"
clientport="27007" # default="27005"
ip="0.0.0.0"
params="-game synergy -includepath ${filesdir} -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} -maxplayers ${maxplayers}"
# Game content to enable on the server (true/false)
synhl2=true # Half-Life 2
synep1=true # Half-Life 2: Episode One
synep2=true # Half-Life 2: Episode Two
synlost=false # Half-Life 2: Lost Coast
synhl1=false # Half-Life: Source
synmeta=false # MINERVIA: Metastasis
synbase=false # Synergy (a set of cooperative levels that come preinstalled with the Synergy mod)
rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
filesdir="${rootdir}/serverfiles"
executabledir="${rootdir}/steamcmd/linux32/steamapps/content/app_${appid}/depot_${depotid}"
executable="./srcds_run"
selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
servicename="synergy-server"
lockselfname=".${servicename}.lock"
log="${rootdir}/logs/${servicename}.log"
####################################
### Script ### DO NOT EDIT BELOW ###
####################################
pfred="\x1b[31m"
pfgreen="\x1b[32m"
pfyellow="\x1b[33m"
pfblue="\x1b[34m"
pfpurple="\x1b[35m"
pfreset="\e[0m"
consolemode=false
fn_start(){
fn_status
echo "$(date) - Starting server..." >> ${log}
if [ ${status} == 0 ] ; then
date > "${rootdir}/${lockselfname}"
cd "${executabledir}"
tmux new-session -d -s "${servicename}" "${executable} ${params}" 2> "${rootdir}/logs/.${servicename}-tmux-error.tmp"
tmux pipe-pane -o -t ${servicename} "cat >> tee -a '${log}'"
if ${consolemode} ; then
echo "Console is enabled"
printf "${pfred}DO NOT PRESS CTRL-C! USE CTRL-B, D TO EXIT!${pfreset}\n"
#tmux -L ${servicename}
else
echo "Console is (probably) disabled"
fi
fi
fn_status > /dev/null 2>&1
if [ $status == 0 ] ; then
echo "ERROR - server did not start." | tee -a "${log}"
fi
}
fn_update(){
if $synhl2 ; then
echo "Half-Life 2 content is enabled"
hl2dl="+app_update xxx"
fi
${rootdir}/steamcmd/steamcmd.sh +login "${steamuser}" "${steampass}" +force_install_dir "${filesdir}" +app_update "${appid}" ${branch} +download_depot "${appid}" "${depotid}" +quit | tee -a "${log}"
}
fn_update_content(){
synhl2=true # Half-Life 2
synep1=true # Half-Life 2: Episode One
synep2=true # Half-Life 2: Episode Two
synlost=false # Half-Life 2: Lost Coast
synhl1=false # Half-Life: Source
synmeta=false # MINERVIA: Metastasis
synbase=false
# Currently does not automatically enable the content on the Synergy server
}
fn_status(){
status=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
if test ${status} -gt 0 ; then
echo "Synergy server is running." 1>&2
running="running"
pfrunning=${pfgreen}
else
echo "Synergy server not running... (not) Starting..." 1>&2
running="not running"
pfrunning=${pfred}
fi
}
fn_stop(){
tmux send -t "${servicename}" quit ENTER > /dev/null 2>&1
echo "$(date) - Stopping server..." >> ${log}
for seconds in {1..30}; do
fn_status > /dev/null 2>&1
if [ ${status} == "0" ] ; then
echo -e "Graceful: rcon quit: ${seconds}: " | tee -a "${log}"
break
fi
sleep 1
done
fn_status > /dev/null 2>&1
if [ ${status} != "0" ] ; then
echo "Graceful: rcon quit: " | tee -a "${log}"
echo "I can't stop this feeling, deep inside of me, girl, you just don't realize, what you do to me"
fi
sleep 1
tmux kill-session -t "${servicename}" > /dev/null 2>&1 # Kill tmux session
sleep 0.5
fn_status > /dev/null 2>&1
if [ ${status} == "0" ] ; then
rm -f "${rootdir}/${lockselfname}" # Remove lockfile
echo "Stopped ${servicename}" | tee -a "${log}"
else
echo "Unable to stop${servicename}" | tee -a "${log}"
fi
exit 0
}
fn_console(){
echo "Wello; horld?"
consolemode=true
fn_start
}
fn_debug(){
echo "WARNING: theres probably a bug somewhere, but I'm not really sure where tbh"
params="${params} -debug"
fn_start
}
fn_help(){
fn_status > /dev/null 2>&1
clm="${pfblue}%-15s${pfreset}%-15s\n"
cmds=(" start" " stop" " status" " update" " console" " debug" " help")
tips=("starts" "stops" "Checks whether the server is running or not (It's ${pfrunning}${running})." "Checks for and applies updates to the server." "consoles." "Starts the server in debug mode (currently does nothing)." "What you're looking at right now.")
printf "${pfred}Commands${pfreset}"\ "\n"
for ((i = 0; i < ${#cmds[@]}; ++i)) ; do
printf "$clm" "${cmds[$i]}" "${tips[$i]}"
done
}
fn_minimal(){
fn_status
echo "$(date) - Starting server in minimal mode..." | tee -a "${log}"
if [ ${status} == 0 ] ; then
date > "${rootdir}/${lockselfname}"
cd "${homedir}"
ls ${executabledir}
${executabledir}/srcds_linux $params -debug
else
echo "WE CANT STAAAAAAAART, WE WONT STAAAAAART"
fi
}
fn_colortest(){
printf "${pfred}pfred ${pfgreen}pfgreen ${pfyellow}pfyellow ${pfblue}pfblue ${pfpurple}pfpurple ${pfreset}pfreset\n"
printf "I spent way too on this${pfreset}\n"
}
if [ $# == 0 ] ; then
printf "Synergy server manager by Rob Chiocchio\nUsage: ./$selfname [option]\n"
fn_help
fi
while test $# -gt 0 ; do
case "$1" in
start) fn_start
;;
stop) fn_stop
;;
status) fn_status
;;
update) fn_update
;;
console) fn_console
;;
debug) fn_debug
;;
help) fn_help
;;
colortest) fn_colortest
;;
version) echo "who knows?"
;;
minimal) fn_minimal
esac
shift
done
exit 0
@RobChiocchio
Copy link
Author

RobChiocchio commented Mar 4, 2017

Incomplete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment