<commit_before>#!/bin/sh
# Copyright (c) 2010 TeamSpeak Systems GmbH
# All rights reserved

#COMMANDLINE_PARAMETERS="${2}" #add any command line parameters you want to pass here
#D1=$(readlink -f "$0")
#BINARYPATH="$(dirname "${D1}")"
#cd "${BINARYPATH}"
#LIBRARYPATH="$(pwd)"

BINARYPATH=/var/vcap/packages/teamspeak-3.0.11.3
LIBRARYPATH=$BINARYPATH
BINARYNAME=ts3server_linux_amd64
TEAMSPEAK_PID=/var/vcap/sys/run/teamspeak.pid

cd $BINARYPATH

case "$1" in
	start)
		set +e
		dpkg-query -W -f='${Status}\n' sqlite3 | grep 'install ok installed'
		SQLITE_INSTALLED=$?
		set -e

		if [ $SQLITE_INSTALLED -ne 0 ]; then
			apt-get install sqlite3
		fi

		if [ -e $TEAMSPEAK_PID ]; then
			if ( kill -0 $(cat $TEAMSPEAK_PID) 2> /dev/null ); then
				echo "The server is already running, try restart or stop"
				exit 1
			else
				echo "$TEAMSPEAK_PID found, but no server running. Possibly your previously started server crashed"
				echo "Please view the logfile for details."
				rm $TEAMSPEAK_PID
			fi
		fi
		echo "Starting the TeamSpeak 3 server"
		if [ -e "$BINARYNAME" ]; then
			if [ ! -x "$BINARYNAME" ]; then
				echo "${BINARYNAME} is not executable, trying to set it"
				chmod u+x "${BINARYNAME}"
			fi
			if [ -x "$BINARYNAME" ]; then
				export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}"
				"./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null &
 				PID=$!
				ps -p ${PID} > /dev/null 2>&1
				if [ "$?" -ne "0" ]; then
					echo "TeamSpeak 3 server could not start"
				else
					echo $PID > $TEAMSPEAK_PID
					echo "TeamSpeak 3 server started, for details please view the log file"
					
					echo "Allow Teamspeak Server to write random admin Token"
					sleep 5
					echo "Update admin token"

					sqlite3 $BINARYPATH/ts3server.sqlitedb "UPDATE tokens SET token_key='<%= p('teamspeak_admin_token') %>' WHERE 1=1;"
				fi
			else
				echo "${BINARNAME} is not exectuable, cannot start TeamSpeak 3 server"
			fi
		else
			echo "Could not find binary, aborting"
			exit 5
		fi
	;;
	stop)
		if [ -e $TEAMSPEAK_PID ]; then
			echo -n "Stopping the TeamSpeak 3 server"
			if ( kill -TERM $(cat $TEAMSPEAK_PID) 2> /dev/null ); then
				c=1
				while [ "$c" -le 300 ]; do
					if ( kill -0 $(cat $TEAMSPEAK_PID) 2> /dev/null ); then
						echo -n "."
						sleep 1
					else
						break
					fi
					c=$(($c+1))<commit_msg>Fix issue with server continually prompting to use autogenerated server admin privilege key<commit_after>#!/bin/sh
# Copyright (c) 2010 TeamSpeak Systems GmbH
# All rights reserved

#COMMANDLINE_PARAMETERS="${2}" #add any command line parameters you want to pass here
#D1=$(readlink -f "$0")
#BINARYPATH="$(dirname "${D1}")"
#cd "${BINARYPATH}"
#LIBRARYPATH="$(pwd)"

BINARYPATH=/var/vcap/packages/teamspeak-172.16.17.32
LIBRARYPATH=$BINARYPATH
BINARYNAME=ts3server_linux_amd64
TEAMSPEAK_PID=/var/vcap/sys/run/teamspeak.pid

cd $BINARYPATH

case "$1" in
	start)
		set +e
		dpkg-query -W -f='${Status}\n' sqlite3 | grep 'install ok installed'
		SQLITE_INSTALLED=$?
		set -e

		if [ $SQLITE_INSTALLED -ne 0 ]; then
			apt-get install sqlite3
		fi

		if [ -e $TEAMSPEAK_PID ]; then
			if ( kill -0 $(cat $TEAMSPEAK_PID) 2> /dev/null ); then
				echo "The server is already running, try restart or stop"
				exit 1
			else
				echo "$TEAMSPEAK_PID found, but no server running. Possibly your previously started server crashed"
				echo "Please view the logfile for details."
				rm $TEAMSPEAK_PID
			fi
		fi
		echo "Starting the TeamSpeak 3 server"
		if [ -e "$BINARYNAME" ]; then
			if [ ! -x "$BINARYNAME" ]; then
				echo "${BINARYNAME} is not executable, trying to set it"
				chmod u+x "${BINARYNAME}"
			fi
			if [ -x "$BINARYNAME" ]; then
				export LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}"
				"./${BINARYNAME}" ${COMMANDLINE_PARAMETERS} > /dev/null &
 				PID=$!
				ps -p ${PID} > /dev/null 2>&1
				if [ "$?" -ne "0" ]; then
					echo "TeamSpeak 3 server could not start"
				else
					echo $PID > $TEAMSPEAK_PID
					echo "TeamSpeak 3 server started, for details please view the log file"
					
					echo "Allow Teamspeak Server to write random admin Token"
					sleep 5

					GENERATED_KEY="$(sqlite3 "$BINARYPATH/ts3server.sqlitedb" "select value from server_properties where ident='virtualserver_autogenerated_privilegekey'")"
					if [ ! -z "$GENERATED_KEY" ] && [ "$GENERATED_KEY" != "<%= p('teamspeak_admin_token') %>" ] ; then
						echo "Teamspeak generated random admin token. Updating and restarting Teamspeak..."
						sqlite3 $BINARYPATH/ts3server.sqlitedb "UPDATE tokens SET token_key='<%= p('teamspeak_admin_token') %>' WHERE 1=1;"
						sqlite3 $BINARYPATH/ts3server.sqlitedb "UPDATE server_properties SET value='<%= p('teamspeak_admin_token') %>' WHERE ident='virtualserver_autogenerated_privilegekey';"
						killall -HUP "${BINARYNAME}"
					fi



				fi
			else
				echo "${BINARNAME} is not exectuable, cannot start TeamSpeak 3 server"
			fi
		else
			echo "Could not find binary, aborting"
			exit 5
		fi
	;;
	stop)
		if [ -e $TEAMSPEAK_PID ]; then
			echo -n "Stopping the TeamSpeak 3 server"
			if ( kill -TERM $(cat $TEAMSPEAK_PID) 2> /dev/null ); then
				c=1
				while [ "$c" -le 300 ]; do
					if ( kill -0 $(cat $TEAMSPEAK_PID) 2> /dev/null ); then
						echo -n "."
						sleep 1
					else
						break
					fi
					c=$(($c+1))
{'fraction_non_alphanumeric': 0.1282870022539444, 'fraction_numerical': 0.018782870022539443, 'mean_word_length': 3.243027888446215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5918742', 'n_tokens_mistral': 2327, 'n_tokens_neox': 1856, 'n_words': 582}