tests_mcserver.sh 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2020 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="v20.1.5"
  21. shortname="mc"
  22. gameservername="mcserver"
  23. rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
  24. selfname=$(basename "$(readlink -f "${BASH_SOURCE[0]}")")
  25. lgsmdir="${rootdir}/lgsm"
  26. logdir="${rootdir}/log"
  27. lgsmlogdir="${logdir}/lgsm"
  28. steamcmddir="${rootdir}/steamcmd"
  29. serverfiles="${rootdir}/serverfiles"
  30. functionsdir="${lgsmdir}/functions"
  31. tmpdir="${lgsmdir}/tmp"
  32. datadir="${lgsmdir}/data"
  33. lockdir="${lgsmdir}/lock"
  34. serverlist="${datadir}/serverlist.csv"
  35. serverlistmenu="${datadir}/serverlistmenu.csv"
  36. configdir="${lgsmdir}/config-lgsm"
  37. configdirserver="${configdir}/${gameservername}"
  38. configdirdefault="${lgsmdir}/config-default"
  39. userinput="${1}"
  40. # Allows for testing not on Travis CI
  41. if [ ! -v TRAVIS ]; then
  42. TRAVIS_BRANCH="develop"
  43. TRAVIS_BUILD_DIR="${rootdir}"
  44. else
  45. selfname="travis"
  46. travistest="1"
  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[0]}"
  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. fn_bootstrap_fetch_file(){
  62. remote_fileurl="${1}"
  63. local_filedir="${2}"
  64. local_filename="${3}"
  65. chmodx="${4:-0}"
  66. run="${5:-0}"
  67. forcedl="${6:-0}"
  68. md5="${7:-0}"
  69. # Download file if missing or download forced.
  70. if [ ! -f "${local_filedir}/${local_filename}" ]||[ "${forcedl}" == "forcedl" ]; then
  71. if [ ! -d "${local_filedir}" ]; then
  72. mkdir -p "${local_filedir}"
  73. fi
  74. # If curl exists download file.
  75. if [ "$(command -v curl 2>/dev/null)" ]; then
  76. # Trap to remove part downloaded files.
  77. echo -en " fetching ${local_filename}...\c"
  78. curlcmd=$(curl -s --fail -L -o "${local_filedir}/${local_filename}" "${remote_fileurl}" 2>&1)
  79. local exitcode=$?
  80. if [ ${exitcode} -ne 0 ]; then
  81. echo -e "FAIL"
  82. if [ -f "${lgsmlog}" ]; then
  83. echo -e "${remote_fileurl}" | tee -a "${lgsmlog}"
  84. echo -e "${curlcmd}" | tee -a "${lgsmlog}"
  85. fi
  86. exit 1
  87. else
  88. echo -e "OK"
  89. fi
  90. else
  91. echo -e "[ FAIL ] Curl is not installed"
  92. exit 1
  93. fi
  94. # Make file chmodx if chmodx is set.
  95. if [ "${chmodx}" == "chmodx" ]; then
  96. chmod +x "${local_filedir}/${local_filename}"
  97. fi
  98. fi
  99. if [ -f "${local_filedir}/${local_filename}" ]; then
  100. # Run file if run is set.
  101. if [ "${run}" == "run" ]; then
  102. # shellcheck source=/dev/null
  103. source "${local_filedir}/${local_filename}"
  104. fi
  105. fi
  106. }
  107. fn_bootstrap_fetch_file_github(){
  108. github_file_url_dir="${1}"
  109. github_file_url_name="${2}"
  110. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  111. remote_fileurl="${githuburl}"
  112. local_filedir="${3}"
  113. local_filename="${github_file_url_name}"
  114. chmodx="${4:-0}"
  115. run="${5:-0}"
  116. forcedl="${6:-0}"
  117. md5="${7:-0}"
  118. # Passes vars to the file download function.
  119. fn_bootstrap_fetch_file "${remote_fileurl}" "${local_filedir}" "${local_filename}" "${chmodx}" "${run}" "${forcedl}" "${md5}"
  120. }
  121. # Installer menu.
  122. fn_print_center() {
  123. columns=$(tput cols)
  124. line="$*"
  125. printf "%*s\n" $(( (${#line} + columns) / 2)) "${line}"
  126. }
  127. fn_print_horizontal(){
  128. printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' "="
  129. }
  130. # Bash menu.
  131. fn_install_menu_bash() {
  132. local resultvar=$1
  133. title=$2
  134. caption=$3
  135. options=$4
  136. fn_print_horizontal
  137. fn_print_center "${title}"
  138. fn_print_center "${caption}"
  139. fn_print_horizontal
  140. menu_options=()
  141. while read -r line || [[ -n "${line}" ]]; do
  142. var=$(echo -e "${line}" | awk -F "," '{print $2 " - " $3}')
  143. menu_options+=( "${var}" )
  144. done < "${options}"
  145. menu_options+=( "Cancel" )
  146. select option in "${menu_options[@]}"; do
  147. if [ "${option}" ]&&[ "${option}" != "Cancel" ]; then
  148. eval "$resultvar=\"${option/%\ */}\""
  149. fi
  150. break
  151. done
  152. }
  153. # Whiptail/Dialog menu.
  154. fn_install_menu_whiptail() {
  155. local menucmd=$1
  156. local resultvar=$2
  157. title=$3
  158. caption=$4
  159. options=$5
  160. height=${6:-40}
  161. width=${7:-80}
  162. menuheight=${8:-30}
  163. IFS=","
  164. menu_options=()
  165. while read -r line; do
  166. key=$(echo -e "${line}" | awk -F "," '{print $3}')
  167. val=$(echo -e "${line}" | awk -F "," '{print $2}')
  168. menu_options+=( "${val//\"}" "${key//\"}" )
  169. done < "${options}"
  170. OPTION=$(${menucmd} --title "${title}" --menu "${caption}" "${height}" "${width}" "${menuheight}" "${menu_options[@]}" 3>&1 1>&2 2>&3)
  171. if [ $? == 0 ]; then
  172. eval "$resultvar=\"${OPTION}\""
  173. else
  174. eval "$resultvar="
  175. fi
  176. }
  177. # Menu selector.
  178. fn_install_menu() {
  179. local resultvar=$1
  180. local selection=""
  181. title=$2
  182. caption=$3
  183. options=$4
  184. # Get menu command.
  185. for menucmd in whiptail dialog bash; do
  186. if [ "$(command -v "${menucmd}")" ]; then
  187. menucmd=$(command -v "${menucmd}")
  188. break
  189. fi
  190. done
  191. case "$(basename "${menucmd}")" in
  192. whiptail|dialog)
  193. fn_install_menu_whiptail "${menucmd}" selection "${title}" "${caption}" "${options}" 40 80 30;;
  194. *)
  195. fn_install_menu_bash selection "${title}" "${caption}" "${options}";;
  196. esac
  197. eval "$resultvar=\"${selection}\""
  198. }
  199. # Gets server info from serverlist.csv and puts in to array.
  200. fn_server_info(){
  201. IFS=","
  202. server_info_array=($(grep -aw "${userinput}" "${serverlist}"))
  203. shortname="${server_info_array[0]}" # csgo
  204. gameservername="${server_info_array[1]}" # csgoserver
  205. gamename="${server_info_array[2]}" # Counter Strike: Global Offensive
  206. }
  207. fn_install_getopt(){
  208. userinput="empty"
  209. echo -e "Usage: $0 [option]"
  210. echo -e ""
  211. echo -e "Installer - Linux Game Server Managers - Version ${version}"
  212. echo -e "https://linuxgsm.com"
  213. echo -e ""
  214. echo -e "Commands"
  215. echo -e "install\t\t| Select server to install."
  216. echo -e "servername\t| Enter name of game server to install. e.g $0 csgoserver."
  217. echo -e "list\t\t| List all servers available for install."
  218. exit
  219. }
  220. fn_install_file(){
  221. local_filename="${gameservername}"
  222. if [ -e "${local_filename}" ]; then
  223. i=2
  224. while [ -e "${local_filename}-${i}" ] ; do
  225. let i++
  226. done
  227. local_filename="${local_filename}-${i}"
  228. fi
  229. cp -R "${selfname}" "${local_filename}"
  230. sed -i -e "s/shortname=\"core\"/shortname=\"${shortname}\"/g" "${local_filename}"
  231. sed -i -e "s/gameservername=\"core\"/gameservername=\"${gameservername}\"/g" "${local_filename}"
  232. echo -e "Installed ${gamename} server as ${local_filename}"
  233. echo -e ""
  234. if [ ! -d "${serverfiles}" ]; then
  235. echo -e "./${local_filename} install"
  236. else
  237. echo -e "Remember to check server ports"
  238. echo -e "./${local_filename} details"
  239. fi
  240. echo -e ""
  241. exit
  242. }
  243. # Prevent LinuxGSM from running as root. Except if doing a dependency install.
  244. if [ "$(whoami)" == "root" ]; then
  245. if [ "${userinput}" == "install" ]||[ "${userinput}" == "auto-install" ]||[ "${userinput}" == "i" ]||[ "${userinput}" == "ai" ]; then
  246. if [ "${shortname}" == "core" ]; then
  247. echo -e "[ FAIL ] Do NOT run this script as root!"
  248. exit 1
  249. fi
  250. elif [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]; then
  251. echo -e "[ FAIL ] Do NOT run this script as root!"
  252. exit 1
  253. else
  254. core_functions.sh
  255. check_root.sh
  256. fi
  257. fi
  258. # LinuxGSM installer mode.
  259. if [ "${shortname}" == "core" ]; then
  260. # Download the latest serverlist. This is the complete list of all supported servers.
  261. fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
  262. if [ ! -f "${serverlist}" ]; then
  263. echo -e "[ FAIL ] serverlist.csv could not be loaded."
  264. exit 1
  265. fi
  266. if [ "${userinput}" == "list" ]||[ "${userinput}" == "l" ]; then
  267. {
  268. tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
  269. } | column -s $'\t' -t | more
  270. exit
  271. elif [ "${userinput}" == "install" ]||[ "${userinput}" == "i" ]; then
  272. tail -n +2 "${serverlist}" | awk -F "," '{print $1 "," $2 "," $3}' > "${serverlistmenu}"
  273. fn_install_menu result "LinuxGSM" "Select game server to install." "${serverlistmenu}"
  274. userinput="${result}"
  275. fn_server_info
  276. if [ "${result}" == "${gameservername}" ]; then
  277. fn_install_file
  278. elif [ "${result}" == "" ]; then
  279. echo -e "Install canceled"
  280. else
  281. echo -e "[ FAIL ] menu result does not match gameservername"
  282. echo -e "result: ${result}"
  283. echo -e "gameservername: ${gameservername}"
  284. fi
  285. elif [ "${userinput}" ]; then
  286. fn_server_info
  287. if [ "${userinput}" == "${gameservername}" ]||[ "${userinput}" == "${gamename}" ]||[ "${userinput}" == "${shortname}" ]; then
  288. fn_install_file
  289. else
  290. echo -e "[ FAIL ] unknown game server"
  291. fi
  292. else
  293. fn_install_getopt
  294. fi
  295. # LinuxGSM server mode.
  296. else
  297. core_functions.sh
  298. if [ "${shortname}" != "core-dep" ]; then
  299. # Load LinuxGSM configs.
  300. # These are required to get all the default variables for the specific server.
  301. # Load the default config. If missing download it. If changed reload it.
  302. if [ ! -f "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" ]; then
  303. mkdir -p "${configdirdefault}/config-lgsm/${gameservername}"
  304. fn_fetch_config "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "_default.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  305. fi
  306. if [ ! -f "${configdirserver}/_default.cfg" ]; then
  307. mkdir -p "${configdirserver}"
  308. echo -en " copying _default.cfg...\c"
  309. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  310. exitcode=$?
  311. if [ ${exitcode} -ne 0 ]; then
  312. echo -e "FAIL"
  313. exit 1
  314. else
  315. echo -e "OK"
  316. fi
  317. else
  318. function_file_diff=$(diff -q "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg")
  319. if [ "${function_file_diff}" != "" ]; then
  320. fn_print_warn_nl "_default.cfg has been altered. reloading config."
  321. echo -en " copying _default.cfg...\c"
  322. cp -R "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" "${configdirserver}/_default.cfg"
  323. exitcode=$?
  324. if [ ${exitcode} -ne 0 ]; then
  325. echo -e "FAIL"
  326. exit 1
  327. else
  328. echo -e "OK"
  329. fi
  330. fi
  331. fi
  332. source "${configdirserver}/_default.cfg"
  333. # Load the common.cfg config. If missing download it.
  334. if [ ! -f "${configdirserver}/common.cfg" ]; then
  335. fn_fetch_config "lgsm/config-default/config-lgsm" "common-template.cfg" "${configdirserver}" "common.cfg" "${chmodx}" "nochmodx" "norun" "noforcedl" "nomd5"
  336. source "${configdirserver}/common.cfg"
  337. else
  338. source "${configdirserver}/common.cfg"
  339. fi
  340. # Load the instance.cfg config. If missing download it.
  341. if [ ! -f "${configdirserver}/${selfname}.cfg" ]; then
  342. fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  343. source "${configdirserver}/${selfname}.cfg"
  344. else
  345. source "${configdirserver}/${selfname}.cfg"
  346. fi
  347. # Load the linuxgsm.sh in to tmpdir. If missing download it.
  348. if [ ! -f "${tmpdir}/linuxgsm.sh" ]; then
  349. fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "chmodx" "norun" "noforcedl" "nomd5"
  350. fi
  351. fi
  352. # Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
  353. fn_ansi_loader
  354. # Prevents running of core_exit.sh for Travis-CI.
  355. if [ -z "${travistest}" ]; then
  356. getopt=$1
  357. core_getopt.sh
  358. fi
  359. fi
  360. fn_currentstatus_tmux(){
  361. check_status.sh
  362. if [ "${status}" != "0" ]; then
  363. currentstatus="ONLINE"
  364. else
  365. currentstatus="OFFLINE"
  366. fi
  367. }
  368. fn_currentstatus_ts3(){
  369. check_status.sh
  370. if [ "${status}" != "0" ]; then
  371. currentstatus="ONLINE"
  372. else
  373. currentstatus="OFFLINE"
  374. fi
  375. }
  376. fn_setstatus(){
  377. fn_currentstatus_tmux
  378. echo""
  379. echo -e "Required status: ${requiredstatus}"
  380. counter=0
  381. echo -e "Current status: ${currentstatus}"
  382. while [ "${requiredstatus}" != "${currentstatus}" ]; do
  383. counter=$((counter+1))
  384. fn_currentstatus_tmux
  385. echo -en "New status: ${currentstatus}\\r"
  386. if [ "${requiredstatus}" == "ONLINE" ]; then
  387. (command_start.sh > /dev/null 2>&1)
  388. else
  389. (command_stop.sh > /dev/null 2>&1)
  390. fi
  391. if [ "${counter}" -gt "5" ]; then
  392. currentstatus="FAIL"
  393. echo -e "Current status: ${currentstatus}"
  394. echo -e ""
  395. echo -e "Unable to start or stop server."
  396. exit 1
  397. fi
  398. done
  399. echo -en "New status: ${currentstatus}\\r"
  400. echo -e "\n"
  401. echo -e "Test starting:"
  402. echo -e ""
  403. }
  404. # End of every test will expect the result to either pass or fail
  405. # If the script does not do as intended the whole test will fail
  406. # if expecting a pass
  407. fn_test_result_pass(){
  408. if [ $? != 0 ]; then
  409. echo -e "================================="
  410. echo -e "Expected result: PASS"
  411. echo -e "Actual result: FAIL"
  412. fn_print_fail_nl "TEST FAILED"
  413. exitcode=1
  414. core_exit.sh
  415. else
  416. echo -e "================================="
  417. echo -e "Expected result: PASS"
  418. echo -e "Actual result: PASS"
  419. fn_print_ok_nl "TEST PASSED"
  420. echo -e ""
  421. fi
  422. }
  423. # if expecting a fail
  424. fn_test_result_fail(){
  425. if [ $? == 0 ]; then
  426. echo -e "================================="
  427. echo -e "Expected result: FAIL"
  428. echo -e "Actual result: PASS"
  429. fn_print_fail_nl "TEST FAILED"
  430. exitcode=1
  431. core_exit.sh
  432. else
  433. echo -e "================================="
  434. echo -e "Expected result: FAIL"
  435. echo -e "Actual result: FAIL"
  436. fn_print_ok_nl "TEST PASSED"
  437. echo -e ""
  438. fi
  439. }
  440. # test result n/a
  441. fn_test_result_na(){
  442. echo -e "================================="
  443. echo -e "Expected result: N/A"
  444. echo -e "Actual result: N/A"
  445. fn_print_fail_nl "TEST N/A"
  446. }
  447. sleeptime="0"
  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' > "${lockdir}/${selfname}.lock"
  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. if [ ! -v TRAVIS ]; then
  988. fn_print_info "Tidying up directories."
  989. rm -rfv "${serverfiles:?}"
  990. fi
  991. core_exit.sh