tests_mcserver.sh 29 KB

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