tests_jc2server.sh 28 KB

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