<commit_before>#!/bin/bash
# TravisCI Tests
# Server Management Script
# Author: <NAME>
# Website: http://gameservermanagers.com
version="011115"

#### Variables ####

# Notification Email
# (on|off)
emailnotification="on"
email="<EMAIL>"

# Steam login
steamuser="anonymous"
steampass=""

# Start Variables
updateonstart="off"

fn_parms(){
parms=""
}

#### Advanced Variables ####

# Steam
appid="261140"

# Server Details
servicename="jc2-server"
gamename="Just Cause 2"
engine="avalanche"

# Directories
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
selfname="$(basename $0)"
lockselfname=".${servicename}.lock"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}"
executabledir="${filesdir}"
executable="./Jcmp-Server"
servercfg="config.lua"
servercfgdir="${filesdir}"
servercfgfullpath="${servercfgdir}/${servercfg}"
servercfgdefault="${servercfgdir}/default_config.lua"
backupdir="${rootdir}/backups"

# Logging
logdays="7"
#gamelogdir="" # No server logs available
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

fn_runfunction(){
# Functions are downloaded and run with this function
if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
	cd "${rootdir}"
	if [ ! -d "functions" ]; then
		mkdir functions
	fi
	cd functions
	echo -e "    loading ${functionfile}...\c"
	wget -N /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
	chmod +x "${functionfile}"
	cd "${rootdir}"
fi
source "${rootdir}/functions/${functionfile}"
}

fn_functions(){
# Functions are defined in fn_functions.
functionfile="${FUNCNAME}"
fn_runfunction
}

fn_functions

fn_currentstatus(){
if [ "${gamename}" == "Teamspeak 3" ]; then
	fn_check_ts3status
	ts3status=$(${executable} status servercfgfullpathfile=${servercfgfullpath})
else
	pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
fi

#echo "${ts3status}"
if [ "${pid}" == "0" ]||[ "${ts3status}" != "Server is running" ]; then
	currentstatus="OFFLINE"
else
	currentstatus="ONLINE"
fi
}
	
fn_setstatus(){
	fn_currentstatus
	
	echo""
	echo "Required status: ${requiredstatus}"
	counter=0
	echo "Current status:  ${currentstatus}"
    while [  "${requiredstatus}" != "${currentstatus}" ]; do
    	counter=$((counter+1))
    	fn_currentstatus
		echo -ne "New status:  ${currentstatus}\\r"
    	
		if [ "${requiredstatus}" == "ONLINE" ]; then
			(fn_start > /dev/null 2>&1)
		else
			(fn_stop > /dev/null 2>&1)
		fi
    	if [ "${counter}" -gt "5" ]; then
    		currentstatus="FAIL"
    		echo "Current status:  ${currentstatus}"
    		echo ""
    		echo "Unable to start or stop server."
    		exit 1
    	fi
    done
    echo -ne "Current status:  ${currentstatus}\\r"
    echo -e "\n"
    echo "Test starting:"<commit_msg>removed devnull to see output<commit_after>#!/bin/bash
# TravisCI Tests
# Server Management Script
# Author: <NAME>
# Website: http://gameservermanagers.com
version="011115"

#### Variables ####

# Notification Email
# (on|off)
emailnotification="on"
email="<EMAIL>"

# Steam login
steamuser="anonymous"
steampass=""

# Start Variables
updateonstart="off"

fn_parms(){
parms=""
}

#### Advanced Variables ####

# Steam
appid="261140"

# Server Details
servicename="jc2-server"
gamename="Just Cause 2"
engine="avalanche"

# Directories
rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
selfname="$(basename $0)"
lockselfname=".${servicename}.lock"
filesdir="${rootdir}/serverfiles"
systemdir="${filesdir}"
executabledir="${filesdir}"
executable="./Jcmp-Server"
servercfg="config.lua"
servercfgdir="${filesdir}"
servercfgfullpath="${servercfgdir}/${servercfg}"
servercfgdefault="${servercfgdir}/default_config.lua"
backupdir="${rootdir}/backups"

# Logging
logdays="7"
#gamelogdir="" # No server logs available
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

fn_runfunction(){
# Functions are downloaded and run with this function
if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
	cd "${rootdir}"
	if [ ! -d "functions" ]; then
		mkdir functions
	fi
	cd functions
	echo -e "    loading ${functionfile}...\c"
	wget -N /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
	chmod +x "${functionfile}"
	cd "${rootdir}"
fi
source "${rootdir}/functions/${functionfile}"
}

fn_functions(){
# Functions are defined in fn_functions.
functionfile="${FUNCNAME}"
fn_runfunction
}

fn_functions

fn_currentstatus(){
if [ "${gamename}" == "Teamspeak 3" ]; then
	fn_check_ts3status
	ts3status=$(${executable} status servercfgfullpathfile=${servercfgfullpath})
else
	pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
fi

#echo "${ts3status}"
if [ "${pid}" == "0" ]||[ "${ts3status}" != "Server is running" ]; then
	currentstatus="OFFLINE"
else
	currentstatus="ONLINE"
fi
}
	
fn_setstatus(){
	fn_currentstatus
	
	echo""
	echo "Required status: ${requiredstatus}"
	counter=0
	echo "Current status:  ${currentstatus}"
    while [  "${requiredstatus}" != "${currentstatus}" ]; do
    	counter=$((counter+1))
    	fn_currentstatus
		echo -ne "New status:  ${currentstatus}\\r"
    	
		if [ "${requiredstatus}" == "ONLINE" ]; then
			(fn_start)
		else
			(fn_stop > /dev/null 2>&1)
		fi
    	if [ "${counter}" -gt "5" ]; then
    		currentstatus="FAIL"
    		echo "Current status:  ${currentstatus}"
    		echo ""
    		echo "Unable to start or stop server."
    		exit 1
    	fi
    done
    echo -ne "Current status:  ${currentstatus}\\r"
    echo -e "\n"
    echo "Test starting:"
{'fraction_non_alphanumeric': 0.19151610369206598, 'fraction_numerical': 0.01225451688923802, 'mean_word_length': 5.132947976878612, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1970739', 'n_tokens_mistral': 2269, 'n_tokens_neox': 2172, 'n_words': 465}