tests_mcserver.sh 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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: Minecraft | 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="mc"
  22. gameservername="mcserver"
  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 "30s Pause"
  637. echo "================================="
  638. echo "Description:"
  639. echo "give time for server to fully start."
  640. echo "Command: sleep 30"
  641. requiredstatus="ONLINE"
  642. fn_setstatus
  643. sleep 30
  644. echo ""
  645. echo "3.4 - stop"
  646. echo "================================="
  647. echo "Description:"
  648. echo "stop ${gamename} server."
  649. echo "Command: ./${gameservername} stop"
  650. requiredstatus="ONLINE"
  651. fn_setstatus
  652. (
  653. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  654. BASH_XTRACEFD="5"
  655. set -x
  656. command_stop.sh
  657. )
  658. fn_test_result_pass
  659. echo "run order"
  660. echo "================="
  661. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  662. echo ""
  663. echo "3.5 - stop - offline"
  664. echo "================================="
  665. echo "Description:"
  666. echo "stop ${gamename} server while already stopped."
  667. echo "Command: ./${gameservername} stop"
  668. requiredstatus="OFFLINE"
  669. fn_setstatus
  670. (
  671. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  672. BASH_XTRACEFD="5"
  673. set -x
  674. command_stop.sh
  675. )
  676. fn_test_result_fail
  677. echo "run order"
  678. echo "================="
  679. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  680. echo ""
  681. echo "3.6 - restart"
  682. echo "================================="
  683. echo "Description:"
  684. echo "restart ${gamename}."
  685. echo "Command: ./${gameservername} restart"
  686. requiredstatus="ONLINE"
  687. fn_setstatus
  688. (
  689. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  690. BASH_XTRACEFD="5"
  691. set -x
  692. command_restart.sh
  693. )
  694. fn_test_result_pass
  695. echo "run order"
  696. echo "================="
  697. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  698. echo ""
  699. echo "3.7 - restart - offline"
  700. echo "================================="
  701. echo "Description:"
  702. echo "restart ${gamename} while already stopped."
  703. echo "Command: ./${gameservername} restart"
  704. requiredstatus="OFFLINE"
  705. fn_setstatus
  706. (
  707. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  708. BASH_XTRACEFD="5"
  709. set -x
  710. command_restart.sh
  711. )
  712. fn_test_result_pass
  713. echo "run order"
  714. echo "================="
  715. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  716. echo ""
  717. echo "4.0 - Update Tests"
  718. echo "=================================================================="
  719. echo ""
  720. echo "4.1 - update"
  721. echo "================================="
  722. echo "Description:"
  723. echo "check for updates."
  724. echo "Command: ./${gameservername} update"
  725. requiredstatus="OFFLINE"
  726. fn_setstatus
  727. (
  728. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  729. BASH_XTRACEFD="5"
  730. set -x
  731. command_update.sh
  732. )
  733. fn_test_result_pass
  734. echo "run order"
  735. echo "================="
  736. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  737. echo ""
  738. echo "Inserting IP address"
  739. echo "================================="
  740. echo "Description:"
  741. echo "Inserting Travis IP in to config."
  742. echo "Allows monitor to work"
  743. if [ "$(ip -o -4 addr|grep eth0)" ]; then
  744. travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
  745. else
  746. travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
  747. fi
  748. sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
  749. echo "IP: ${travisip}"
  750. echo ""
  751. echo "5.0 - Monitor Tests"
  752. echo "=================================================================="
  753. echo ""
  754. echo "Server IP - Port: ${ip}:${port}"
  755. echo "Server IP - Query Port: ${ip}:${queryport}"
  756. echo ""
  757. echo "30s Pause"
  758. echo "================================="
  759. echo "Description:"
  760. echo "give time for server to fully start."
  761. echo "Command: sleep 30"
  762. requiredstatus="ONLINE"
  763. fn_setstatus
  764. sleep 30
  765. echo ""
  766. echo "5.1 - monitor - online"
  767. echo "================================="
  768. echo "Description:"
  769. echo "run monitor server while already running."
  770. echo "Command: ./${gameservername} monitor"
  771. requiredstatus="ONLINE"
  772. fn_setstatus
  773. (
  774. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  775. BASH_XTRACEFD="5"
  776. set -x
  777. command_monitor.sh
  778. )
  779. fn_test_result_pass
  780. echo "run order"
  781. echo "================="
  782. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  783. echo ""
  784. echo "5.2 - monitor - offline - with lockfile"
  785. echo "================================="
  786. echo "Description:"
  787. echo "run monitor while server is offline with lockfile."
  788. echo "Command: ./${gameservername} monitor"
  789. requiredstatus="OFFLINE"
  790. fn_setstatus
  791. fn_print_info_nl "creating lockfile."
  792. date '+%s' > "${rootdir}/${lockselfname}"
  793. (
  794. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  795. BASH_XTRACEFD="5"
  796. set -x
  797. command_monitor.sh
  798. )
  799. fn_test_result_pass
  800. echo "run order"
  801. echo "================="
  802. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  803. echo ""
  804. echo "5.3 - monitor - offline - no lockfile"
  805. echo "================================="
  806. echo "Description:"
  807. echo "run monitor while server is offline with no lockfile."
  808. echo "Command: ./${gameservername} monitor"
  809. requiredstatus="OFFLINE"
  810. fn_setstatus
  811. (
  812. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  813. BASH_XTRACEFD="5"
  814. set -x
  815. command_monitor.sh
  816. )
  817. fn_test_result_fail
  818. echo "run order"
  819. echo "================="
  820. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  821. echo ""
  822. echo "5.4 - test-alert"
  823. echo "================================="
  824. echo "Description:"
  825. echo "run monitor while server is offline with no lockfile."
  826. echo "Command: ./${gameservername} test-alert"
  827. requiredstatus="OFFLINE"
  828. fn_setstatus
  829. (
  830. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  831. BASH_XTRACEFD="5"
  832. set -x
  833. command_test_alert.sh
  834. )
  835. fn_test_result_fail
  836. echo "run order"
  837. echo "================="
  838. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  839. echo ""
  840. echo "6.0 - Details Tests"
  841. echo "=================================================================="
  842. echo ""
  843. echo "6.1 - details"
  844. echo "================================="
  845. echo "Description:"
  846. echo "display details."
  847. echo "Command: ./${gameservername} details"
  848. requiredstatus="ONLINE"
  849. fn_setstatus
  850. (
  851. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  852. BASH_XTRACEFD="5"
  853. set -x
  854. command_details.sh
  855. )
  856. fn_test_result_pass
  857. echo "run order"
  858. echo "================="
  859. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  860. echo ""
  861. echo "6.2 - postdetails"
  862. echo "================================="
  863. echo "Description:"
  864. echo "post details."
  865. echo "Command: ./${gameservername} postdetails"
  866. requiredstatus="ONLINE"
  867. fn_setstatus
  868. (
  869. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  870. BASH_XTRACEFD="5"
  871. set -x
  872. command_postdetails.sh
  873. )
  874. fn_test_result_pass
  875. echo "run order"
  876. echo "================="
  877. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  878. echo ""
  879. echo "7.0 - Backup Tests"
  880. echo "=================================================================="
  881. echo ""
  882. echo "7.1 - backup"
  883. echo "================================="
  884. echo "Description:"
  885. echo "run a backup."
  886. echo "Command: ./${gameservername} backup"
  887. requiredstatus="ONLINE"
  888. fn_setstatus
  889. echo "test de-activated until issue #1839 fixed"
  890. #(command_backup.sh)
  891. fn_test_result_pass
  892. echo "run order"
  893. echo "================="
  894. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  895. echo ""
  896. echo "8.0 - Development Tools Tests"
  897. echo "=================================================================="
  898. echo ""
  899. echo "8.1 - dev - detect glibc"
  900. echo "================================="
  901. echo "Description:"
  902. echo "detect glibc."
  903. echo "Command: ./${gameservername} detect-glibc"
  904. requiredstatus="ONLINE"
  905. fn_setstatus
  906. (
  907. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  908. BASH_XTRACEFD="5"
  909. set -x
  910. command_dev_detect_glibc.sh
  911. )
  912. fn_test_result_pass
  913. echo "run order"
  914. echo "================="
  915. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  916. echo ""
  917. echo "8.2 - dev - detect ldd"
  918. echo "================================="
  919. echo "Description:"
  920. echo "detect ldd."
  921. echo "Command: ./${gameservername} detect-ldd"
  922. requiredstatus="ONLINE"
  923. fn_setstatus
  924. (
  925. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  926. BASH_XTRACEFD="5"
  927. set -x
  928. command_dev_detect_ldd.sh
  929. )
  930. fn_test_result_pass
  931. echo "run order"
  932. echo "================="
  933. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  934. echo ""
  935. echo "8.3 - dev - detect deps"
  936. echo "================================="
  937. echo "Description:"
  938. echo "detect dependencies."
  939. echo "Command: ./${gameservername} detect-deps"
  940. requiredstatus="ONLINE"
  941. fn_setstatus
  942. (
  943. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  944. BASH_XTRACEFD="5"
  945. set -x
  946. command_dev_detect_deps.sh
  947. )
  948. fn_test_result_pass
  949. echo "run order"
  950. echo "================="
  951. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  952. echo ""
  953. echo "Inserting IP address"
  954. echo "================================="
  955. echo "Description:"
  956. echo "Inserting Travis IP in to config."
  957. echo "Allows monitor to work"
  958. if [ "$(ip -o -4 addr|grep eth0)" ]; then
  959. travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
  960. else
  961. travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
  962. fi
  963. sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
  964. echo "IP: ${travisip}"
  965. echo ""
  966. echo "8.4 - dev - query-raw"
  967. echo "================================="
  968. echo "Description:"
  969. echo "raw query output."
  970. echo "Command: ./${gameservername} query-raw"
  971. requiredstatus="ONLINE"
  972. fn_setstatus
  973. (
  974. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  975. BASH_XTRACEFD="5"
  976. set -x
  977. command_dev_query_raw.sh
  978. )
  979. fn_test_result_na
  980. echo "run order"
  981. echo "================="
  982. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  983. echo ""
  984. echo "================================="
  985. echo "Server Tests - Complete!"
  986. echo "Using: ${gamename}"
  987. echo "================================="
  988. requiredstatus="OFFLINE"
  989. fn_setstatus
  990. fn_print_info "Tidying up directories."
  991. rm -rfv "${serverfiles}"
  992. core_exit.sh