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