Browse Source

feat(travis-ci): update test script to match linuxgsm.sh

pull/2217/head
Daniel Gibbs 7 years ago
parent
commit
4be065cd56
  1. 162
      tests/tests_fctrserver.sh

162
tests/tests_fctrserver.sh

@ -8,7 +8,7 @@
# Website: https://linuxgsm.com # Website: https://linuxgsm.com
travistest="1" travistest="1"
version="180409" version="190303"
shortname="fctr" shortname="fctr"
gameservername="fctrserver" gameservername="fctrserver"
rootdir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" rootdir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
@ -23,9 +23,13 @@ serverfiles="${rootdir}/serverfiles"
functionsdir="${lgsmdir}/functions" functionsdir="${lgsmdir}/functions"
libdir="${lgsmdir}/lib" libdir="${lgsmdir}/lib"
tmpdir="${lgsmdir}/tmp" tmpdir="${lgsmdir}/tmp"
datadir="${lgsmdir}/data"
serverlist="${datadir}/serverlist.csv"
serverlistmenu="${datadir}/serverlistmenu.csv"
configdir="${lgsmdir}/config-lgsm" configdir="${lgsmdir}/config-lgsm"
configdirserver="${configdir}/${gameservername}" configdirserver="${configdir}/${gameservername}"
configdirdefault="${lgsmdir}/config-default" configdirdefault="${lgsmdir}/config-default"
userinput="${1}"
# Allows for testing not on Travis CI # Allows for testing not on Travis CI
if [ ! -v TRAVIS ]; then if [ ! -v TRAVIS ]; then
@ -40,16 +44,16 @@ githubuser="GameServerManagers"
githubrepo="LinuxGSM" githubrepo="LinuxGSM"
githubbranch="${TRAVIS_BRANCH}" githubbranch="${TRAVIS_BRANCH}"
# Core Function that is required first # Core function that is required first.
core_functions.sh(){ core_functions.sh(){
functionfile="${FUNCNAME}" functionfile="${FUNCNAME}"
fn_bootstrap_fetch_file_github "lgsm/functions" "core_functions.sh" "${functionsdir}" "chmodx" "run" "noforcedl" "nomd5" fn_bootstrap_fetch_file_github "lgsm/functions" "core_functions.sh" "${functionsdir}" "chmodx" "run" "noforcedl" "nomd5"
} }
# Bootstrap # Bootstrap
# Fetches the core functions required before passed off to core_dl.sh # Fetches the core functions required before passed off to core_dl.sh.
# Fetches core functions # Fetches core functions.
fn_bootstrap_fetch_file(){ fn_bootstrap_fetch_file(){
remote_fileurl="${1}" remote_fileurl="${1}"
local_filedir="${2}" local_filedir="${2}"
@ -58,42 +62,42 @@ fn_bootstrap_fetch_file(){
run="${5:-0}" run="${5:-0}"
forcedl="${6:-0}" forcedl="${6:-0}"
md5="${7:-0}" md5="${7:-0}"
# download file if missing or download forced # Download file if missing or download forced.
if [ ! -f "${local_filedir}/${local_filename}" ]||[ "${forcedl}" == "forcedl" ]; then if [ ! -f "${local_filedir}/${local_filename}" ]||[ "${forcedl}" == "forcedl" ]; then
if [ ! -d "${local_filedir}" ]; then if [ ! -d "${local_filedir}" ]; then
mkdir -p "${local_filedir}" mkdir -p "${local_filedir}"
fi fi
# Defines curl path # Defines curl path.
curlpath=$(command -v curl 2>/dev/null) curlpath=$(command -v curl 2>/dev/null)
# If curl exists download file # If curl exists download file.
if [ "$(basename "${curlpath}")" == "curl" ]; then if [ "$(basename "${curlpath}")" == "curl" ]; then
# trap to remove part downloaded files # Trap to remove part downloaded files.
echo -en " fetching ${local_filename}...\c" echo -en " fetching ${local_filename}...\c"
curlcmd=$(${curlpath} -s --fail -L -o "${local_filedir}/${local_filename}" "${remote_fileurl}" 2>&1) curlcmd=$(${curlpath} -s --fail -L -o "${local_filedir}/${local_filename}" "${remote_fileurl}" 2>&1)
local exitcode=$? local exitcode=$?
if [ ${exitcode} -ne 0 ]; then if [ ${exitcode} -ne 0 ]; then
echo -e "\e[0;31mFAIL\e[0m\n" echo -e "FAIL"
if [ -f "${lgsmlog}" ]; then if [ -f "${lgsmlog}" ]; then
echo -e "${remote_fileurl}" | tee -a "${lgsmlog}" echo -e "${remote_fileurl}" | tee -a "${lgsmlog}"
echo "${curlcmd}" | tee -a "${lgsmlog}" echo "${curlcmd}" | tee -a "${lgsmlog}"
fi fi
exit 1 exit 1
else else
echo -e "\e[0;32mOK\e[0m" echo -e "OK"
fi fi
else else
echo "[ FAIL ] Curl is not installed" echo "[ FAIL ] Curl is not installed"
exit 1 exit 1
fi fi
# make file chmodx if chmodx is set # Make file chmodx if chmodx is set.
if [ "${chmodx}" == "chmodx" ]; then if [ "${chmodx}" == "chmodx" ]; then
chmod +x "${local_filedir}/${local_filename}" chmod +x "${local_filedir}/${local_filename}"
fi fi
fi fi
if [ -f "${local_filedir}/${local_filename}" ]; then if [ -f "${local_filedir}/${local_filename}" ]; then
# run file if run is set # Run file if run is set.
if [ "${run}" == "run" ]; then if [ "${run}" == "run" ]; then
source "${local_filedir}/${local_filename}" source "${local_filedir}/${local_filename}"
fi fi
@ -112,11 +116,11 @@ fn_bootstrap_fetch_file_github(){
run="${5:-0}" run="${5:-0}"
forcedl="${6:-0}" forcedl="${6:-0}"
md5="${7:-0}" md5="${7:-0}"
# Passes vars to the file download function # Passes vars to the file download function.
fn_bootstrap_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}" fn_bootstrap_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
} }
# Installer menu # Installer menu.
fn_print_center() { fn_print_center() {
columns="$(tput cols)" columns="$(tput cols)"
@ -129,7 +133,7 @@ fn_print_horizontal(){
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "${char}" printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "${char}"
} }
# Bash Menu # Bash menu.
fn_install_menu_bash() { fn_install_menu_bash() {
local resultvar=$1 local resultvar=$1
title=$2 title=$2
@ -153,7 +157,7 @@ fn_install_menu_bash() {
done done
} }
# Whiptail/Dialog Menu # Whiptail/Dialog menu.
fn_install_menu_whiptail() { fn_install_menu_whiptail() {
local menucmd=$1 local menucmd=$1
local resultvar=$2 local resultvar=$2
@ -178,14 +182,14 @@ fn_install_menu_whiptail() {
fi fi
} }
# Menu selector # Menu selector.
fn_install_menu() { fn_install_menu() {
local resultvar=$1 local resultvar=$1
local selection="" local selection=""
title=$2 title=$2
caption=$3 caption=$3
options=$4 options=$4
# Get menu command # Get menu command.
for menucmd in whiptail dialog bash; do for menucmd in whiptail dialog bash; do
if [ -x "$(command -v "${menucmd}")" ]; then if [ -x "$(command -v "${menucmd}")" ]; then
menucmd=$(command -v "${menucmd}") menucmd=$(command -v "${menucmd}")
@ -201,7 +205,7 @@ fn_install_menu() {
eval "$resultvar=\"${selection}\"" eval "$resultvar=\"${selection}\""
} }
# Gets server info from serverlist.csv and puts in to array # Gets server info from serverlist.csv and puts in to array.
fn_server_info(){ fn_server_info(){
IFS="," IFS=","
server_info_array=($(grep -aw "${userinput}" "${serverlist}")) server_info_array=($(grep -aw "${userinput}" "${serverlist}"))
@ -219,7 +223,7 @@ fn_install_getopt(){
echo -e "" echo -e ""
echo -e "Commands" echo -e "Commands"
echo -e "install\t\t| Select server to install." echo -e "install\t\t| Select server to install."
echo -e "servername\t| e.g $0 csgoserver. Enter name of server/game to install." echo -e "servername\t| Enter name of game server to install. e.g $0 csgoserver."
echo -e "list\t\t| List all servers available for install." echo -e "list\t\t| List all servers available for install."
exit exit
} }
@ -248,9 +252,14 @@ fn_install_file(){
exit exit
} }
# Prevent from running this script as root. # Prevent LinuxGSM from running as root. Except if doing a dependency install.
if [ "$(whoami)" == "root" ]; then if [ "$(whoami)" == "root" ]; then
if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]; then if [ "${userinput}" == "install" ]||[ "${userinput}" == "auto-install" ]||[ "${userinput}" == "i" ]||[ "${userinput}" == "ai" ]; then
if [ "${shortname}" == "core" ]; then
echo "[ FAIL ] Do NOT run this script as root!"
exit 1
fi
elif [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]; then
echo "[ FAIL ] Do NOT run this script as root!" echo "[ FAIL ] Do NOT run this script as root!"
exit 1 exit 1
else else
@ -259,12 +268,8 @@ if [ "$(whoami)" == "root" ]; then
fi fi
fi fi
# LinuxGSM installer mode # LinuxGSM installer mode.
if [ "${shortname}" == "core" ]; then if [ "${shortname}" == "core" ]; then
userinput=$1
datadir="${tmpdir}/data"
serverlist="${datadir}/serverlist.csv"
# Download the latest serverlist. This is the complete list of all supported servers. # Download the latest serverlist. This is the complete list of all supported servers.
fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5" fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
if [ ! -f "${serverlist}" ]; then if [ ! -f "${serverlist}" ]; then
@ -272,13 +277,14 @@ if [ "${shortname}" == "core" ]; then
exit 1 exit 1
fi fi
if [ "${userinput}" == "list" ]; then if [ "${userinput}" == "list" ]||[ "${userinput}" == "l" ]; then
{ {
awk -F "," '{print $2 "\t" $3}' "${serverlist}" tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
} | column -s $'\t' -t | more } | column -s $'\t' -t | more
exit exit
elif [ "${userinput}" == "install" ]||[ "${userinput}" == "i" ]; then elif [ "${userinput}" == "install" ]||[ "${userinput}" == "i" ]; then
fn_install_menu result "LinuxGSM" "Select game to install" "${serverlist}" tail -n +2 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' > "${serverlistmenu}"
fn_install_menu result "LinuxGSM" "Select game server to install." "${serverlistmenu}"
userinput="${result}" userinput="${result}"
fn_server_info fn_server_info
if [ "${result}" == "${gameservername}" ]; then if [ "${result}" == "${gameservername}" ]; then
@ -301,65 +307,67 @@ if [ "${shortname}" == "core" ]; then
fn_install_getopt fn_install_getopt
fi fi
# LinuxGSM Server Mode # LinuxGSM server mode.
else else
core_functions.sh core_functions.sh
if [ "${shortname}" != "core-dep" ]; then
# Load LinuxGSM configs # Load LinuxGSM configs.
# These are required to get all the default variables for the specific server. # These are required to get all the default variables for the specific server.
# Load the default config. If missing download it. If changed reload it. # Load the default config. If missing download it. If changed reload it.
if [ ! -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" ]; then if [ ! -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" ]; then
mkdir -p "${configdirdefault}/config-lgsm/${gameservername}" mkdir -p "${configdirdefault}/config-lgsm/${gameservername}"
fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforcedl" "nomd5" fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
fi
if [ ! -f "${configdirserver}/_default.cfg" ]; then
mkdir -p "${configdirserver}"
echo -en " copying _default.cfg...\c"
cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
exitcode=$?
if [ ${exitcode} -ne 0 ]; then
echo -e "\e[0;31mFAIL\e[0m\n"
exit 1
else
echo -e "\e[0;32mOK\e[0m"
fi fi
else if [ ! -f "${configdirserver}/_default.cfg" ]; then
function_file_diff=$(diff -q "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg") mkdir -p "${configdirserver}"
if [ "${function_file_diff}" != "" ]; then
fn_print_warn_nl "_default.cfg has been altered. reloading config."
echo -en " copying _default.cfg...\c" echo -en " copying _default.cfg...\c"
cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg" cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
exitcode=$? exitcode=$?
if [ ${exitcode} -ne 0 ]; then if [ ${exitcode} -ne 0 ]; then
echo -e "\e[0;31mFAIL\e[0m\n" echo -e "FAIL"
exit 1 exit 1
else else
echo -e "\e[0;32mOK\e[0m" echo -e "OK"
fi
else
function_file_diff=$(diff -q "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg")
if [ "${function_file_diff}" != "" ]; then
fn_print_warn_nl "_default.cfg has been altered. reloading config."
echo -en " copying _default.cfg...\c"
cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
exitcode=$?
if [ ${exitcode} -ne 0 ]; then
echo -e "FAIL"
exit 1
else
echo -e "OK"
fi
fi fi
fi fi
source "${configdirserver}/_default.cfg"
# Load the common.cfg config. If missing download it.
if [ ! -f "${configdirserver}/common.cfg" ]; then
fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
source "${configdirserver}/common.cfg"
else
source "${configdirserver}/common.cfg"
fi
# Load the instance.cfg config. If missing download it.
if [ ! -f "${configdirserver}/${servicename}.cfg" ]; then
fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${servicename}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
source "${configdirserver}/${servicename}.cfg"
else
source "${configdirserver}/${servicename}.cfg"
fi
# Load the linuxgsm.sh in to tmpdir. If missing download it.
if [ ! -f "${tmpdir}/linuxgsm.sh" ]; then
fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "chmodx" "norun" "noforcedl" "nomd5"
fi
fi fi
source "${configdirserver}/_default.cfg" # Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
# Load the common.cfg config. If missing download it fn_ansi_loader
if [ ! -f "${configdirserver}/common.cfg" ]; then # Prevents running of core_exit.sh for Travis-CI.
fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5" if [ "${travistest}" != "1" ]; then
source "${configdirserver}/common.cfg"
else
source "${configdirserver}/common.cfg"
fi
# Load the instance.cfg config. If missing download it
if [ ! -f "${configdirserver}/${servicename}.cfg" ]; then
fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${servicename}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
source "${configdirserver}/${servicename}.cfg"
else
source "${configdirserver}/${servicename}.cfg"
fi
# Load the linuxgsm.sh in to tmpdir. If missing download it
if [ ! -f "${tmpdir}/linuxgsm.sh" ]; then
fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "chmodx" "norun" "noforcedl" "nomd5"
fi
# Prevents running of core_exit.sh for Travis.
if [ -z "${travistest}" ]; then
getopt=$1 getopt=$1
core_getopt.sh core_getopt.sh
fi fi

Loading…
Cancel
Save