tests_jc2server.sh 31 KB

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