tests_mcserver.sh 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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}"
  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. # 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 -e "${curlcmd}" | tee -a "${lgsmlog}"
  88. fi
  89. exit 1
  90. else
  91. echo -e "OK"
  92. fi
  93. else
  94. echo -e "[ 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 -e "${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 -e "${line}" | awk -F "," '{print $3}')
  170. val=$(echo -e "${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 -e "Usage: $0 [option]"
  213. echo -e ""
  214. echo -e "Installer - Linux Game Server Managers - Version ${version}"
  215. echo -e "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 -e "Installed ${gamename} server as ${local_filename}"
  236. echo -e ""
  237. if [ ! -d "${serverfiles}" ]; then
  238. echo -e "./${local_filename} install"
  239. else
  240. echo -e "Remember to check server ports"
  241. echo -e "./${local_filename} details"
  242. fi
  243. echo -e ""
  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 -e "[ 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 -e "[ 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. # LinuxGSM installer mode.
  262. if [ "${shortname}" == "core" ]; then
  263. # Download the latest serverlist. This is the complete list of all supported servers.
  264. fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
  265. if [ ! -f "${serverlist}" ]; then
  266. echo -e "[ FAIL ] serverlist.csv could not be loaded."
  267. exit 1
  268. fi
  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 -e "Install canceled"
  283. else
  284. echo -e "[ FAIL ] menu result does not match gameservername"
  285. echo -e "result: ${result}"
  286. echo -e "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 -e "[ 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}/${selfname}.cfg" ]; then
  345. fn_fetch_config "lgsm/config-default/config-lgsm" "instance-template.cfg" "${configdirserver}" "${selfname}.cfg" "nochmodx" "norun" "noforcedl" "nomd5"
  346. source "${configdirserver}/${selfname}.cfg"
  347. else
  348. source "${configdirserver}/${selfname}.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 [ -z "${travistest}" ]; 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 -e "Required status: ${requiredstatus}"
  383. counter=0
  384. echo -e "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 -e "Current status: ${currentstatus}"
  397. echo -e ""
  398. echo -e "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 -e "Test starting:"
  405. echo -e ""
  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 -e "================================="
  413. echo -e "Expected result: PASS"
  414. echo -e "Actual result: FAIL"
  415. fn_print_fail_nl "TEST FAILED"
  416. exitcode=1
  417. core_exit.sh
  418. else
  419. echo -e "================================="
  420. echo -e "Expected result: PASS"
  421. echo -e "Actual result: PASS"
  422. fn_print_ok_nl "TEST PASSED"
  423. echo -e ""
  424. fi
  425. }
  426. # if expecting a fail
  427. fn_test_result_fail(){
  428. if [ $? == 0 ]; then
  429. echo -e "================================="
  430. echo -e "Expected result: FAIL"
  431. echo -e "Actual result: PASS"
  432. fn_print_fail_nl "TEST FAILED"
  433. exitcode=1
  434. core_exit.sh
  435. else
  436. echo -e "================================="
  437. echo -e "Expected result: FAIL"
  438. echo -e "Actual result: FAIL"
  439. fn_print_ok_nl "TEST PASSED"
  440. echo -e ""
  441. fi
  442. }
  443. # test result n/a
  444. fn_test_result_na(){
  445. echo -e "================================="
  446. echo -e "Expected result: N/A"
  447. echo -e "Actual result: N/A"
  448. fn_print_fail_nl "TEST N/A"
  449. }
  450. echo -e "================================="
  451. echo -e "Travis CI Tests"
  452. echo -e "Linux Game Server Manager"
  453. echo -e "by Daniel Gibbs"
  454. echo -e "Contributors: http://goo.gl/qLmitD"
  455. echo -e "https://linuxgsm.com"
  456. echo -e "================================="
  457. echo -e ""
  458. echo -e "================================="
  459. echo -e "Server Tests"
  460. echo -e "Using: ${gamename}"
  461. echo -e "Testing Branch: $TRAVIS_BRANCH"
  462. echo -e "================================="
  463. echo -e ""
  464. echo -e "0.0 - Pre-test Tasks"
  465. echo -e "=================================================================="
  466. echo -e "Description:"
  467. echo -e "Create log dir's"
  468. echo -e ""
  469. echo -e ""
  470. echo -e "0.1 - Create log dir's"
  471. echo -e "================================="
  472. echo -e ""
  473. (
  474. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  475. BASH_XTRACEFD="5"
  476. set -x
  477. install_logs.sh
  478. )
  479. echo -e "run order"
  480. echo -e "================="
  481. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  482. echo -e ""
  483. echo -e "0.2 - Enable dev-debug"
  484. echo -e "================================="
  485. echo -e "Description:"
  486. echo -e "Enable dev-debug"
  487. echo -e ""
  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 -e "run order"
  496. echo -e "================="
  497. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  498. echo -e ""
  499. echo -e "1.0 - Pre-install tests"
  500. echo -e "=================================================================="
  501. echo -e ""
  502. echo -e "1.1 - start - no files"
  503. echo -e "================================="
  504. echo -e "Description:"
  505. echo -e "test script reaction to missing server files."
  506. echo -e "Command: ./${gameservername} start"
  507. echo -e ""
  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 -e "Test bypassed"
  519. fi
  520. echo -e "run order"
  521. echo -e "================="
  522. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  523. echo -e ""
  524. echo -e "1.2 - getopt"
  525. echo -e "================================="
  526. echo -e "Description:"
  527. echo -e "displaying options messages."
  528. echo -e "Command: ./${gameservername}"
  529. echo -e ""
  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 -e "run order"
  538. echo -e "================="
  539. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  540. echo -e ""
  541. echo -e "1.3 - getopt with incorrect args"
  542. echo -e "================================="
  543. echo -e "Description:"
  544. echo -e "displaying options messages."
  545. echo -e "Command: ./${gameservername} abc123"
  546. echo -e ""
  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 -e "run order"
  556. echo -e "================="
  557. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  558. echo -e ""
  559. echo -e "2.0 - Installation"
  560. echo -e "=================================================================="
  561. echo -e ""
  562. echo -e "2.0 - install"
  563. echo -e "================================="
  564. echo -e "Description:"
  565. echo -e "install ${gamename} server."
  566. echo -e "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 -e "run order"
  575. echo -e "================="
  576. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  577. echo -e ""
  578. echo -e "3.0 - Start/Stop/Restart Tests"
  579. echo -e "=================================================================="
  580. echo -e ""
  581. echo -e "3.1 - start"
  582. echo -e "================================="
  583. echo -e "Description:"
  584. echo -e "start ${gamename} server."
  585. echo -e "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 -e "run order"
  596. echo -e "================="
  597. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  598. echo -e ""
  599. echo -e "3.2 - start - online"
  600. echo -e "================================="
  601. echo -e "Description:"
  602. echo -e "start ${gamename} server while already running."
  603. echo -e "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 -e "run order"
  614. echo -e "================="
  615. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  616. echo -e ""
  617. echo -e "3.3 - start - updateonstart"
  618. echo -e "================================="
  619. echo -e "Description:"
  620. echo -e "will update server on start."
  621. echo -e "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 -e "run order"
  632. echo -e "================="
  633. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  634. echo -e ""
  635. echo -e "30s Pause"
  636. echo -e "================================="
  637. echo -e "Description:"
  638. echo -e "give time for server to fully start."
  639. echo -e "Command: sleep 30"
  640. requiredstatus="ONLINE"
  641. fn_setstatus
  642. sleep 30
  643. echo -e ""
  644. echo -e "3.4 - stop"
  645. echo -e "================================="
  646. echo -e "Description:"
  647. echo -e "stop ${gamename} server."
  648. echo -e "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 -e "run order"
  659. echo -e "================="
  660. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  661. echo -e ""
  662. echo -e "3.5 - stop - offline"
  663. echo -e "================================="
  664. echo -e "Description:"
  665. echo -e "stop ${gamename} server while already stopped."
  666. echo -e "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 -e "run order"
  677. echo -e "================="
  678. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  679. echo -e ""
  680. echo -e "3.6 - restart"
  681. echo -e "================================="
  682. echo -e "Description:"
  683. echo -e "restart ${gamename}."
  684. echo -e "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 -e "run order"
  695. echo -e "================="
  696. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  697. echo -e ""
  698. echo -e "3.7 - restart - offline"
  699. echo -e "================================="
  700. echo -e "Description:"
  701. echo -e "restart ${gamename} while already stopped."
  702. echo -e "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 -e "run order"
  713. echo -e "================="
  714. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  715. echo -e ""
  716. echo -e "4.0 - Update Tests"
  717. echo -e "=================================================================="
  718. echo -e ""
  719. echo -e "4.1 - update"
  720. echo -e "================================="
  721. echo -e "Description:"
  722. echo -e "check for updates."
  723. echo -e "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 -e "run order"
  734. echo -e "================="
  735. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  736. echo -e ""
  737. echo -e "Inserting IP address"
  738. echo -e "================================="
  739. echo -e "Description:"
  740. echo -e "Inserting Travis IP in to config."
  741. echo -e "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 -e "IP: ${travisip}"
  749. echo -e ""
  750. echo -e "5.0 - Monitor Tests"
  751. echo -e "=================================================================="
  752. echo -e ""
  753. echo -e "Server IP - Port: ${ip}:${port}"
  754. echo -e "Server IP - Query Port: ${ip}:${queryport}"
  755. echo -e ""
  756. echo -e "30s Pause"
  757. echo -e "================================="
  758. echo -e "Description:"
  759. echo -e "give time for server to fully start."
  760. echo -e "Command: sleep 30"
  761. requiredstatus="ONLINE"
  762. fn_setstatus
  763. sleep 30
  764. echo -e ""
  765. echo -e "5.1 - monitor - online"
  766. echo -e "================================="
  767. echo -e "Description:"
  768. echo -e "run monitor server while already running."
  769. echo -e "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 -e "run order"
  780. echo -e "================="
  781. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  782. echo -e ""
  783. echo -e "5.2 - monitor - offline - with lockfile"
  784. echo -e "================================="
  785. echo -e "Description:"
  786. echo -e "run monitor while server is offline with lockfile."
  787. echo -e "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 -e "run order"
  800. echo -e "================="
  801. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  802. echo -e ""
  803. echo -e "5.3 - monitor - offline - no lockfile"
  804. echo -e "================================="
  805. echo -e "Description:"
  806. echo -e "run monitor while server is offline with no lockfile."
  807. echo -e "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 -e "run order"
  818. echo -e "================="
  819. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  820. echo -e ""
  821. echo -e "5.4 - test-alert"
  822. echo -e "================================="
  823. echo -e "Description:"
  824. echo -e "run monitor while server is offline with no lockfile."
  825. echo -e "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 -e "run order"
  836. echo -e "================="
  837. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  838. echo -e ""
  839. echo -e "6.0 - Details Tests"
  840. echo -e "=================================================================="
  841. echo -e ""
  842. echo -e "6.1 - details"
  843. echo -e "================================="
  844. echo -e "Description:"
  845. echo -e "display details."
  846. echo -e "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 -e "run order"
  857. echo -e "================="
  858. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  859. echo -e ""
  860. echo -e "6.2 - postdetails"
  861. echo -e "================================="
  862. echo -e "Description:"
  863. echo -e "post details."
  864. echo -e "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 -e "run order"
  875. echo -e "================="
  876. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  877. echo -e ""
  878. echo -e "7.0 - Backup Tests"
  879. echo -e "=================================================================="
  880. echo -e ""
  881. echo -e "7.1 - backup"
  882. echo -e "================================="
  883. echo -e "Description:"
  884. echo -e "run a backup."
  885. echo -e "Command: ./${gameservername} backup"
  886. requiredstatus="ONLINE"
  887. fn_setstatus
  888. echo -e "test de-activated until issue #1839 fixed"
  889. #(command_backup.sh)
  890. fn_test_result_pass
  891. echo -e "run order"
  892. echo -e "================="
  893. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  894. echo -e ""
  895. echo -e "8.0 - Development Tools Tests"
  896. echo -e "=================================================================="
  897. echo -e ""
  898. echo -e "8.1 - dev - detect glibc"
  899. echo -e "================================="
  900. echo -e "Description:"
  901. echo -e "detect glibc."
  902. echo -e "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 -e "run order"
  913. echo -e "================="
  914. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  915. echo -e ""
  916. echo -e "8.2 - dev - detect ldd"
  917. echo -e "================================="
  918. echo -e "Description:"
  919. echo -e "detect ldd."
  920. echo -e "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 -e "run order"
  931. echo -e "================="
  932. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  933. echo -e ""
  934. echo -e "8.3 - dev - detect deps"
  935. echo -e "================================="
  936. echo -e "Description:"
  937. echo -e "detect dependencies."
  938. echo -e "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 -e "run order"
  949. echo -e "================="
  950. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  951. echo -e ""
  952. echo -e "Inserting IP address"
  953. echo -e "================================="
  954. echo -e "Description:"
  955. echo -e "Inserting Travis IP in to config."
  956. echo -e "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 -e "IP: ${travisip}"
  964. echo -e ""
  965. echo -e "8.4 - dev - query-raw"
  966. echo -e "================================="
  967. echo -e "Description:"
  968. echo -e "raw query output."
  969. echo -e "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 -e "run order"
  980. echo -e "================="
  981. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  982. echo -e ""
  983. echo -e "================================="
  984. echo -e "Server Tests - Complete!"
  985. echo -e "Using: ${gamename}"
  986. echo -e "================================="
  987. requiredstatus="OFFLINE"
  988. fn_setstatus
  989. fn_print_info "Tidying up directories."
  990. rm -rfv "${serverfiles}"
  991. core_exit.sh