| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- #!/bin/bash
- # TravisCI Tests
- # Server Management Script
- # Author: Daniel Gibbs
- # Website: https://gameservermanagers.com
- version="071115"
- #### Variables ####
- # Alert Email
- # (on|off)
- emailalert="off"
- email=""
- # Start Variables
- updateonstart="off"
- # Server Details
- gamename="Teamspeak 3"
- servername="Teamspeak 3 Server"
- servicename="ts3-server"
- # Directories
- rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
- selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
- lockselfname=".${servicename}.lock"
- filesdir="${rootdir}/serverfiles"
- systemdir="${filesdir}"
- executabledir="${filesdir}"
- executable="./ts3server_startscript.sh"
- servercfg="${servicename}.ini"
- servercfgdir="${filesdir}"
- servercfgfullpath="${servercfgdir}/${servercfg}"
- servercfgdefault="${servercfgdir}/lgsm-default.ini"
- 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"
- #### Advanced Variables ####
- # Github Branch Select
- # Allows for the use of different function files
- # from a different repo and/or branch.
- githubuser="dgibbs64"
- githubrepo="linuxgsm"
- githubbranch="$TRAVIS_BRANCH"
- ##### Script #####
- # Do not edit
- fn_getgithubfile(){
- filename=$1
- exec=$2
- fileurl=${3:-$filename}
- filepath="${rootdir}/${filename}"
- filedir=$(dirname "${filepath}")
- # If the function file is missing, then download
- if [ ! -f "${filepath}" ]; then
- if [ ! -d "${filedir}" ]; then
- mkdir "${filedir}"
- fi
- githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
- echo -e " fetching ${filename}...\c"
- if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then
- :
- else
- echo -e "\e[0;31mFAIL\e[0m\n"
- echo "Curl is not installed!"
- echo -e ""
- exit
- fi
- curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1)
- if [ $? -ne 0 ]; then
- echo -e "\e[0;31mFAIL\e[0m\n"
- echo "${curl}"
- echo -e "${githuburl}\n"
- exit
- else
- echo -e "\e[0;32mOK\e[0m"
- fi
- if [ "${exec}" ]; then
- chmod +x "${filepath}"
- fi
- fi
- if [ "${exec}" ]; then
- source "${filepath}"
- fi
- }
- fn_runfunction(){
- fn_getgithubfile "functions/${functionfile}" 1
- }
- core_functions.sh(){
- # Functions are defined in core_functions.sh.
- functionfile="${FUNCNAME}"
- fn_runfunction
- }
- core_functions.sh
- fn_currentstatus_tmux(){
- check_status.sh
- if [ "${status}" != "0" ]; then
- currentstatus="ONLINE"
- else
- currentstatus="OFFLINE"
- fi
- }
- fn_currentstatus_ts3(){
- check_status.sh
- if [ "${status}" != "0" ]; then
- currentstatus="ONLINE"
- else
- currentstatus="OFFLINE"
- fi
- }
-
- fn_setstatus(){
- fn_currentstatus_ts3
- echo""
- echo "Required status: ${requiredstatus}"
- counter=0
- echo "Current status: ${currentstatus}"
- while [ "${requiredstatus}" != "${currentstatus}" ]; do
- counter=$((counter+1))
- fn_currentstatus_ts3
- echo -ne "New status: ${currentstatus}\\r"
-
- if [ "${requiredstatus}" == "ONLINE" ]; then
- (command_start.sh)
- else
- (command_stop.sh)
- 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 "New 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 "https://gameservermanagers.com"
- echo "================================="
- echo ""
- sleep 1
- echo "================================="
- echo "Server Tests"
- echo "Using: ${gamename}"
- echo "================================="
- echo ""
- sleep 1
- echo "1.0 - start - no files"
- echo "================================="
- echo "Description:"
- echo "test script reaction to missing server files."
- echo ""
- (command_start.sh)
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "1.1 - getopt"
- echo "================================="
- echo "Description:"
- echo "displaying options messages."
- echo ""
- (core_getopt.sh)
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "2.0 - install"
- echo "================================="
- echo "Description:"
- echo "install ${gamename} server."
- fn_autoinstall
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "3.1 - start"
- echo "================================="
- echo "Description:"
- echo "start ${gamename} server."
- requiredstatus="OFFLINE"
- fn_setstatus
- command_start.sh
- 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
- (command_start.sh)
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "3.3 - start - updateonstart"
- echo "================================="
- echo "Description:"
- echo "will update server on start."
- requiredstatus="OFFLINE"
- fn_setstatus
- (
- updateonstart="on"
- command_start.sh
- )
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "3.4 - stop"
- echo "================================="
- echo "Description:"
- echo "stop ${gamename} server."
- requiredstatus="ONLINE"
- fn_setstatus
- command_stop.sh
- 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
- (command_stop.sh)
- 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
- update_check.sh
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "4.1 - update - old version"
- echo "================================="
- echo "Description:"
- echo "change the version number tricking LGSM to update."
- requiredstatus="OFFLINE"
- sed -i 's/[0-9]\+/0/g' ${gamelogdir}/ts3server*_0.log
- fn_setstatus
- update_check.sh
- 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
- (command_monitor.sh)
- 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
- (command_monitor.sh)
- 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_print_info_nl "creating lockfile."
- date > "${rootdir}/${lockselfname}"
- (command_monitor.sh)
- 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}"
- (command_monitor.sh)
- echo ""
- fn_print_info_nl "Reseting ${servercfg}."
- install_config.sh
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "6.0 - details"
- echo "================================="
- echo "Description:"
- echo "display details."
- requiredstatus="ONLINE"
- fn_setstatus
- command_details.sh
- echo ""
- echo "Test complete!"
- sleep 1
- echo ""
- echo "================================="
- echo "Server Tests - Complete!"
- echo "Using: ${gamename}"
- echo "================================="
- echo ""
- requiredstatus="OFFLINE"
- fn_setstatus
- sleep 1
- fn_print_info "Tidying up directories."
- sleep 1
- rm -rfv ${serverfiles}
- echo "END"
|