From da0dc10e999f79a1807de8ebddf009c3585c10ee Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 30 Oct 2015 22:37:19 +0000 Subject: [PATCH 01/13] Adding deps to tests Want to see the results --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a2d1726d6..8c7e9a36b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: bash before_script: - curl -L "https://shunit2.googlecode.com/files/shunit2-2.1.6.tgz" | tar zx + - sudo apt-get install tmux mailutils postfix lib32gcc1 libstdc++6 libstdc++6:i386 - mkdir /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles - touch /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles/serverconfig.xml From f46be948e2d41602478be7bc76f8c5f14fdfddc9 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 30 Oct 2015 22:38:38 +0000 Subject: [PATCH 02/13] correction --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c7e9a36b..52a01b49d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: bash before_script: - curl -L "https://shunit2.googlecode.com/files/shunit2-2.1.6.tgz" | tar zx - - sudo apt-get install tmux mailutils postfix lib32gcc1 libstdc++6 libstdc++6:i386 + - sudo apt-get update -qq + - sudo apt-get install -y tmux mailutils postfix lib32gcc1 libstdc++6 libstdc++6:i386 - mkdir /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles - touch /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles/serverconfig.xml From 053c62ef58afff8f05ab3731f42a13adbe808897 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 30 Oct 2015 22:46:10 +0000 Subject: [PATCH 03/13] minor bug --- functions/fn_details_distro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/fn_details_distro b/functions/fn_details_distro index 11122d7f6..4246d4a89 100644 --- a/functions/fn_details_distro +++ b/functions/fn_details_distro @@ -29,7 +29,7 @@ glibcv=$(ldd --version |grep ldd|awk '{print $NF}') # e.g: tmux 1.6 if [ -z "$(command -v tmux)" ]; then tmuxv="\e[0;31mNOT INSTALLED!\e[0m" -elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:])' -lt "16" ]; then +elif [ "$(tmux -V|sed "s/tmux //"|sed -n '1 p'|tr -cd '[:digit:]')" -lt "16" ]; then tmuxv="$(tmux -V) (>= 1.6 required for console log)" else tmuxv=$(tmux -V) From 3f9eb50c05affc3fcee5d8b14beb2eb1845ed55c Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 30 Oct 2015 23:04:23 +0000 Subject: [PATCH 04/13] trying container infra on travis --- .travis.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 52a01b49d..95a170f9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,25 @@ language: bash +sudo: false +env: +- DISTRO=ubuntu-trusty before_script: - curl -L "https://shunit2.googlecode.com/files/shunit2-2.1.6.tgz" | tar zx - - sudo apt-get update -qq - - sudo apt-get install -y tmux mailutils postfix lib32gcc1 libstdc++6 libstdc++6:i386 +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - tmux + - mailutils + - postfix + - lib32gcc1 + - libstdc++6 + - libstdc++6:i386 + - telnet + - expect + - mkdir /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles - touch /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles/serverconfig.xml From 5c171bedd082b026b94ee90d389b42084b654339 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 03:24:40 +0000 Subject: [PATCH 05/13] removed space --- Arma3/arma3server | 1 - 1 file changed, 1 deletion(-) diff --git a/Arma3/arma3server b/Arma3/arma3server index 4620961fe..437d05a88 100644 --- a/Arma3/arma3server +++ b/Arma3/arma3server @@ -1,4 +1,3 @@ - #!/bin/bash # ARMA 3 # Server Management Script From 5d3337c8a4a139b6864494c8356532f9dcc30bdb Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 03:27:57 +0000 Subject: [PATCH 06/13] Started work on test script --- test.sh | 353 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 test.sh diff --git a/test.sh b/test.sh new file mode 100644 index 000000000..f2e6cc30c --- /dev/null +++ b/test.sh @@ -0,0 +1,353 @@ +#!/bin/bash +# Just Cause 2 +# Server Management Script +# Author: Daniel Gibbs +# Website: http://gameservermanagers.com +version="150715" + +#### Variables #### + +# Notification Email +# (on|off) +emailnotification="off" +email="email@example.com" + +# 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 + +getopt=$1 + +fn_currentstatus(){ +pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:") +if [ "${pid}" == "0" ]; then + currentstatus="OFFLINE" +else + currentstatus="ONLINE" +fi +} + +fn_setstatus(){ + fn_currentstatus + + echo"" + echo "Required status: ${requiredstatus}" + while [ "${requiredstatus}" != "${currentstatus}" ]; do + fn_currentstatus + echo -ne "Current status: ${currentstatus}\\r" + if [ "${requiredstatus}" == "ONLINE" ]; then + (fn_start > /dev/null 2>&1) + else + (fn_stop > /dev/null 2>&1) + fi + done + echo -ne "Current status: ${currentstatus}\\r" + echo -e "\n" + echo "Test starting:" + echo "" + sleep 0.5 +} + +echo "1.0 - start - no files" +echo "=================================" +echo "Description:" +echo "Test script reaction to missing server files." +requiredstatus="OFFLINE" +fn_setstatus +(fn_start) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "2.0 - install" +echo "=================================" +echo "Description:" +echo "install ${gamename} server." +requiredstatus="OFFLINE" +fn_setstatus +fn_autoinstall +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.1 - start" +echo "=================================" +echo "Description:" +echo "start ${gamename} server." +requiredstatus="OFFLINE" +fn_setstatus +fn_start +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.2 - start - online" +echo "=================================" +echo "Description:" +echo "start ${gamename} server while already running." +requiredstatus="ONLINE" +fn_setstatus +(fn_start) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.3 - stop" +echo "=================================" +echo "Description:" +echo "stop ${gamename} server." +requiredstatus="ONLINE" +fn_setstatus +fn_stop +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.4 - stop - offline" +echo "=================================" +echo "Description:" +echo "stop ${gamename} server while already stopped." +requiredstatus="OFFLINE" +fn_setstatus +(fn_stop) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.5 - restart" +echo "=================================" +echo "Description:" +echo "restart ${gamename}." +requiredstatus="ONLINE" +fn_setstatus +fn_restart +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.5 - restart - offline" +echo "=================================" +echo "Description:" +echo "restart ${gamename} while already stopped." +requiredstatus="OFFLINE" +fn_setstatus +fn_restart +echo "" +echo "Test complete!" +sleep 1 +echo "" + +echo "4.1 - update" +echo "=================================" +echo "Description:" +echo "check for updates." +requiredstatus="OFFLINE" +fn_setstatus +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.2 - update - change buildid" +echo "=================================" +echo "Description:" +echo "change the buildid tricking SteamCMD to update." +requiredstatus="OFFLINE" +fn_setstatus +fn_printinfonl "changed buildid to 0." +sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.3 - update - change buildid - online" +echo "=================================" +echo "Description:" +echo "change the buildid tricking SteamCMD to update server while already running." +requiredstatus="ONLINE" +fn_setstatus +fn_printinfonl "changed buildid to 0." +sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.4 - update - remove appmanifest file" +echo "=================================" +echo "Description:" +echo "removing appmanifest file will cause script to repair." +requiredstatus="OFFLINE" +fn_setstatus +fn_printinfonl "removed appmanifest_${appid}.acf." +rm --verbose "${filesdir}/steamapps/appmanifest_${appid}.acf" +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.5 - force-update" +echo "=================================" +echo "Description:" +echo "force-update bypassing update check." +requiredstatus="OFFLINE" +fn_setstatus +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.6 - force-update - online" +echo "=================================" +echo "Description:" +echo "force-update bypassing update check server while already running." +requiredstatus="ONLINE" +fn_setstatus +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.7 - validate" +echo "=================================" +echo "Description:" +echo "validate server files." +requiredstatus="OFFLINE" +fn_setstatus +fn_validate +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.8 - validate - online" +echo "=================================" +echo "Description:" +echo "validate server files while server while already running." +requiredstatus="ONLINE" +fn_setstatus +fn_validate +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.1 - monitor - online" +echo "=================================" +echo "Description:" +echo "run monitor server while already running." +requiredstatus="ONLINE" +fn_setstatus +(fn_monitor) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.2 - monitor - offline - no lockfile" +echo "=================================" +echo "Description:" +echo "run monitor while server is offline with no lockfile" +requiredstatus="OFFLINE" +fn_setstatus +(fn_monitor) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.2 - monitor - offline - with lockfile" +echo "=================================" +echo "Description:" +echo "run monitor while server is offline with no lockfile" +requiredstatus="OFFLINE" +fn_setstatus +fn_printinfonl "creating lockfile." +date > "${rootdir}/${lockselfname}" +(fn_monitor) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.2 - monitor - gsquery.py failure" +echo "=================================" +echo "Description:" +echo "gsquery.py will fail to query port" +requiredstatus="ONLINE" +fn_setstatus +port=${port+1} +(fn_monitor) +port=${port-1} +echo "" +echo "Test complete!" +sleep 1 +echo "" + From ddf9b26de8d25d0b7c4f545050036274126ccae3 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 12:19:16 +0000 Subject: [PATCH 07/13] New test script --- .travis.yml | 158 +--------------------------------------------------- test.sh | 66 ++++++++++++++++++---- 2 files changed, 57 insertions(+), 167 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95a170f9d..85148ae4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,162 +20,6 @@ addons: - telnet - expect - - - mkdir /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles - - touch /home/travis/build/dgibbs64/linuxgsm/7DaysToDie/serverfiles/serverconfig.xml - - - mkdir /home/travis/build/dgibbs64/linuxgsm/CounterStrike/serverfiles/ - - mkdir /home/travis/build/dgibbs64/linuxgsm/CounterStrike/serverfiles/cstrike - - - mkdir /home/travis/build/dgibbs64/linuxgsm/CounterStrikeGlobalOffensive/serverfiles/ - - mkdir /home/travis/build/dgibbs64/linuxgsm/CounterStrikeGlobalOffensive/serverfiles/csgo - - mkdir /home/travis/build/dgibbs64/linuxgsm/CounterStrikeGlobalOffensive/serverfiles/csgo/cfg - - - mkdir /home/travis/build/dgibbs64/linuxgsm/JustCause2/serverfiles/ - - touch /home/travis/build/dgibbs64/linuxgsm/JustCause2/serverfiles/default_config.lua - - - mkdir /home/travis/build/dgibbs64/linuxgsm/KillingFloor/serverfiles - - mkdir /home/travis/build/dgibbs64/linuxgsm/KillingFloor/serverfiles/System - - touch /home/travis/build/dgibbs64/linuxgsm/KillingFloor/serverfiles/System/Default.ini - - - mkdir /home/travis/build/dgibbs64/linuxgsm/ProjectZomboid/Zomboid - - mkdir /home/travis/build/dgibbs64/linuxgsm/ProjectZomboid/Zomboid/Server - - mkdir /home/travis/build/dgibbs64/linuxgsm/ProjectZomboid/serverfiles - - mkdir /home/travis/build/dgibbs64/linuxgsm/ProjectZomboid/serverfiles/projectzomboid - - - mkdir /home/travis/build/dgibbs64/linuxgsm/SeriousSam3BFE/serverfiles - - mkdir /home/travis/build/dgibbs64/linuxgsm/SeriousSam3BFE/serverfiles/Content/ - - mkdir /home/travis/build/dgibbs64/linuxgsm/SeriousSam3BFE/serverfiles/Content/SeriousSam3 - - mkdir /home/travis/build/dgibbs64/linuxgsm/SeriousSam3BFE/serverfiles/Content/SeriousSam3/Config - - mkdir /home/travis/build/dgibbs64/linuxgsm/SeriousSam3BFE/serverfiles/Bin - - - mkdir /home/travis/build/dgibbs64/linuxgsm/UnrealTournament2004/serverfiles - - mkdir /home/travis/build/dgibbs64/linuxgsm/UnrealTournament2004/serverfiles/System - - touch /home/travis/build/dgibbs64/linuxgsm/UnrealTournament2004/serverfiles/System/ut2k4-server.ini - - - mkdir /home/travis/build/dgibbs64/linuxgsm/UnrealTournament99/serverfiles - - mkdir /home/travis/build/dgibbs64/linuxgsm/UnrealTournament99/serverfiles/System - - touch /home/travis/build/dgibbs64/linuxgsm/UnrealTournament99/serverfiles/System/ut99-server.ini - - mkdir /home/travis/build/dgibbs64/linuxgsm/TeamSpeak3/serverfiles script: - - bash 7DaysToDie/sdtdserver auto-install - - bash 7DaysToDie/sdtdserver start - - bash 7DaysToDie/sdtdserver stop - - bash 7DaysToDie/sdtdserver restart - - bash 7DaysToDie/sdtdserver validate - - bash 7DaysToDie/sdtdserver monitor - - bash 7DaysToDie/sdtdserver email-test - - bash 7DaysToDie/sdtdserver details - - - bash Arma3/arma3server auto-install - - bash Arma3/arma3server start - - bash Arma3/arma3server stop - - bash Arma3/arma3server restart - - bash Arma3/arma3server validate - - bash Arma3/arma3server monitor - - bash Arma3/arma3server email-test - - bash Arma3/arma3server details - - - bash CounterStrike/csserver auto-install - - bash CounterStrike/csserver start - - bash CounterStrike/csserver stop - - bash CounterStrike/csserver restart - - bash CounterStrike/csserver validate - - bash CounterStrike/csserver monitor - - bash CounterStrike/csserver email-test - - bash CounterStrike/csserver details - - - bash CounterStrikeGlobalOffensive/csgoserver auto-install - - bash CounterStrikeGlobalOffensive/csgoserver start - - bash CounterStrikeGlobalOffensive/csgoserver stop - - bash CounterStrikeGlobalOffensive/csgoserver restart - - bash CounterStrikeGlobalOffensive/csgoserver validate - - bash CounterStrikeGlobalOffensive/csgoserver monitor - - bash CounterStrikeGlobalOffensive/csgoserver email-test - - bash CounterStrikeGlobalOffensive/csgoserver details - - - bash JustCause2/jc2server auto-install - - bash JustCause2/jc2server start - - bash JustCause2/jc2server stop - - bash JustCause2/jc2server restart - - bash JustCause2/jc2server validate - - bash JustCause2/jc2server monitor - - bash JustCause2/jc2server email-test - - bash JustCause2/jc2server details - - - bash KillingFloor/kfserver auto-install - - bash KillingFloor/kfserver start - - bash KillingFloor/kfserver stop - - bash KillingFloor/kfserver restart - - bash KillingFloor/kfserver validate - - bash KillingFloor/kfserver monitor - - bash KillingFloor/kfserver email-test - - bash KillingFloor/kfserver details - - - bash NaturalSelection2/ns2server auto-install - - bash NaturalSelection2/ns2server start - - bash NaturalSelection2/ns2server stop - - bash NaturalSelection2/ns2server restart - - bash NaturalSelection2/ns2server validate - - bash NaturalSelection2/ns2server monitor - - bash NaturalSelection2/ns2server email-test - - bash NaturalSelection2/ns2server details - - - bash ProjectZomboid/pzserver auto-install - - bash ProjectZomboid/pzserver start - - bash ProjectZomboid/pzserver stop - - bash ProjectZomboid/pzserver restart - - bash ProjectZomboid/pzserver validate - - bash ProjectZomboid/pzserver monitor - - bash ProjectZomboid/pzserver email-test - - bash ProjectZomboid/pzserver details - - - bash SeriousSam3BFE/ss3sserver auto-install - - bash SeriousSam3BFE/ss3sserver start - - bash SeriousSam3BFE/ss3sserver stop - - bash SeriousSam3BFE/ss3sserver restart - - bash SeriousSam3BFE/ss3sserver validate - - bash SeriousSam3BFE/ss3sserver monitor - - bash SeriousSam3BFE/ss3sserver email-test - - bash SeriousSam3BFE/ss3sserver details - - - bash StarBound/sbserver auto-install - - bash StarBound/sbserver start - - bash StarBound/sbserver stop - - bash StarBound/sbserver restart - - bash StarBound/sbserver validate - - bash StarBound/sbserver monitor - - bash StarBound/sbserver email-test - - bash StarBound/sbserver details - - - bash Terraria/terrariaserver auto-install - - bash Terraria/terrariaserver start - - bash Terraria/terrariaserver stop - - bash Terraria/terrariaserver restart - - bash Terraria/terrariaserver validate - - bash Terraria/terrariaserver monitor - - bash Terraria/terrariaserver email-test - - bash Terraria/terrariaserver details - - - bash UnrealTournament2004/ut2k4server start - - bash UnrealTournament2004/ut2k4server stop - - bash UnrealTournament2004/ut2k4server restart - - bash UnrealTournament2004/ut2k4server monitor - - bash UnrealTournament2004/ut2k4server email-test - - bash UnrealTournament2004/ut2k4server details - - - bash UnrealTournament99/ut99server start - - bash UnrealTournament99/ut99server stop - - bash UnrealTournament99/ut99server restart - - bash UnrealTournament99/ut99server monitor - - bash UnrealTournament99/ut99server email-test - - bash UnrealTournament99/ut99server details - - - bash TeamSpeak3/ts3server start - - bash TeamSpeak3/ts3server stop - - bash TeamSpeak3/ts3server restart - - bash TeamSpeak3/ts3server update - - bash TeamSpeak3/ts3server monitor - - bash TeamSpeak3/ts3server email-test - - bash TeamSpeak3/ts3server details + - bash test.sh \ No newline at end of file diff --git a/test.sh b/test.sh index f2e6cc30c..ce8efa06e 100644 --- a/test.sh +++ b/test.sh @@ -9,8 +9,8 @@ version="150715" # Notification Email # (on|off) -emailnotification="off" -email="email@example.com" +emailnotification="on" +email="me@danielgibbs.co.uk" # Steam login steamuser="anonymous" @@ -103,14 +103,24 @@ fn_setstatus(){ echo"" echo "Required status: ${requiredstatus}" + counter=0 while [ "${requiredstatus}" != "${currentstatus}" ]; do + counter=$((counter+1)) fn_currentstatus + echo -ne "Current 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 + fi done echo -ne "Current status: ${currentstatus}\\r" echo -e "\n" @@ -119,6 +129,16 @@ fn_setstatus(){ sleep 0.5 } +echo "=================================" +echo "TravisCI Tests" +echo "Linux Game Server Manager" +echo "by Daniel Gibbs" +echo "http://gameservermanagers.com" +echo "=================================" +echo "" + + + echo "1.0 - start - no files" echo "=================================" echo "Description:" @@ -130,6 +150,9 @@ echo "" echo "Test complete!" sleep 1 echo "" + + + echo "2.0 - install" echo "=================================" echo "Description:" @@ -141,6 +164,9 @@ echo "" echo "Test complete!" sleep 1 echo "" + + + echo "3.1 - start" echo "=================================" echo "Description:" @@ -208,6 +234,8 @@ echo "Test complete!" sleep 1 echo "" + + echo "4.1 - update" echo "=================================" echo "Description:" @@ -302,6 +330,9 @@ echo "" echo "Test complete!" sleep 1 echo "" + + + echo "5.1 - monitor - online" echo "=================================" echo "Description:" @@ -316,7 +347,7 @@ echo "" echo "5.2 - monitor - offline - no lockfile" echo "=================================" echo "Description:" -echo "run monitor while server is offline with no lockfile" +echo "run monitor while server is offline with no lockfile." requiredstatus="OFFLINE" fn_setstatus (fn_monitor) @@ -324,10 +355,10 @@ echo "" echo "Test complete!" sleep 1 echo "" -echo "5.2 - monitor - offline - with lockfile" +echo "5.3 - monitor - offline - with lockfile" echo "=================================" echo "Description:" -echo "run monitor while server is offline with no lockfile" +echo "run monitor while server is offline with no lockfile." requiredstatus="OFFLINE" fn_setstatus fn_printinfonl "creating lockfile." @@ -337,17 +368,32 @@ echo "" echo "Test complete!" sleep 1 echo "" -echo "5.2 - monitor - gsquery.py failure" +echo "5.4 - monitor - gsquery.py failure" echo "=================================" echo "Description:" -echo "gsquery.py will fail to query port" +echo "gsquery.py will fail to query port." requiredstatus="ONLINE" fn_setstatus -port=${port+1} -(fn_monitor) -port=${port-1} +sed -i 's/[0-9]\+/0/' "${servercfgfullpath}" +fn_monitor +echo "" +fn_printinfonl "Reseting ${servercfg}." +fn_install_config echo "" echo "Test complete!" sleep 1 echo "" + + +echo "6.0 - details" +echo "=================================" +echo "Description:" +echo "gsquery.py will fail to query port." +requiredstatus="ONLINE" +fn_setstatus +fn_details +echo "" +echo "Test complete!" +sleep 1 +echo "" \ No newline at end of file From 9a9c80f743bda08cbf7f861383be3bbf5f1284c8 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 18:39:24 +0000 Subject: [PATCH 08/13] further test improvements --- test.sh | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 7 deletions(-) diff --git a/test.sh b/test.sh index ce8efa06e..839b7538c 100644 --- a/test.sh +++ b/test.sh @@ -34,7 +34,7 @@ gamename="Just Cause 2" engine="avalanche" # Directories -rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/jc2server" selfname="$(basename $0)" lockselfname=".${servicename}.lock" filesdir="${rootdir}/serverfiles" @@ -136,7 +136,14 @@ echo "by Daniel Gibbs" echo "http://gameservermanagers.com" echo "=================================" echo "" - +sleep 1 +echo "=================================" +echo "Generic Server Tests" +echo "Using: ${gamename}" +echo "=================================" +echo "" +sleep 1 +mkdir ${rootfdir} echo "1.0 - start - no files" @@ -189,7 +196,21 @@ echo "" echo "Test complete!" sleep 1 echo "" -echo "3.3 - stop" +echo "3.3 - start - updateonstart" +echo "=================================" +echo "Description:" +echo "will update server on start." +requiredstatus="ONLINE" +fn_setstatus +( + updateonstart="on" + fn_start +) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.4 - stop" echo "=================================" echo "Description:" echo "stop ${gamename} server." @@ -200,7 +221,7 @@ echo "" echo "Test complete!" sleep 1 echo "" -echo "3.4 - stop - offline" +echo "3.5 - stop - offline" echo "=================================" echo "Description:" echo "stop ${gamename} server while already stopped." @@ -211,7 +232,7 @@ echo "" echo "Test complete!" sleep 1 echo "" -echo "3.5 - restart" +echo "3.6 - restart" echo "=================================" echo "Description:" echo "restart ${gamename}." @@ -222,7 +243,7 @@ echo "" echo "Test complete!" sleep 1 echo "" -echo "3.5 - restart - offline" +echo "3.7 - restart - offline" echo "=================================" echo "Description:" echo "restart ${gamename} while already stopped." @@ -396,4 +417,68 @@ fn_details echo "" echo "Test complete!" sleep 1 -echo "" \ No newline at end of file +echo "" + +echo "=================================" +echo "Generic Server Tests - Complete!" +echo "Using: ${gamename}" +echo "=================================" +echo "" +sleep 1 +fn_printinfo "Tidying up directories." +sleep 1 +rm -rfv ${rootdir} +echo "END" + +#!/bin/bash +# Teamspeak 3 +# Server Management Script +# Author: Daniel Gibbs +# Website: http://gameservermanagers.com +version="040715" + +#### Variables #### + +# Notification Email +# (on|off) +emailnotification="on" +email="me@Danielgibbs.co.uk" + +# Start Variables +updateonstart="off" + +# Server Details +gamename="Teamspeak 3" +servername="Teamspeak 3 Server" +servicename="ts3-server" + +# Directories +rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/ts3server" +selfname="$(basename $0)" +lockselfname=".${servicename}.lock" +filesdir="${rootdir}/serverfiles" +systemdir="${filesdir}" +executabledir="${filesdir}" +executable="./ts3server_startscript.sh" +servercfg="${servicename}.ini" +servercfgdir="${filesdir}" +servercfgfullpath="${servercfgdir}/${servercfg}" +backupdir="${rootdir}/backups" + +# Logging +logdays="7" +gamelogdir="${filesdir}/logs" +scriptlogdir="${rootdir}/log/script" + +scriptlog="${scriptlogdir}/${servicename}-script.log" +emaillog="${scriptlogdir}/${servicename}-email.log" + +scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log" + + +echo "=================================" +echo "Generic Server Tests" +echo "Using: ${gamename}" +echo "=================================" +echo "" +sleep 1 \ No newline at end of file From 4fbbf95246dc6601dcbab31c79ac1952d648e4ba Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 18:40:43 +0000 Subject: [PATCH 09/13] removed unrequired exit was returning a wrong exit code --- functions/fn_getopt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/functions/fn_getopt b/functions/fn_getopt index 1b9b281d4..e495fc566 100644 --- a/functions/fn_getopt +++ b/functions/fn_getopt @@ -2,7 +2,7 @@ # LGSM fn_getopt function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 200615 +# Version: 311015 # Description: getopt arguments. @@ -46,7 +46,6 @@ case "$getopt" in fn_deps_detect;; *) echo "Usage: $0 {start|stop|restart|update|force-update|update-functions|validate|monitor|email-test|details|backup|console|debug|install|auto-install}" - exit 1;; esac exit } @@ -79,7 +78,6 @@ case "$getopt" in fn_deps_detect;; *) echo "Usage: $0 {start|stop|restart|update|update-functions|monitor|email-test|details|backup|install|auto-install}" - exit 1;; esac exit } @@ -108,7 +106,6 @@ case "$getopt" in fn_deps_detect;; *) echo "Usage: $0 {start|stop|restart|update-functions|monitor|email-test|backup|console|debug}" - exit 1;; esac exit } @@ -143,7 +140,6 @@ case "$getopt" in fn_deps_detect;; *) echo "Usage: $0 {start|stop|restart|update-functions|monitor|email-test|details|backup|console|debug|install|map-compressor}" - exit 1;; esac exit } @@ -191,7 +187,6 @@ case "$getopt" in fn_deps_detect;; *) echo "Usage: $0 {start|stop|restart|update|update-functions|validate|monitor|email-test|details|backup|console|debug|install|auto-install|map-compressor}" - exit 1;; esac exit } @@ -227,7 +222,6 @@ case "$getopt" in fn_deps_detect;; *) echo "Usage: $0 {start|stop|restart|update-functions|monitor|email-test|details|backup|console|debug|install|map-compressor}" - exit 1;; esac exit } From 4a66d6de7f4b723177c5ee4fd3f44dd95a5b2474 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 18:53:19 +0000 Subject: [PATCH 10/13] Added exit codes where needed --- functions/fn_backup | 4 ++-- functions/fn_check_ip | 4 ++-- functions/fn_check_root | 4 ++-- functions/fn_check_systemdir | 4 ++-- functions/fn_check_tmux | 4 ++-- functions/fn_compress_unreal2maps | 4 ++-- functions/fn_compress_ut99maps | 4 ++-- functions/fn_console | 4 ++-- functions/fn_debug | 4 ++-- functions/fn_install_ts3 | 10 +++++----- functions/fn_monitor | 8 ++++---- functions/fn_monitor_query | 8 ++++---- functions/fn_update_check | 12 ++++++------ functions/fn_update_dl | 6 +++--- 14 files changed, 40 insertions(+), 40 deletions(-) diff --git a/functions/fn_backup b/functions/fn_backup index c1365d321..3d3f5a7a9 100644 --- a/functions/fn_backup +++ b/functions/fn_backup @@ -2,7 +2,7 @@ # LGSM fn_backup function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 210115 +# Version: 311015 # Description: Creates a .tar.gz file in the backup directory. @@ -22,7 +22,7 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1;; + [Nn]* ) echo Exiting; return;; * ) echo "Please answer yes or no.";; esac done diff --git a/functions/fn_check_ip b/functions/fn_check_ip index 81f6ab6c0..06ce0adc1 100644 --- a/functions/fn_check_ip +++ b/functions/fn_check_ip @@ -2,7 +2,7 @@ # LGSM fn_check_ip function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 120715 +# Version: 311015 # Description: Automatically identifies the server interface IP. # If multiple interfaces are detected the user will need to manualy set using ip="0.0.0.0". @@ -24,7 +24,7 @@ if [ "${ip}" == "0.0.0.0" ]||[ "${ip}" == "" ]; then echo -en "" echo -en "http://gameservermanagers.com/network-interfaces" echo -en "" - exit + exit 1 else ip=${getip} fi diff --git a/functions/fn_check_root b/functions/fn_check_root index b91536803..64ee2cca2 100644 --- a/functions/fn_check_root +++ b/functions/fn_check_root @@ -2,9 +2,9 @@ # LGSM fn_check_root function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 210115 +# Version: 311015 if [ $(whoami) = "root" ]; then fn_printfailnl "Do NOT run this script as root!" - exit + exit 1 fi \ No newline at end of file diff --git a/functions/fn_check_systemdir b/functions/fn_check_systemdir index ae4a85e88..47a3f4860 100644 --- a/functions/fn_check_systemdir +++ b/functions/fn_check_systemdir @@ -2,9 +2,9 @@ # LGSM fn_check_systemdir function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 210115 +# Version: 311015 if [ ! -e "${systemdir}" ]; then fn_printfailnl "Cannot access ${systemdir}: No such directory" - exit + exit 1 fi \ No newline at end of file diff --git a/functions/fn_check_tmux b/functions/fn_check_tmux index 387617be8..49ab4f18d 100644 --- a/functions/fn_check_tmux +++ b/functions/fn_check_tmux @@ -2,7 +2,7 @@ # LGSM fn_check_tmux function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 291015 +# Version: 311015 # Checks if tmux is installed as too many users do not RTFM or know how to use Google. @@ -16,5 +16,5 @@ else # Suitable passive agressive message echo " * Please see the the following link." echo " * http://gameservermanagers.com/tmux-not-found" - exit + exit 127 fi \ No newline at end of file diff --git a/functions/fn_compress_unreal2maps b/functions/fn_compress_unreal2maps index 0b859f3d6..00b35ae09 100644 --- a/functions/fn_compress_unreal2maps +++ b/functions/fn_compress_unreal2maps @@ -2,7 +2,7 @@ # LGSM fn_compress_unreal2maps function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 210115 +# Version: 311015 fn_check_root clear @@ -20,7 +20,7 @@ while true; do read -p "Start compression [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1;; + [Nn]* ) echo Exiting; return;; * ) echo "Please answer yes or no.";; esac done diff --git a/functions/fn_compress_ut99maps b/functions/fn_compress_ut99maps index ed098217a..2f608c0a3 100644 --- a/functions/fn_compress_ut99maps +++ b/functions/fn_compress_ut99maps @@ -2,7 +2,7 @@ # LGSM fn_compress_ut99maps function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 210115 +# Version: 311015 fn_check_root clear @@ -20,7 +20,7 @@ while true; do read -p "Start compression [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1;; + [Nn]* ) echo Exiting; return;; * ) echo "Please answer yes or no.";; esac done diff --git a/functions/fn_console b/functions/fn_console index cec27686d..38e055f3f 100644 --- a/functions/fn_console +++ b/functions/fn_console @@ -2,7 +2,7 @@ # LGSM fn_console function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 260515 +# Version: 311015 # Description: Gives access to the server tmux console. @@ -20,7 +20,7 @@ while true; do read -e -i "y" -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1;; + [Nn]* ) echo Exiting; return;; * ) echo "Please answer yes or no.";; esac done diff --git a/functions/fn_debug b/functions/fn_debug index 93fb240aa..d303e6498 100644 --- a/functions/fn_debug +++ b/functions/fn_debug @@ -2,7 +2,7 @@ # LGSM fn_debug function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 160415 +# Version: 311015 # Description: Runs the server without tmux. Runs direct from the terminal. @@ -37,7 +37,7 @@ while true; do read -p "Continue? [y/N]" yn case $yn in [Yy]* ) break;; - [Nn]* ) echo Exiting; return 1;; + [Nn]* ) echo Exiting; return;; * ) echo "Please answer yes or no.";; esac done diff --git a/functions/fn_install_ts3 b/functions/fn_install_ts3 index 78246c0cf..bde40acfe 100644 --- a/functions/fn_install_ts3 +++ b/functions/fn_install_ts3 @@ -2,7 +2,7 @@ # LGSM fn_install_ts3 function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 301015 +# Version: 311015 fn_details_distro # Gets the teamspeak server architecture @@ -12,7 +12,7 @@ elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then ts3arch="x86" else fn_printfailure "${arch} is an unsupported architecture" - exit + exit 1 fi # Grabs all version numbers not in correct order @@ -45,7 +45,7 @@ if [ -z "${availablebuild}" ]; then sleep 1 fn_printfail "Checking for update: teamspeak.com: Not returning version info" sleep 2 - exit + exit 1 fi cd "${rootdir}" @@ -63,7 +63,7 @@ else sleep 1 cat ".${servicename}-tar-error.tmp" rm ".${servicename}-tar-error.tmp" - exit + exit $? fi echo -e "copying to ${filesdir}...\c" cp -R "${rootdir}/teamspeak3-server_linux-${ts3arch}/"* "${filesdir}" 2> ".${servicename}-cp-error.tmp" @@ -75,7 +75,7 @@ else sleep 1 cat ".${servicename}-cp-error.tmp" rm ".${servicename}-cp-error.tmp" - exit + exit $? fi rm -f teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz rm -rf "${rootdir}/teamspeak3-server_linux-${ts3arch}" diff --git a/functions/fn_monitor b/functions/fn_monitor index 7f27718e7..3978aa43d 100644 --- a/functions/fn_monitor +++ b/functions/fn_monitor @@ -2,7 +2,7 @@ # LGSM fn_monitor function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 150815 +# Version: 311015 # Description: Monitors server by checking for running proccesses # then passes to fn_monitor_query. @@ -22,7 +22,7 @@ if [ ! -f "${rootdir}/${lockselfname}" ]; then sleep 1 echo -en "\n" echo "To enable monitor run ./${selfname} start" - exit + exit 1 fi fn_printdots "Checking session: CHECKING" fn_scriptlog "Checking session: CHECKING" @@ -67,7 +67,7 @@ if [ ! -f "${rootdir}/${lockselfname}" ]; then sleep 1 echo -en "\n" echo "To enable monitor run ./${selfname} start" - exit + exit 1 fi updatecheck=$(ps -ef|grep "${selfname} update"|grep -v grep|wc -l) @@ -85,7 +85,7 @@ if [ "${updatecheck}" = "0" ]||[ "${gamename}" == "Unreal Tournament 99" ]||[ "$ if [ "${engine}" == "avalanche" ]||[ "${engine}" == "goldsource" ]||[ "${engine}" == "realvirtuality" ]||[ "${engine}" == "source" ]||[ "${engine}" == "spark" ]||[ "${engine}" == "unity3d" ]||[ "${engine}" == "unreal" ]||[ "${engine}" == "unreal2" ]; then fn_monitor_query fi - exit + exit $? else fn_printfail "Checking session: FAIL" fn_scriptlog "Checking session: FAIL" diff --git a/functions/fn_monitor_query b/functions/fn_monitor_query index 0b575bb42..f56b6cf23 100644 --- a/functions/fn_monitor_query +++ b/functions/fn_monitor_query @@ -2,7 +2,7 @@ # LGSM fn_monitor_query function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 301015 +# Version: 311015 # Description: uses gsquery.py to directly query the server. # Detects if the server has frozen. @@ -56,7 +56,7 @@ if [ -f "${rootdir}/gsquery.py" ]; then fn_email fi fn_restart - exit + exit 1 elif [ "${exitcode}" == "0" ]; then fn_printok "Querying port: ${ip}:${port} : OK" fn_scriptlog "Querying port: ${ip}:${port} : OK" @@ -79,7 +79,7 @@ if [ -f "${rootdir}/gsquery.py" ]; then echo "As user ${owner} or root run the following command." whoami=$(whoami) echo -en "\nchown ${whoami}:${whoami} ${rootdir}/gsquery.py\n\n" - exit + exit 1 fi else fn_printfail "Querying port: ${ip}:${port} : UNKNOWN ERROR" @@ -87,7 +87,7 @@ if [ -f "${rootdir}/gsquery.py" ]; then sleep 1 echo -en "\n" ${rootdir}/gsquery.py -a ${ip} -p ${port} -e ${engine} - exit + exit 1 fi else fn_printfailnl "Could not find ${rootdir}/gsquery.py" diff --git a/functions/fn_update_check b/functions/fn_update_check index f41203b50..443a88f1c 100644 --- a/functions/fn_update_check +++ b/functions/fn_update_check @@ -2,7 +2,7 @@ # LGSM fn_update_check function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 301015 +# Version: 311015 # Description: Checks if a server update is available. @@ -40,7 +40,7 @@ if [ "${appmanifestfilewc}" -ge "2" ]; then for appfile in ${appmanifestfile}; do echo " ${appfile}" done - exit + exit 1 else sleep 1 fn_printok "Removed x${appmanifestfilewc1} appmanifest_${appid}.acf files" @@ -56,7 +56,7 @@ elif [ "${appmanifestfilewc}" -eq "0" ]; then if [ "${forceupdate}" -eq "1" ]; then fn_printfail "Still no appmanifest_${appid}.acf found: Unable to update" fn_scriptlog "Warning! Still no appmanifest_${appid}.acf found: Unable to update" - exit + exit 1 fi forceupdate=1 fn_printwarn "No appmanifest_${appid}.acf found" @@ -128,7 +128,7 @@ if [ -z "${availablebuild}" ]; then sleep 1 fn_printfailnl "Checking for update: SteamCMD: Not returning version info" fn_scriptlog "Failure! Checking for update: SteamCMD: Not returning version info" - exit + exit 1 else fn_printok "Checking for update: SteamCMD" fn_scriptlog "Success! Checking for update: SteamCMD" @@ -205,7 +205,7 @@ if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then fn_printfailnl "Checking for update: teamspeak.com: Still No logs with server version found" fn_scriptlog "Failure! Checking for update: teamspeak.com: Still No logs with server version found" - exit + exit 1 fi fi currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}') @@ -245,7 +245,7 @@ if [ -z "${availablebuild}" ]; then fn_printfail "Checking for update: teamspeak.com: Not returning version info" fn_scriptlog "Failure! Checking for update: teamspeak.com: Not returning version info" sleep 2 - exit + exit 1 else fn_printok "Checking for update: teamspeak.com" fn_scriptlog "Success! Checking for update: teamspeak.com" diff --git a/functions/fn_update_dl b/functions/fn_update_dl index c4500c331..b22bc7d95 100644 --- a/functions/fn_update_dl +++ b/functions/fn_update_dl @@ -2,7 +2,7 @@ # LGSM fn_update_dl function # Author: Daniel Gibbs # Website: http://gameservermanagers.com -# Version: 040715 +# Version: 311015 # Description: Runs a server update. @@ -66,7 +66,7 @@ else cat "${scriptlogdir}/.${servicename}-tar-error.tmp" >> "${scriptlog}" rm "${scriptlogdir}/.${servicename}-tar-error.tmp" fn_scriptlog "Failure! Unable to update" - exit + exit ${status} fi echo -e "copying to ${filesdir}...\c" fn_scriptlog "Copying to ${filesdir}" @@ -82,7 +82,7 @@ else cat "${scriptlogdir}/.${servicename}-cp-error.tmp" >> "${scriptlog}" rm "${scriptlogdir}/.${servicename}-cp-error.tmp" fn_scriptlog "Failure! Unable to update" - exit + exit ${status} fi rm -f teamspeak3-server_linux-${ts3arch}-${availablebuild}.tar.gz rm -rf "${rootdir}/teamspeak3-server_linux-${ts3arch}" From 79c511d8e6841d9d7112c8489232bb04d3caaee7 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 19:32:39 +0000 Subject: [PATCH 11/13] Updated tests --- tests/test.sh | 432 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 432 insertions(+) create mode 100644 tests/test.sh diff --git a/tests/test.sh b/tests/test.sh new file mode 100644 index 000000000..edddbd25b --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,432 @@ +#!/bin/bash +# Just Cause 2 +# Server Management Script +# Author: Daniel Gibbs +# Website: http://gameservermanagers.com +version="150715" + +#### Variables #### + +# Notification Email +# (on|off) +emailnotification="on" +email="me@danielgibbs.co.uk" + +# 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)/jc2server" +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 + +getopt=$1 + +fn_currentstatus(){ +pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:") +if [ "${pid}" == "0" ]; then + currentstatus="OFFLINE" +else + currentstatus="ONLINE" +fi +} + +fn_setstatus(){ + fn_currentstatus + + echo"" + echo "Required status: ${requiredstatus}" + counter=0 + while [ "${requiredstatus}" != "${currentstatus}" ]; do + counter=$((counter+1)) + fn_currentstatus + + echo -ne "Current 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 + fi + done + echo -ne "Current status: ${currentstatus}\\r" + echo -e "\n" + echo "Test starting:" + echo "" + sleep 0.5 +} + +echo "=================================" +echo "TravisCI Tests" +echo "Linux Game Server Manager" +echo "by Daniel Gibbs" +echo "http://gameservermanagers.com" +echo "=================================" +echo "" +sleep 1 +echo "=================================" +echo "Generic Server Tests" +echo "Using: ${gamename}" +echo "=================================" +echo "" +sleep 1 +mkdir ${rootfdir} + + +echo "1.0 - start - no files" +echo "=================================" +echo "Description:" +echo "Test script reaction to missing server files." +requiredstatus="OFFLINE" +fn_setstatus +(fn_start) +echo "" +echo "Test complete!" +sleep 1 +echo "" + + + +echo "2.0 - install" +echo "=================================" +echo "Description:" +echo "install ${gamename} server." +requiredstatus="OFFLINE" +fn_setstatus +fn_autoinstall +echo "" +echo "Test complete!" +sleep 1 +echo "" + + + +echo "3.1 - start" +echo "=================================" +echo "Description:" +echo "start ${gamename} server." +requiredstatus="OFFLINE" +fn_setstatus +fn_start +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.2 - start - online" +echo "=================================" +echo "Description:" +echo "start ${gamename} server while already running." +requiredstatus="ONLINE" +fn_setstatus +(fn_start) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.3 - start - updateonstart" +echo "=================================" +echo "Description:" +echo "will update server on start." +requiredstatus="ONLINE" +fn_setstatus +( + updateonstart="on" + fn_start +) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.4 - stop" +echo "=================================" +echo "Description:" +echo "stop ${gamename} server." +requiredstatus="ONLINE" +fn_setstatus +fn_stop +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.5 - stop - offline" +echo "=================================" +echo "Description:" +echo "stop ${gamename} server while already stopped." +requiredstatus="OFFLINE" +fn_setstatus +(fn_stop) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.6 - restart" +echo "=================================" +echo "Description:" +echo "restart ${gamename}." +requiredstatus="ONLINE" +fn_setstatus +fn_restart +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "3.7 - restart - offline" +echo "=================================" +echo "Description:" +echo "restart ${gamename} while already stopped." +requiredstatus="OFFLINE" +fn_setstatus +fn_restart +echo "" +echo "Test complete!" +sleep 1 +echo "" + + + +echo "4.1 - update" +echo "=================================" +echo "Description:" +echo "check for updates." +requiredstatus="OFFLINE" +fn_setstatus +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.2 - update - change buildid" +echo "=================================" +echo "Description:" +echo "change the buildid tricking SteamCMD to update." +requiredstatus="OFFLINE" +fn_setstatus +fn_printinfonl "changed buildid to 0." +sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.3 - update - change buildid - online" +echo "=================================" +echo "Description:" +echo "change the buildid tricking SteamCMD to update server while already running." +requiredstatus="ONLINE" +fn_setstatus +fn_printinfonl "changed buildid to 0." +sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.4 - update - remove appmanifest file" +echo "=================================" +echo "Description:" +echo "removing appmanifest file will cause script to repair." +requiredstatus="OFFLINE" +fn_setstatus +fn_printinfonl "removed appmanifest_${appid}.acf." +rm --verbose "${filesdir}/steamapps/appmanifest_${appid}.acf" +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.5 - force-update" +echo "=================================" +echo "Description:" +echo "force-update bypassing update check." +requiredstatus="OFFLINE" +fn_setstatus +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.6 - force-update - online" +echo "=================================" +echo "Description:" +echo "force-update bypassing update check server while already running." +requiredstatus="ONLINE" +fn_setstatus +fn_update_check +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.7 - validate" +echo "=================================" +echo "Description:" +echo "validate server files." +requiredstatus="OFFLINE" +fn_setstatus +fn_validate +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "4.8 - validate - online" +echo "=================================" +echo "Description:" +echo "validate server files while server while already running." +requiredstatus="ONLINE" +fn_setstatus +fn_validate +echo "" +echo "Test complete!" +sleep 1 +echo "" + + + +echo "5.1 - monitor - online" +echo "=================================" +echo "Description:" +echo "run monitor server while already running." +requiredstatus="ONLINE" +fn_setstatus +(fn_monitor) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.2 - monitor - offline - no lockfile" +echo "=================================" +echo "Description:" +echo "run monitor while server is offline with no lockfile." +requiredstatus="OFFLINE" +fn_setstatus +(fn_monitor) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.3 - monitor - offline - with lockfile" +echo "=================================" +echo "Description:" +echo "run monitor while server is offline with no lockfile." +requiredstatus="OFFLINE" +fn_setstatus +fn_printinfonl "creating lockfile." +date > "${rootdir}/${lockselfname}" +(fn_monitor) +echo "" +echo "Test complete!" +sleep 1 +echo "" +echo "5.4 - monitor - gsquery.py failure" +echo "=================================" +echo "Description:" +echo "gsquery.py will fail to query port." +requiredstatus="ONLINE" +fn_setstatus +sed -i 's/[0-9]\+/0/' "${servercfgfullpath}" +fn_monitor +echo "" +fn_printinfonl "Reseting ${servercfg}." +fn_install_config +echo "" +echo "Test complete!" +sleep 1 +echo "" + + + +echo "6.0 - details" +echo "=================================" +echo "Description:" +echo "gsquery.py will fail to query port." +requiredstatus="ONLINE" +fn_setstatus +fn_details +echo "" +echo "Test complete!" +sleep 1 +echo "" + +echo "=================================" +echo "Generic Server Tests - Complete!" +echo "Using: ${gamename}" +echo "=================================" +echo "" +sleep 1 +fn_printinfo "Tidying up directories." +sleep 1 +rm -rfv ${rootdir} +echo "END" + From 10e0ad8916479eff84efe35b0c7f799725bd8aed Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 19:38:59 +0000 Subject: [PATCH 12/13] added new set of tests for travisci --- .travis.yml | 2 +- tests/test.sh | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 85148ae4e..4e39e2473 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,4 +22,4 @@ addons: script: - - bash test.sh \ No newline at end of file + - bash tests/test.sh \ No newline at end of file diff --git a/tests/test.sh b/tests/test.sh index edddbd25b..839b7538c 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -430,3 +430,55 @@ sleep 1 rm -rfv ${rootdir} echo "END" +#!/bin/bash +# Teamspeak 3 +# Server Management Script +# Author: Daniel Gibbs +# Website: http://gameservermanagers.com +version="040715" + +#### Variables #### + +# Notification Email +# (on|off) +emailnotification="on" +email="me@Danielgibbs.co.uk" + +# Start Variables +updateonstart="off" + +# Server Details +gamename="Teamspeak 3" +servername="Teamspeak 3 Server" +servicename="ts3-server" + +# Directories +rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/ts3server" +selfname="$(basename $0)" +lockselfname=".${servicename}.lock" +filesdir="${rootdir}/serverfiles" +systemdir="${filesdir}" +executabledir="${filesdir}" +executable="./ts3server_startscript.sh" +servercfg="${servicename}.ini" +servercfgdir="${filesdir}" +servercfgfullpath="${servercfgdir}/${servercfg}" +backupdir="${rootdir}/backups" + +# Logging +logdays="7" +gamelogdir="${filesdir}/logs" +scriptlogdir="${rootdir}/log/script" + +scriptlog="${scriptlogdir}/${servicename}-script.log" +emaillog="${scriptlogdir}/${servicename}-email.log" + +scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log" + + +echo "=================================" +echo "Generic Server Tests" +echo "Using: ${gamename}" +echo "=================================" +echo "" +sleep 1 \ No newline at end of file From 5eb96d39bc2bab10f6e2385186716e9c006df6e7 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sat, 31 Oct 2015 19:43:28 +0000 Subject: [PATCH 13/13] fixed mkdir --- tests/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.sh b/tests/test.sh index 839b7538c..cbe7fdbaf 100644 --- a/tests/test.sh +++ b/tests/test.sh @@ -35,6 +35,7 @@ engine="avalanche" # Directories rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/jc2server" +mkdir "${rootdir}" selfname="$(basename $0)" lockselfname=".${servicename}.lock" filesdir="${rootdir}/serverfiles" @@ -143,7 +144,6 @@ echo "Using: ${gamename}" echo "=================================" echo "" sleep 1 -mkdir ${rootfdir} echo "1.0 - start - no files" @@ -396,7 +396,7 @@ echo "gsquery.py will fail to query port." requiredstatus="ONLINE" fn_setstatus sed -i 's/[0-9]\+/0/' "${servercfgfullpath}" -fn_monitor +(fn_monitor) echo "" fn_printinfonl "Reseting ${servercfg}." fn_install_config