tests_ts3server.sh 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2020 Daniel Gibbs
  5. # Purpose: Travis CI Tests: Teamspeak 3 | Linux Game Server Management Script
  6. # Contributors: https://linuxgsm.com/contrib
  7. # Documentation: https://docs.linuxgsm.com
  8. # Website: https://linuxgsm.com
  9. # DO NOT EDIT THIS FILE
  10. # LinuxGSM configuration is no longer edited here
  11. # To update your LinuxGSM config go to:
  12. # lgsm/config-lgsm
  13. # https://docs.linuxgsm.com/configuration/linuxgsm-config
  14. # Debugging
  15. if [ -f ".dev-debug" ]; then
  16. exec 5>dev-debug.log
  17. BASH_XTRACEFD="5"
  18. set -x
  19. fi
  20. version="v20.3.1"
  21. shortname="ts3"
  22. gameservername="ts3server"
  23. commandname="CORE"
  24. rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
  25. selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
  26. sessionname=$(echo "${selfname}" | cut -f1 -d".")
  27. lgsmdir="${rootdir}/lgsm"
  28. logdir="${rootdir}/log"
  29. lgsmlogdir="${logdir}/lgsm"
  30. steamcmddir="${HOME}/.steam/steamcmd"
  31. serverfiles="${rootdir}/serverfiles"
  32. functionsdir="${lgsmdir}/functions"
  33. tmpdir="${lgsmdir}/tmp"
  34. datadir="${lgsmdir}/data"
  35. lockdir="${lgsmdir}/lock"
  36. serverlist="${datadir}/serverlist.csv"
  37. serverlistmenu="${datadir}/serverlistmenu.csv"
  38. configdir="${lgsmdir}/config-lgsm"
  39. configdirserver="${configdir}/${gameservername}"
  40. configdirdefault="${lgsmdir}/config-default"
  41. userinput="${1}"
  42. # Allows for testing not on Travis CI.
  43. # if using travis for tests
  44. if [ -z "${TRAVIS}" ]; then
  45. TRAVIS_BRANCH="develop"
  46. TRAVIS_BUILD_DIR="${rootdir}"
  47. fi
  48. travistest="1"
  49. ## GitHub Branch Select
  50. # Allows for the use of different function files
  51. # from a different repo and/or branch.
  52. githubuser="GameServerManagers"
  53. githubrepo="LinuxGSM"
  54. githubbranch="${TRAVIS_BRANCH}"
  55. # Core function that is required first.
  56. core_functions.sh(){
  57. functionfile="${FUNCNAME[0]}"
  58. fn_bootstrap_fetch_file_github "lgsm/functions" "core_functions.sh" "${functionsdir}" "chmodx" "run" "noforcedl" "nomd5"
  59. }
  60. # Bootstrap
  61. # Fetches the core functions required before passed off to core_dl.sh.
  62. fn_bootstrap_fetch_file(){
  63. remote_fileurl="${1}"
  64. remote_fileurl_backup="${2}"
  65. remote_fileurl_name="${3}"
  66. remote_fileurl_backup_name="${4}"
  67. local_filedir="${5}"
  68. local_filename="${6}"
  69. chmodx="${7:-0}"
  70. run="${8:-0}"
  71. forcedl="${9:-0}"
  72. md5="${10:-0}"
  73. # Download file if missing or download forced.
  74. if [ ! -f "${local_filedir}/${local_filename}" ]||[ "${forcedl}" == "forcedl" ]; then
  75. # If backup fileurl exists include it.
  76. if [ -n "${remote_fileurl_backup}" ]; then
  77. # counter set to 0 to allow second try
  78. counter=0
  79. remote_fileurls_array=( remote_fileurl remote_fileurl_backup )
  80. else
  81. # counter set to 1 to not allow second try
  82. counter=1
  83. remote_fileurls_array=( remote_fileurl )
  84. fi
  85. for remote_fileurl_array in "${remote_fileurls_array[@]}"
  86. do
  87. if [ "${remote_fileurl_array}" == "remote_fileurl" ]; then
  88. fileurl="${remote_fileurl}"
  89. fileurl_name="${remote_fileurl_name}"
  90. elif [ "${remote_fileurl_array}" == "remote_fileurl_backup" ]; then
  91. fileurl="${remote_fileurl_backup}"
  92. fileurl_name="${remote_fileurl_backup_name}"
  93. fi
  94. counter=$((counter+1))
  95. if [ ! -d "${local_filedir}" ]; then
  96. mkdir -p "${local_filedir}"
  97. fi
  98. # Trap will remove part downloaded files if canceled.
  99. trap fn_fetch_trap INT
  100. # Larger files show a progress bar.
  101. echo -en "fetching ${fileurl_name} ${local_filename}...\c"
  102. curlcmd=$(curl -s --fail -L -o "${local_filedir}/${local_filename}" "${fileurl}" 2>&1)
  103. local exitcode=$?
  104. # Download will fail if downloads a html file.
  105. if [ -f "${local_filedir}/${local_filename}" ]; then
  106. if [ -n "$(head "${local_filedir}/${local_filename}" | grep "DOCTYPE" )" ]; then
  107. rm "${local_filedir:?}/${local_filename:?}"
  108. local exitcode=2
  109. fi
  110. fi
  111. # On first try will error. On second try will fail.
  112. if [ ${exitcode} -ne 0 ]; then
  113. if [ ${counter} -ge 2 ]; then
  114. echo -e "FAIL"
  115. if [ -f "${lgsmlog}" ]; then
  116. fn_script_log_fatal "Downloading ${local_filename}"
  117. fn_script_log_fatal "${fileurl}"
  118. fi
  119. core_exit.sh
  120. else
  121. echo -e "ERROR"
  122. if [ -f "${lgsmlog}" ]; then
  123. fn_script_log_error "Downloading ${local_filename}"
  124. fn_script_log_error "${fileurl}"
  125. fi
  126. fi
  127. else
  128. echo -en "OK"
  129. sleep 0.3
  130. echo -en "\033[2K\\r"
  131. if [ -f "${lgsmlog}" ]; then
  132. fn_script_log_pass "Downloading ${local_filename}"
  133. fi
  134. # Make file executable if chmodx is set.
  135. if [ "${chmodx}" == "chmodx" ]; then
  136. chmod +x "${local_filedir}/${local_filename}"
  137. fi
  138. # Remove trap.
  139. trap - INT
  140. break
  141. fi
  142. done
  143. fi
  144. if [ -f "${local_filedir}/${local_filename}" ]; then
  145. # Execute file if run is set.
  146. if [ "${run}" == "run" ]; then
  147. # shellcheck source=/dev/null
  148. source "${local_filedir}/${local_filename}"
  149. fi
  150. fi
  151. }
  152. fn_bootstrap_fetch_file_github(){
  153. github_file_url_dir="${1}"
  154. github_file_url_name="${2}"
  155. if [ "${githubbranch}" == "master" ]&&[ "${commandname}" != "UPDATE-LGSM" ]; then
  156. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${version}/${github_file_url_dir}/${github_file_url_name}"
  157. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${version}/${github_file_url_dir}/${github_file_url_name}"
  158. else
  159. remote_fileurl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  160. remote_fileurl_backup="https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  161. fi
  162. remote_fileurl_name="GitHub"
  163. remote_fileurl_backup_name="Bitbucket"
  164. local_filedir="${3}"
  165. local_filename="${github_file_url_name}"
  166. chmodx="${4:-0}"
  167. run="${5:-0}"
  168. forcedl="${6:-0}"
  169. md5="${7:-0}"
  170. # Passes vars to the file download function.
  171. fn_bootstrap_fetch_file "${remote_fileurl}" "${remote_fileurl_backup}" "${remote_fileurl_name}" "${remote_fileurl_backup_name}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  172. }
  173. # Installer menu.
  174. fn_print_center() {
  175. columns=$(tput cols)
  176. line="$*"
  177. printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
  178. }
  179. fn_print_horizontal(){
  180. printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "="
  181. }
  182. # Bash menu.
  183. fn_install_menu_bash() {
  184. local resultvar=$1
  185. title=$2
  186. caption=$3
  187. options=$4
  188. fn_print_horizontal
  189. fn_print_center "${title}"
  190. fn_print_center "${caption}"
  191. fn_print_horizontal
  192. menu_options=()
  193. while read -r line || [[ -n "${line}" ]]; do
  194. var=$(echo -e "${line}" | awk -F "," '{print $2 " - " $3}')
  195. menu_options+=( "${var}" )
  196. done < "${options}"
  197. menu_options+=( "Cancel" )
  198. select option in "${menu_options[@]}"; do
  199. if [ "${option}" ]&&[ "${option}" != "Cancel" ]; then
  200. eval "$resultvar=\"${option/%\ */}\""
  201. fi
  202. break
  203. done
  204. }
  205. # Whiptail/Dialog menu.
  206. fn_install_menu_whiptail() {
  207. local menucmd=$1
  208. local resultvar=$2
  209. title=$3
  210. caption=$4
  211. options=$5
  212. height=${6:-40}
  213. width=${7:-80}
  214. menuheight=${8:-30}
  215. IFS=","
  216. menu_options=()
  217. while read -r line; do
  218. key=$(echo -e "${line}" | awk -F "," '{print $3}')
  219. val=$(echo -e "${line}" | awk -F "," '{print $2}')
  220. menu_options+=( "${val//\"}" "${key//\"}" )
  221. done < "${options}"
  222. OPTION=$(${menucmd} --title "${title}" --menu "${caption}" "${height}" "${width}" "${menuheight}" "${menu_options[@]}" 3>&1 1>&2 2>&3)
  223. if [ $? == 0 ]; then
  224. eval "$resultvar=\"${OPTION}\""
  225. else
  226. eval "$resultvar="
  227. fi
  228. }
  229. # Menu selector.
  230. fn_install_menu() {
  231. local resultvar=$1
  232. local selection=""
  233. title=$2
  234. caption=$3
  235. options=$4
  236. # Get menu command.
  237. for menucmd in whiptail dialog bash; do
  238. if [ "$(command -v "${menucmd}")" ]; then
  239. menucmd=$(command -v "${menucmd}")
  240. break
  241. fi
  242. done
  243. case "$(basename "${menucmd}")" in
  244. whiptail|dialog)
  245. fn_install_menu_whiptail "${menucmd}" selection "${title}" "${caption}" "${options}" 40 80 30;;
  246. *)
  247. fn_install_menu_bash selection "${title}" "${caption}" "${options}";;
  248. esac
  249. eval "$resultvar=\"${selection}\""
  250. }
  251. # Gets server info from serverlist.csv and puts in to array.
  252. fn_server_info(){
  253. IFS=","
  254. server_info_array=($(grep -aw "${userinput}" "${serverlist}"))
  255. shortname="${server_info_array[0]}" # csgo
  256. gameservername="${server_info_array[1]}" # csgoserver
  257. gamename="${server_info_array[2]}" # Counter Strike: Global Offensive
  258. }
  259. fn_install_getopt(){
  260. userinput="empty"
  261. echo -e "Usage: $0 [option]"
  262. echo -e ""
  263. echo -e "Installer - Linux Game Server Managers - Version ${version}"
  264. echo -e "https://linuxgsm.com"
  265. echo -e ""
  266. echo -e "Commands"
  267. echo -e "install\t\t| Select server to install."
  268. echo -e "servername\t| Enter name of game server to install. e.g $0 csgoserver."
  269. echo -e "list\t\t| List all servers available for install."
  270. exit
  271. }
  272. fn_install_file(){
  273. local_filename="${gameservername}"
  274. if [ -e "${local_filename}" ]; then
  275. i=2
  276. while [ -e "${local_filename}-${i}" ] ; do
  277. (( i++ ))
  278. done
  279. local_filename="${local_filename}-${i}"
  280. fi
  281. cp -R "${selfname}" "${local_filename}"
  282. sed -i -e "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${local_filename}"
  283. sed -i -e "s/gameservername=\"core\"/gameservername=\"${gameservername}\"/g" "${local_filename}"
  284. echo -e "Installed ${gamename} server as ${local_filename}"
  285. echo -e ""
  286. if [ ! -d "${serverfiles}" ]; then
  287. echo -e "./${local_filename} install"
  288. else
  289. echo -e "Remember to check server ports"
  290. echo -e "./${local_filename} details"
  291. fi
  292. echo -e ""
  293. exit
  294. }
  295. # Prevent LinuxGSM from running as root. Except if doing a dependency install.
  296. if [ "$(whoami)" == "root" ]; then
  297. if [ "${userinput}" == "install" ]||[ "${userinput}" == "auto-install" ]||[ "${userinput}" == "i" ]||[ "${userinput}" == "ai" ]; then
  298. if [ "${shortname}" == "core" ]; then
  299. echo -e "[ FAIL ] Do NOT run this script as root!"
  300. exit 1
  301. fi
  302. elif [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]; then
  303. echo -e "[ FAIL ] Do NOT run this script as root!"
  304. exit 1
  305. else
  306. core_functions.sh
  307. check_root.sh
  308. fi
  309. fi
  310. # LinuxGSM installer mode.
  311. if [ "${shortname}" == "core" ]; then
  312. # Download the latest serverlist. This is the complete list of all supported servers.
  313. fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
  314. if [ ! -f "${serverlist}" ]; then
  315. echo -e "[ FAIL ] serverlist.csv could not be loaded."
  316. exit 1
  317. fi
  318. if [ "${userinput}" == "list" ]||[ "${userinput}" == "l" ]; then
  319. {
  320. tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
  321. } | column -s $'\t' -t | more
  322. exit
  323. elif [ "${userinput}" == "install" ]||[ "${userinput}" == "i" ]; then
  324. tail -n +2 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' > "${serverlistmenu}"
  325. fn_install_menu result "LinuxGSM" "Select game server to install." "${serverlistmenu}"
  326. userinput="${result}"
  327. fn_server_info
  328. if [ "${result}" == "${gameservername}" ]; then
  329. fn_install_file
  330. elif [ "${result}" == "" ]; then
  331. echo -e "Install canceled"
  332. else
  333. echo -e "[ FAIL ] menu result does not match gameservername"
  334. echo -e "result: ${result}"
  335. echo -e "gameservername: ${gameservername}"
  336. fi
  337. elif [ "${userinput}" ]; then
  338. fn_server_info
  339. if [ "${userinput}" == "${gameservername}" ]||[ "${userinput}" == "${gamename}" ]||[ "${userinput}" == "${shortname}" ]; then
  340. fn_install_file
  341. else
  342. echo -e "[ FAIL ] unknown game server"
  343. fi
  344. else
  345. fn_install_getopt
  346. fi
  347. # LinuxGSM server mode.
  348. else
  349. core_functions.sh
  350. if [ "${shortname}" != "core-dep" ]; then
  351. # Load LinuxGSM configs.
  352. # These are required to get all the default variables for the specific server.
  353. # Load the default config. If missing download it. If changed reload it.
  354. if [ ! -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" ]; then
  355. mkdir -p "${configdirdefault}/config-lgsm/${gameservername}"
  356. fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  357. fi
  358. if [ ! -f "${configdirserver}/_default.cfg" ]; then
  359. mkdir -p "${configdirserver}"
  360. echo -en "copying _default.cfg...\c"
  361. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  362. exitcode=$?
  363. if [ ${exitcode} -ne 0 ]; then
  364. echo -e "FAIL"
  365. exit 1
  366. else
  367. echo -e "OK"
  368. fi
  369. else
  370. function_file_diff=$(diff -q "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg")
  371. if [ "${function_file_diff}" != "" ]; then
  372. fn_print_warn_nl "_default.cfg has been altered. reloading config."
  373. echo -en "copying _default.cfg...\c"
  374. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  375. exitcode=$?
  376. if [ ${exitcode} -ne 0 ]; then
  377. echo -e "FAIL"
  378. exit 1
  379. else
  380. echo -e "OK"
  381. fi
  382. fi
  383. fi
  384. # shellcheck source=/dev/null
  385. source "${configdirserver}/_default.cfg"
  386. # Load the common.cfg config. If missing download it.
  387. if [ ! -f "${configdirserver}/common.cfg" ]; then
  388. fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
  389. # shellcheck source=/dev/null
  390. source "${configdirserver}/common.cfg"
  391. else
  392. # shellcheck source=/dev/null
  393. source "${configdirserver}/common.cfg"
  394. fi
  395. # Load the instance.cfg config. If missing download it.
  396. if [ ! -f "${configdirserver}/${selfname}.cfg" ]; then
  397. fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  398. # shellcheck source=/dev/null
  399. source "${configdirserver}/${selfname}.cfg"
  400. else
  401. # shellcheck source=/dev/null
  402. source "${configdirserver}/${selfname}.cfg"
  403. fi
  404. # Load the linuxgsm.sh in to tmpdir. If missing download it.
  405. if [ ! -f "${tmpdir}/linuxgsm.sh" ]; then
  406. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "chmodx" "norun" "noforcedl" "nomd5"
  407. fi
  408. fi
  409. # Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
  410. fn_ansi_loader
  411. # Prevents running of core_exit.sh for Travis-CI.
  412. if [ "${travistest}" != "1" ]; then
  413. getopt=$1
  414. core_getopt.sh
  415. fi
  416. fi
  417. fn_currentstatus_tmux(){
  418. check_status.sh
  419. if [ "${status}" != "0" ]; then
  420. currentstatus="ONLINE"
  421. else
  422. currentstatus="OFFLINE"
  423. fi
  424. }
  425. fn_setstatus(){
  426. fn_currentstatus_tmux
  427. echo""
  428. echo -e "Required status: ${requiredstatus}"
  429. counter=0
  430. echo -e "Current status: ${currentstatus}"
  431. while [ "${requiredstatus}" != "${currentstatus}" ]; do
  432. counter=$((counter+1))
  433. fn_currentstatus_tmux
  434. echo -en "New status: ${currentstatus}\\r"
  435. if [ "${requiredstatus}" == "ONLINE" ]; then
  436. (command_start.sh > /dev/null 2>&1)
  437. else
  438. (command_stop.sh > /dev/null 2>&1)
  439. fi
  440. if [ "${counter}" -gt "5" ]; then
  441. currentstatus="FAIL"
  442. echo -e "Current status: ${currentstatus}"
  443. echo -e ""
  444. echo -e "Unable to start or stop server."
  445. exit 1
  446. fi
  447. done
  448. echo -en "New status: ${currentstatus}\\r"
  449. echo -e "\n"
  450. echo -e "Test starting:"
  451. echo -e ""
  452. }
  453. # End of every test will expect the result to either pass or fail
  454. # If the script does not do as intended the whole test will fail
  455. # if expecting a pass
  456. fn_test_result_pass(){
  457. if [ $? != 0 ]; then
  458. echo -e "================================="
  459. echo -e "Expected result: PASS"
  460. echo -e "Actual result: FAIL"
  461. fn_print_fail_nl "TEST FAILED"
  462. exitcode=1
  463. core_exit.sh
  464. else
  465. echo -e "================================="
  466. echo -e "Expected result: PASS"
  467. echo -e "Actual result: PASS"
  468. fn_print_ok_nl "TEST PASSED"
  469. echo -e ""
  470. fi
  471. }
  472. # if expecting a fail
  473. fn_test_result_fail(){
  474. if [ $? == 0 ]; then
  475. echo -e "================================="
  476. echo -e "Expected result: FAIL"
  477. echo -e "Actual result: PASS"
  478. fn_print_fail_nl "TEST FAILED"
  479. exitcode=1
  480. core_exit.sh
  481. else
  482. echo -e "================================="
  483. echo -e "Expected result: FAIL"
  484. echo -e "Actual result: FAIL"
  485. fn_print_ok_nl "TEST PASSED"
  486. echo -e ""
  487. fi
  488. }
  489. # test result n/a
  490. fn_test_result_na(){
  491. echo -e "================================="
  492. echo -e "Expected result: N/A"
  493. echo -e "Actual result: N/A"
  494. fn_print_fail_nl "TEST N/A"
  495. }
  496. sleeptime="0"
  497. echo -e "================================="
  498. echo -e "Travis CI Tests"
  499. echo -e "Linux Game Server Manager"
  500. echo -e "by Daniel Gibbs"
  501. echo -e "Contributors: http://goo.gl/qLmitD"
  502. echo -e "https://linuxgsm.com"
  503. echo -e "================================="
  504. echo -e ""
  505. echo -e "================================="
  506. echo -e "Server Tests"
  507. echo -e "Using: ${gamename}"
  508. echo -e "Testing Branch: ${TRAVIS_BRANCH}"
  509. echo -e "================================="
  510. echo -e ""
  511. echo -e "Tests Summary"
  512. echo -e "================================="
  513. echo -e "0.0 - Pre-test Tasks"
  514. echo -e "0.1 - Create log dir's"
  515. echo -e "0.2 - Enable dev-debug"
  516. echo -e ""
  517. echo -e "1.0 - Pre-install tests"
  518. echo -e "1.1 - start - no files"
  519. echo -e "1.2 - getopt"
  520. echo -e "1.3 - getopt with incorrect args"
  521. echo -e ""
  522. echo -e "2.0 - Installation"
  523. echo -e "2.1 - install"
  524. echo -e ""
  525. echo -e "3.0 - Start/Stop/Restart Tests"
  526. echo -e "3.1 - start"
  527. echo -e "3.2 - start - online"
  528. echo -e "3.3 - start - updateonstart"
  529. echo -e "3.4 - stop"
  530. echo -e "3.5 - stop - offline"
  531. echo -e "3.6 - restart"
  532. echo -e "3.7 - restart - offline"
  533. echo -e ""
  534. echo -e "4.0 - Update Tests"
  535. echo -e "4.1 - update"
  536. echo -e "4.2 - update-lgsm"
  537. echo -e ""
  538. echo -e "5.0 - Monitor Tests"
  539. echo -e "5.1 - monitor - online"
  540. echo -e "5.2 - monitor - offline - with lockfile"
  541. echo -e "5.3 - monitor - offline - no lockfile"
  542. echo -e "5.4 - test-alert"
  543. echo -e ""
  544. echo -e "6.0 - Details Tests"
  545. echo -e "6.1 - details"
  546. echo -e "6.2 - postdetails"
  547. echo -e ""
  548. echo -e "7.0 - Backup Tests"
  549. echo -e "7.1 - backup"
  550. echo -e ""
  551. echo -e "8.0 - Development Tools Tests"
  552. echo -e "8.1 - dev - detect glibc"
  553. echo -e "8.2 - dev - detect ldd"
  554. echo -e "8.3 - dev - detect deps"
  555. echo -e "8.4 - dev - query-raw"
  556. echo -e ""
  557. echo -e "9.0 - Donate"
  558. echo -e "9.1 - donate"
  559. echo -e ""
  560. echo -e "0.0 - Pre-test Tasks"
  561. echo -e "=================================================================="
  562. echo -e "Description:"
  563. echo -e "Create log dir's"
  564. echo -e ""
  565. echo -e ""
  566. echo -e "0.1 - Create log dir's"
  567. echo -e "================================="
  568. echo -e ""
  569. (
  570. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  571. BASH_XTRACEFD="5"
  572. set -x
  573. install_logs.sh
  574. )
  575. echo -e "run order"
  576. echo -e "================="
  577. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  578. echo -e ""
  579. echo -e "0.2 - Enable dev-debug"
  580. echo -e "================================="
  581. echo -e "Description:"
  582. echo -e "Enable dev-debug"
  583. echo -e ""
  584. (
  585. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  586. BASH_XTRACEFD="5"
  587. set -x
  588. command_dev_debug.sh
  589. )
  590. fn_test_result_pass
  591. echo -e "run order"
  592. echo -e "================="
  593. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  594. echo -e ""
  595. echo -e "1.0 - Pre-install tests"
  596. echo -e "=================================================================="
  597. echo -e ""
  598. echo -e "1.1 - start - no files"
  599. echo -e "================================="
  600. echo -e "Description:"
  601. echo -e "test script reaction to missing server files."
  602. echo -e "Command: ./${gameservername} start"
  603. echo -e ""
  604. # Allows for testing not on Travis CI
  605. if [ -z "${TRAVIS}" ]; then
  606. (
  607. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  608. BASH_XTRACEFD="5"
  609. set -x
  610. command_start.sh
  611. )
  612. fn_test_result_fail
  613. else
  614. echo -e "Test bypassed"
  615. fi
  616. echo -e "run order"
  617. echo -e "================="
  618. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  619. echo -e ""
  620. echo -e "1.2 - getopt"
  621. echo -e "================================="
  622. echo -e "Description:"
  623. echo -e "displaying options messages."
  624. echo -e "Command: ./${gameservername}"
  625. echo -e ""
  626. (
  627. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  628. BASH_XTRACEFD="5"
  629. set -x
  630. core_getopt.sh
  631. )
  632. fn_test_result_pass
  633. echo -e "run order"
  634. echo -e "================="
  635. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  636. echo -e ""
  637. echo -e "1.3 - getopt with incorrect args"
  638. echo -e "================================="
  639. echo -e "Description:"
  640. echo -e "displaying options messages."
  641. echo -e "Command: ./${gameservername} abc123"
  642. echo -e ""
  643. getopt="abc123"
  644. (
  645. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  646. BASH_XTRACEFD="5"
  647. set -x
  648. core_getopt.sh
  649. )
  650. fn_test_result_pass
  651. echo -e "run order"
  652. echo -e "================="
  653. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  654. echo -e ""
  655. echo -e "2.0 - Installation"
  656. echo -e "=================================================================="
  657. echo -e ""
  658. echo -e "2.1 - install"
  659. echo -e "================================="
  660. echo -e "Description:"
  661. echo -e "install ${gamename} server."
  662. echo -e "Command: ./${gameservername} auto-install"
  663. (
  664. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  665. BASH_XTRACEFD="5"
  666. set -x
  667. fn_autoinstall
  668. )
  669. fn_test_result_pass
  670. echo -e "run order"
  671. echo -e "================="
  672. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  673. echo -e ""
  674. echo -e "3.0 - Start/Stop/Restart Tests"
  675. echo -e "=================================================================="
  676. echo -e ""
  677. echo -e "3.1 - start"
  678. echo -e "================================="
  679. echo -e "Description:"
  680. echo -e "start ${gamename} server."
  681. echo -e "Command: ./${gameservername} start"
  682. requiredstatus="OFFLINE"
  683. fn_setstatus
  684. (
  685. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  686. BASH_XTRACEFD="5"
  687. set -x
  688. command_start.sh
  689. )
  690. fn_test_result_pass
  691. echo -e "run order"
  692. echo -e "================="
  693. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  694. echo -e ""
  695. echo -e "3.2 - start - online"
  696. echo -e "================================="
  697. echo -e "Description:"
  698. echo -e "start ${gamename} server while already running."
  699. echo -e "Command: ./${gameservername} start"
  700. requiredstatus="ONLINE"
  701. fn_setstatus
  702. (
  703. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  704. BASH_XTRACEFD="5"
  705. set -x
  706. command_start.sh
  707. )
  708. fn_test_result_fail
  709. echo -e "run order"
  710. echo -e "================="
  711. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  712. echo -e ""
  713. echo -e "3.3 - start - updateonstart"
  714. echo -e "================================="
  715. echo -e "Description:"
  716. echo -e "will update server on start."
  717. echo -e "Command: ./${gameservername} start"
  718. requiredstatus="OFFLINE"
  719. fn_setstatus
  720. (
  721. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  722. BASH_XTRACEFD="5"
  723. set -x
  724. updateonstart="on";command_start.sh
  725. )
  726. fn_test_result_pass
  727. echo -e "run order"
  728. echo -e "================="
  729. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  730. echo -e ""
  731. echo -e "3.4 - stop"
  732. echo -e "================================="
  733. echo -e "Description:"
  734. echo -e "stop ${gamename} server."
  735. echo -e "Command: ./${gameservername} stop"
  736. requiredstatus="ONLINE"
  737. fn_setstatus
  738. (
  739. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  740. BASH_XTRACEFD="5"
  741. set -x
  742. command_stop.sh
  743. )
  744. fn_test_result_pass
  745. echo -e "run order"
  746. echo -e "================="
  747. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  748. echo -e ""
  749. echo -e "3.5 - stop - offline"
  750. echo -e "================================="
  751. echo -e "Description:"
  752. echo -e "stop ${gamename} server while already stopped."
  753. echo -e "Command: ./${gameservername} stop"
  754. requiredstatus="OFFLINE"
  755. fn_setstatus
  756. (
  757. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  758. BASH_XTRACEFD="5"
  759. set -x
  760. command_stop.sh
  761. )
  762. fn_test_result_fail
  763. echo -e "run order"
  764. echo -e "================="
  765. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  766. echo -e ""
  767. echo -e "3.6 - restart"
  768. echo -e "================================="
  769. echo -e "Description:"
  770. echo -e "restart ${gamename}."
  771. echo -e "Command: ./${gameservername} restart"
  772. requiredstatus="ONLINE"
  773. fn_setstatus
  774. (
  775. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  776. BASH_XTRACEFD="5"
  777. set -x
  778. command_restart.sh
  779. )
  780. fn_test_result_pass
  781. echo -e "run order"
  782. echo -e "================="
  783. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  784. echo -e ""
  785. echo -e "3.7 - restart - offline"
  786. echo -e "================================="
  787. echo -e "Description:"
  788. echo -e "restart ${gamename} while already stopped."
  789. echo -e "Command: ./${gameservername} restart"
  790. requiredstatus="OFFLINE"
  791. fn_setstatus
  792. (
  793. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  794. BASH_XTRACEFD="5"
  795. set -x
  796. command_restart.sh
  797. )
  798. fn_test_result_pass
  799. echo -e "run order"
  800. echo -e "================="
  801. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  802. echo -e ""
  803. echo -e "4.0 - Update Tests"
  804. echo -e "=================================================================="
  805. echo -e ""
  806. echo -e "4.1 - update"
  807. echo -e "================================="
  808. echo -e "Description:"
  809. echo -e "check for updates."
  810. echo -e "Command: ./${gameservername} update"
  811. requiredstatus="OFFLINE"
  812. fn_setstatus
  813. (
  814. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  815. BASH_XTRACEFD="5"
  816. set -x
  817. command_update.sh
  818. )
  819. fn_test_result_pass
  820. echo -e "run order"
  821. echo -e "================="
  822. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  823. echo -e ""
  824. echo -e "4.2 - update-lgsm"
  825. echo -e "================================="
  826. echo -e "Description:"
  827. echo -e "update LinuxGSM."
  828. echo -e ""
  829. echo -e "Command: ./jc2server update-lgam"
  830. requiredstatus="ONLINE"
  831. fn_setstatus
  832. (
  833. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  834. BASH_XTRACEFD="5"
  835. set -x
  836. command_update_linuxgsm.sh
  837. )
  838. fn_test_result_pass
  839. echo -e "run order"
  840. echo -e "================="
  841. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  842. echo -e ""
  843. echo -e "5.0 - Monitor Tests"
  844. echo -e "=================================================================="
  845. echo -e ""
  846. info_config.sh
  847. echo -e "Server IP - Port: ${ip}:${port}"
  848. echo -e "Server IP - Query Port: ${ip}:${queryport}"
  849. echo -e ""
  850. echo -e "5.1 - monitor - online"
  851. echo -e "================================="
  852. echo -e "Description:"
  853. echo -e "run monitor server while already running."
  854. echo -e "Command: ./${gameservername} monitor"
  855. requiredstatus="ONLINE"
  856. fn_setstatus
  857. (
  858. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  859. BASH_XTRACEFD="5"
  860. set -x
  861. command_monitor.sh
  862. )
  863. fn_test_result_pass
  864. echo -e "run order"
  865. echo -e "================="
  866. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  867. echo -e ""
  868. echo -e "5.2 - monitor - offline - with lockfile"
  869. echo -e "================================="
  870. echo -e "Description:"
  871. echo -e "run monitor while server is offline with lockfile."
  872. echo -e "Command: ./${gameservername} monitor"
  873. requiredstatus="OFFLINE"
  874. fn_setstatus
  875. fn_print_info_nl "creating lockfile."
  876. date '+%s' > "${lockdir}/${selfname}.lock"
  877. (
  878. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  879. BASH_XTRACEFD="5"
  880. set -x
  881. command_monitor.sh
  882. )
  883. fn_test_result_pass
  884. echo -e "run order"
  885. echo -e "================="
  886. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  887. echo -e ""
  888. echo -e "5.3 - monitor - offline - no lockfile"
  889. echo -e "================================="
  890. echo -e "Description:"
  891. echo -e "run monitor while server is offline with no lockfile."
  892. echo -e "Command: ./${gameservername} monitor"
  893. requiredstatus="OFFLINE"
  894. fn_setstatus
  895. (
  896. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  897. BASH_XTRACEFD="5"
  898. set -x
  899. command_monitor.sh
  900. )
  901. fn_test_result_fail
  902. echo -e "run order"
  903. echo -e "================="
  904. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  905. echo -e ""
  906. echo -e "5.4 - test-alert"
  907. echo -e "================================="
  908. echo -e "Description:"
  909. echo -e "run monitor while server is offline with no lockfile."
  910. echo -e "Command: ./${gameservername} test-alert"
  911. requiredstatus="OFFLINE"
  912. fn_setstatus
  913. (
  914. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  915. BASH_XTRACEFD="5"
  916. set -x
  917. command_test_alert.sh
  918. )
  919. fn_test_result_fail
  920. echo -e "run order"
  921. echo -e "================="
  922. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  923. echo -e ""
  924. echo -e "6.0 - Details Tests"
  925. echo -e "=================================================================="
  926. echo -e ""
  927. echo -e "6.1 - details"
  928. echo -e "================================="
  929. echo -e "Description:"
  930. echo -e "display details."
  931. echo -e "Command: ./${gameservername} details"
  932. requiredstatus="ONLINE"
  933. fn_setstatus
  934. (
  935. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  936. BASH_XTRACEFD="5"
  937. set -x
  938. command_details.sh
  939. )
  940. fn_test_result_pass
  941. echo -e "run order"
  942. echo -e "================="
  943. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  944. echo -e ""
  945. echo -e "6.2 - postdetails"
  946. echo -e "================================="
  947. echo -e "Description:"
  948. echo -e "post details."
  949. echo -e "Command: ./${gameservername} postdetails"
  950. requiredstatus="ONLINE"
  951. fn_setstatus
  952. (
  953. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  954. BASH_XTRACEFD="5"
  955. set -x
  956. command_postdetails.sh
  957. )
  958. fn_test_result_pass
  959. echo -e "run order"
  960. echo -e "================="
  961. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  962. echo -e ""
  963. echo -e "7.0 - Backup Tests"
  964. echo -e "=================================================================="
  965. echo -e ""
  966. echo -e "7.1 - backup"
  967. echo -e "================================="
  968. echo -e "Description:"
  969. echo -e "run a backup."
  970. echo -e "Command: ./${gameservername} backup"
  971. requiredstatus="ONLINE"
  972. fn_setstatus
  973. echo -e "test de-activated until issue #1839 fixed"
  974. #(command_backup.sh)
  975. fn_test_result_pass
  976. echo -e "run order"
  977. echo -e "================="
  978. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  979. echo -e ""
  980. echo -e "8.0 - Development Tools Tests"
  981. echo -e "=================================================================="
  982. echo -e ""
  983. echo -e "8.1 - dev - detect glibc"
  984. echo -e "================================="
  985. echo -e "Description:"
  986. echo -e "detect glibc."
  987. echo -e "Command: ./${gameservername} detect-glibc"
  988. requiredstatus="ONLINE"
  989. fn_setstatus
  990. (
  991. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  992. BASH_XTRACEFD="5"
  993. set -x
  994. command_dev_detect_glibc.sh
  995. )
  996. fn_test_result_pass
  997. echo -e "run order"
  998. echo -e "================="
  999. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  1000. echo -e ""
  1001. echo -e "8.2 - dev - detect ldd"
  1002. echo -e "================================="
  1003. echo -e "Description:"
  1004. echo -e "detect ldd."
  1005. echo -e "Command: ./${gameservername} detect-ldd"
  1006. requiredstatus="ONLINE"
  1007. fn_setstatus
  1008. (
  1009. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  1010. BASH_XTRACEFD="5"
  1011. set -x
  1012. command_dev_detect_ldd.sh
  1013. )
  1014. fn_test_result_pass
  1015. echo -e "run order"
  1016. echo -e "================="
  1017. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  1018. echo -e ""
  1019. echo -e "8.3 - dev - detect deps"
  1020. echo -e "================================="
  1021. echo -e "Description:"
  1022. echo -e "detect dependencies."
  1023. echo -e "Command: ./${gameservername} detect-deps"
  1024. requiredstatus="ONLINE"
  1025. fn_setstatus
  1026. (
  1027. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  1028. BASH_XTRACEFD="5"
  1029. set -x
  1030. command_dev_detect_deps.sh
  1031. )
  1032. fn_test_result_pass
  1033. echo -e "run order"
  1034. echo -e "================="
  1035. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  1036. echo -e ""
  1037. echo -e "8.4 - dev - query-raw"
  1038. echo -e "================================="
  1039. echo -e "Description:"
  1040. echo -e "raw query output."
  1041. echo -e "Command: ./${gameservername} query-raw"
  1042. requiredstatus="ONLINE"
  1043. fn_setstatus
  1044. (
  1045. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  1046. BASH_XTRACEFD="5"
  1047. set -x
  1048. command_dev_query_raw.sh
  1049. )
  1050. fn_test_result_na
  1051. echo -e "run order"
  1052. echo -e "================="
  1053. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  1054. echo -e ""
  1055. echo -e "9.0 - Donate"
  1056. echo -e "=================================================================="
  1057. echo -e ""
  1058. echo -e "9.1 - donate"
  1059. echo -e "================================="
  1060. echo -e "Description:"
  1061. echo -e "donate."
  1062. echo -e "Command: ./${gameservername} donate"
  1063. requiredstatus="ONLINE"
  1064. fn_setstatus
  1065. (
  1066. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  1067. BASH_XTRACEFD="5"
  1068. set -x
  1069. command_donate.sh
  1070. )
  1071. fn_test_result_pass
  1072. echo -e "run order"
  1073. echo -e "================="
  1074. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  1075. echo -e ""
  1076. echo -e "================================="
  1077. echo -e "Server Tests - Complete!"
  1078. echo -e "Using: ${gamename}"
  1079. echo -e "================================="
  1080. requiredstatus="OFFLINE"
  1081. fn_setstatus
  1082. core_exit.sh