tests_jc2server.sh 30 KB

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