tests_mcserver.sh 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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 [ "$(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 [ "$(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. sleeptime="0"
  449. echo -e "================================="
  450. echo -e "Travis CI Tests"
  451. echo -e "Linux Game Server Manager"
  452. echo -e "by Daniel Gibbs"
  453. echo -e "Contributors: http://goo.gl/qLmitD"
  454. echo -e "https://linuxgsm.com"
  455. echo -e "================================="
  456. echo -e ""
  457. echo -e "================================="
  458. echo -e "Server Tests"
  459. echo -e "Using: ${gamename}"
  460. echo -e "Testing Branch: $TRAVIS_BRANCH"
  461. echo -e "================================="
  462. echo -e ""
  463. echo -e "0.0 - Pre-test Tasks"
  464. echo -e "=================================================================="
  465. echo -e "Description:"
  466. echo -e "Create log dir's"
  467. echo -e ""
  468. echo -e ""
  469. echo -e "0.1 - Create log dir's"
  470. echo -e "================================="
  471. echo -e ""
  472. (
  473. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  474. BASH_XTRACEFD="5"
  475. set -x
  476. install_logs.sh
  477. )
  478. echo -e "run order"
  479. echo -e "================="
  480. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  481. echo -e ""
  482. echo -e "0.2 - Enable dev-debug"
  483. echo -e "================================="
  484. echo -e "Description:"
  485. echo -e "Enable dev-debug"
  486. echo -e ""
  487. (
  488. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  489. BASH_XTRACEFD="5"
  490. set -x
  491. command_dev_debug.sh
  492. )
  493. fn_test_result_pass
  494. echo -e "run order"
  495. echo -e "================="
  496. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  497. echo -e ""
  498. echo -e "1.0 - Pre-install tests"
  499. echo -e "=================================================================="
  500. echo -e ""
  501. echo -e "1.1 - start - no files"
  502. echo -e "================================="
  503. echo -e "Description:"
  504. echo -e "test script reaction to missing server files."
  505. echo -e "Command: ./${gameservername} start"
  506. echo -e ""
  507. # Allows for testing not on Travis CI
  508. if [ ! -v TRAVIS ]; then
  509. (
  510. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  511. BASH_XTRACEFD="5"
  512. set -x
  513. command_start.sh
  514. )
  515. fn_test_result_fail
  516. else
  517. echo -e "Test bypassed"
  518. fi
  519. echo -e "run order"
  520. echo -e "================="
  521. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  522. echo -e ""
  523. echo -e "1.2 - getopt"
  524. echo -e "================================="
  525. echo -e "Description:"
  526. echo -e "displaying options messages."
  527. echo -e "Command: ./${gameservername}"
  528. echo -e ""
  529. (
  530. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  531. BASH_XTRACEFD="5"
  532. set -x
  533. core_getopt.sh
  534. )
  535. fn_test_result_pass
  536. echo -e "run order"
  537. echo -e "================="
  538. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  539. echo -e ""
  540. echo -e "1.3 - getopt with incorrect args"
  541. echo -e "================================="
  542. echo -e "Description:"
  543. echo -e "displaying options messages."
  544. echo -e "Command: ./${gameservername} abc123"
  545. echo -e ""
  546. getopt="abc123"
  547. (
  548. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  549. BASH_XTRACEFD="5"
  550. set -x
  551. core_getopt.sh
  552. )
  553. fn_test_result_fail
  554. echo -e "run order"
  555. echo -e "================="
  556. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  557. echo -e ""
  558. echo -e "2.0 - Installation"
  559. echo -e "=================================================================="
  560. echo -e ""
  561. echo -e "2.0 - install"
  562. echo -e "================================="
  563. echo -e "Description:"
  564. echo -e "install ${gamename} server."
  565. echo -e "Command: ./${gameservername} auto-install"
  566. (
  567. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  568. BASH_XTRACEFD="5"
  569. set -x
  570. fn_autoinstall
  571. )
  572. fn_test_result_pass
  573. echo -e "run order"
  574. echo -e "================="
  575. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  576. echo -e ""
  577. echo -e "3.0 - Start/Stop/Restart Tests"
  578. echo -e "=================================================================="
  579. echo -e ""
  580. echo -e "3.1 - start"
  581. echo -e "================================="
  582. echo -e "Description:"
  583. echo -e "start ${gamename} server."
  584. echo -e "Command: ./${gameservername} start"
  585. requiredstatus="OFFLINE"
  586. fn_setstatus
  587. (
  588. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  589. BASH_XTRACEFD="5"
  590. set -x
  591. command_start.sh
  592. )
  593. fn_test_result_pass
  594. echo -e "run order"
  595. echo -e "================="
  596. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  597. echo -e ""
  598. echo -e "3.2 - start - online"
  599. echo -e "================================="
  600. echo -e "Description:"
  601. echo -e "start ${gamename} server while already running."
  602. echo -e "Command: ./${gameservername} start"
  603. requiredstatus="ONLINE"
  604. fn_setstatus
  605. (
  606. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  607. BASH_XTRACEFD="5"
  608. set -x
  609. command_start.sh
  610. )
  611. fn_test_result_fail
  612. echo -e "run order"
  613. echo -e "================="
  614. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  615. echo -e ""
  616. echo -e "3.3 - start - updateonstart"
  617. echo -e "================================="
  618. echo -e "Description:"
  619. echo -e "will update server on start."
  620. echo -e "Command: ./${gameservername} start"
  621. requiredstatus="OFFLINE"
  622. fn_setstatus
  623. (
  624. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  625. BASH_XTRACEFD="5"
  626. set -x
  627. updateonstart="on";command_start.sh
  628. )
  629. fn_test_result_pass
  630. echo -e "run order"
  631. echo -e "================="
  632. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  633. echo -e ""
  634. echo -e "30s Pause"
  635. echo -e "================================="
  636. echo -e "Description:"
  637. echo -e "give time for server to fully start."
  638. echo -e "Command: sleep 30"
  639. requiredstatus="ONLINE"
  640. fn_setstatus
  641. sleep 30
  642. echo -e ""
  643. echo -e "3.4 - stop"
  644. echo -e "================================="
  645. echo -e "Description:"
  646. echo -e "stop ${gamename} server."
  647. echo -e "Command: ./${gameservername} stop"
  648. requiredstatus="ONLINE"
  649. fn_setstatus
  650. (
  651. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  652. BASH_XTRACEFD="5"
  653. set -x
  654. command_stop.sh
  655. )
  656. fn_test_result_pass
  657. echo -e "run order"
  658. echo -e "================="
  659. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  660. echo -e ""
  661. echo -e "3.5 - stop - offline"
  662. echo -e "================================="
  663. echo -e "Description:"
  664. echo -e "stop ${gamename} server while already stopped."
  665. echo -e "Command: ./${gameservername} stop"
  666. requiredstatus="OFFLINE"
  667. fn_setstatus
  668. (
  669. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  670. BASH_XTRACEFD="5"
  671. set -x
  672. command_stop.sh
  673. )
  674. fn_test_result_fail
  675. echo -e "run order"
  676. echo -e "================="
  677. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  678. echo -e ""
  679. echo -e "3.6 - restart"
  680. echo -e "================================="
  681. echo -e "Description:"
  682. echo -e "restart ${gamename}."
  683. echo -e "Command: ./${gameservername} restart"
  684. requiredstatus="ONLINE"
  685. fn_setstatus
  686. (
  687. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  688. BASH_XTRACEFD="5"
  689. set -x
  690. command_restart.sh
  691. )
  692. fn_test_result_pass
  693. echo -e "run order"
  694. echo -e "================="
  695. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  696. echo -e ""
  697. echo -e "3.7 - restart - offline"
  698. echo -e "================================="
  699. echo -e "Description:"
  700. echo -e "restart ${gamename} while already stopped."
  701. echo -e "Command: ./${gameservername} restart"
  702. requiredstatus="OFFLINE"
  703. fn_setstatus
  704. (
  705. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  706. BASH_XTRACEFD="5"
  707. set -x
  708. command_restart.sh
  709. )
  710. fn_test_result_pass
  711. echo -e "run order"
  712. echo -e "================="
  713. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  714. echo -e ""
  715. echo -e "4.0 - Update Tests"
  716. echo -e "=================================================================="
  717. echo -e ""
  718. echo -e "4.1 - update"
  719. echo -e "================================="
  720. echo -e "Description:"
  721. echo -e "check for updates."
  722. echo -e "Command: ./${gameservername} update"
  723. requiredstatus="OFFLINE"
  724. fn_setstatus
  725. (
  726. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  727. BASH_XTRACEFD="5"
  728. set -x
  729. command_update.sh
  730. )
  731. fn_test_result_pass
  732. echo -e "run order"
  733. echo -e "================="
  734. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  735. echo -e ""
  736. echo -e "Inserting IP address"
  737. echo -e "================================="
  738. echo -e "Description:"
  739. echo -e "Inserting Travis IP in to config."
  740. echo -e "Allows monitor to work"
  741. if [ "$(ip -o -4 addr|grep eth0)" ]; then
  742. travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
  743. else
  744. travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
  745. fi
  746. sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
  747. echo -e "IP: ${travisip}"
  748. echo -e ""
  749. echo -e "5.0 - Monitor Tests"
  750. echo -e "=================================================================="
  751. echo -e ""
  752. echo -e "Server IP - Port: ${ip}:${port}"
  753. echo -e "Server IP - Query Port: ${ip}:${queryport}"
  754. echo -e ""
  755. echo -e "30s Pause"
  756. echo -e "================================="
  757. echo -e "Description:"
  758. echo -e "give time for server to fully start."
  759. echo -e "Command: sleep 30"
  760. requiredstatus="ONLINE"
  761. fn_setstatus
  762. sleep 30
  763. echo -e ""
  764. echo -e "5.1 - monitor - online"
  765. echo -e "================================="
  766. echo -e "Description:"
  767. echo -e "run monitor server while already running."
  768. echo -e "Command: ./${gameservername} monitor"
  769. requiredstatus="ONLINE"
  770. fn_setstatus
  771. (
  772. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  773. BASH_XTRACEFD="5"
  774. set -x
  775. command_monitor.sh
  776. )
  777. fn_test_result_pass
  778. echo -e "run order"
  779. echo -e "================="
  780. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  781. echo -e ""
  782. echo -e "5.2 - monitor - offline - with lockfile"
  783. echo -e "================================="
  784. echo -e "Description:"
  785. echo -e "run monitor while server is offline with lockfile."
  786. echo -e "Command: ./${gameservername} monitor"
  787. requiredstatus="OFFLINE"
  788. fn_setstatus
  789. fn_print_info_nl "creating lockfile."
  790. date '+%s' > "${rootdir}/${lockselfname}"
  791. (
  792. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  793. BASH_XTRACEFD="5"
  794. set -x
  795. command_monitor.sh
  796. )
  797. fn_test_result_pass
  798. echo -e "run order"
  799. echo -e "================="
  800. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  801. echo -e ""
  802. echo -e "5.3 - monitor - offline - no lockfile"
  803. echo -e "================================="
  804. echo -e "Description:"
  805. echo -e "run monitor while server is offline with no lockfile."
  806. echo -e "Command: ./${gameservername} monitor"
  807. requiredstatus="OFFLINE"
  808. fn_setstatus
  809. (
  810. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  811. BASH_XTRACEFD="5"
  812. set -x
  813. command_monitor.sh
  814. )
  815. fn_test_result_fail
  816. echo -e "run order"
  817. echo -e "================="
  818. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  819. echo -e ""
  820. echo -e "5.4 - test-alert"
  821. echo -e "================================="
  822. echo -e "Description:"
  823. echo -e "run monitor while server is offline with no lockfile."
  824. echo -e "Command: ./${gameservername} test-alert"
  825. requiredstatus="OFFLINE"
  826. fn_setstatus
  827. (
  828. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  829. BASH_XTRACEFD="5"
  830. set -x
  831. command_test_alert.sh
  832. )
  833. fn_test_result_fail
  834. echo -e "run order"
  835. echo -e "================="
  836. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  837. echo -e ""
  838. echo -e "6.0 - Details Tests"
  839. echo -e "=================================================================="
  840. echo -e ""
  841. echo -e "6.1 - details"
  842. echo -e "================================="
  843. echo -e "Description:"
  844. echo -e "display details."
  845. echo -e "Command: ./${gameservername} details"
  846. requiredstatus="ONLINE"
  847. fn_setstatus
  848. (
  849. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  850. BASH_XTRACEFD="5"
  851. set -x
  852. command_details.sh
  853. )
  854. fn_test_result_pass
  855. echo -e "run order"
  856. echo -e "================="
  857. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  858. echo -e ""
  859. echo -e "6.2 - postdetails"
  860. echo -e "================================="
  861. echo -e "Description:"
  862. echo -e "post details."
  863. echo -e "Command: ./${gameservername} postdetails"
  864. requiredstatus="ONLINE"
  865. fn_setstatus
  866. (
  867. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  868. BASH_XTRACEFD="5"
  869. set -x
  870. command_postdetails.sh
  871. )
  872. fn_test_result_pass
  873. echo -e "run order"
  874. echo -e "================="
  875. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  876. echo -e ""
  877. echo -e "7.0 - Backup Tests"
  878. echo -e "=================================================================="
  879. echo -e ""
  880. echo -e "7.1 - backup"
  881. echo -e "================================="
  882. echo -e "Description:"
  883. echo -e "run a backup."
  884. echo -e "Command: ./${gameservername} backup"
  885. requiredstatus="ONLINE"
  886. fn_setstatus
  887. echo -e "test de-activated until issue #1839 fixed"
  888. #(command_backup.sh)
  889. fn_test_result_pass
  890. echo -e "run order"
  891. echo -e "================="
  892. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  893. echo -e ""
  894. echo -e "8.0 - Development Tools Tests"
  895. echo -e "=================================================================="
  896. echo -e ""
  897. echo -e "8.1 - dev - detect glibc"
  898. echo -e "================================="
  899. echo -e "Description:"
  900. echo -e "detect glibc."
  901. echo -e "Command: ./${gameservername} detect-glibc"
  902. requiredstatus="ONLINE"
  903. fn_setstatus
  904. (
  905. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  906. BASH_XTRACEFD="5"
  907. set -x
  908. command_dev_detect_glibc.sh
  909. )
  910. fn_test_result_pass
  911. echo -e "run order"
  912. echo -e "================="
  913. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  914. echo -e ""
  915. echo -e "8.2 - dev - detect ldd"
  916. echo -e "================================="
  917. echo -e "Description:"
  918. echo -e "detect ldd."
  919. echo -e "Command: ./${gameservername} detect-ldd"
  920. requiredstatus="ONLINE"
  921. fn_setstatus
  922. (
  923. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  924. BASH_XTRACEFD="5"
  925. set -x
  926. command_dev_detect_ldd.sh
  927. )
  928. fn_test_result_pass
  929. echo -e "run order"
  930. echo -e "================="
  931. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  932. echo -e ""
  933. echo -e "8.3 - dev - detect deps"
  934. echo -e "================================="
  935. echo -e "Description:"
  936. echo -e "detect dependencies."
  937. echo -e "Command: ./${gameservername} detect-deps"
  938. requiredstatus="ONLINE"
  939. fn_setstatus
  940. (
  941. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  942. BASH_XTRACEFD="5"
  943. set -x
  944. command_dev_detect_deps.sh
  945. )
  946. fn_test_result_pass
  947. echo -e "run order"
  948. echo -e "================="
  949. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  950. echo -e ""
  951. echo -e "Inserting IP address"
  952. echo -e "================================="
  953. echo -e "Description:"
  954. echo -e "Inserting Travis IP in to config."
  955. echo -e "Allows monitor to work"
  956. if [ "$(ip -o -4 addr|grep eth0)" ]; then
  957. travisip=$(ip -o -4 addr | grep eth0 | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | grep -v 127.0.0)
  958. else
  959. travisip=$(ip -o -4 addr | grep ens | awk '{print $4}' | grep -oe '\([0-9]\{1,3\}\.\?\)\{4\}' | sort -u | grep -v 127.0.0)
  960. fi
  961. sed -i "/server-ip=/c\server-ip=${travisip}" "${serverfiles}/server.properties"
  962. echo -e "IP: ${travisip}"
  963. echo -e ""
  964. echo -e "8.4 - dev - query-raw"
  965. echo -e "================================="
  966. echo -e "Description:"
  967. echo -e "raw query output."
  968. echo -e "Command: ./${gameservername} query-raw"
  969. requiredstatus="ONLINE"
  970. fn_setstatus
  971. (
  972. exec 5>"${TRAVIS_BUILD_DIR}/dev-debug.log"
  973. BASH_XTRACEFD="5"
  974. set -x
  975. command_dev_query_raw.sh
  976. )
  977. fn_test_result_na
  978. echo -e "run order"
  979. echo -e "================="
  980. grep functionfile= "${TRAVIS_BUILD_DIR}/dev-debug.log" | sed 's/functionfile=//g'
  981. echo -e ""
  982. echo -e "================================="
  983. echo -e "Server Tests - Complete!"
  984. echo -e "Using: ${gamename}"
  985. echo -e "================================="
  986. requiredstatus="OFFLINE"
  987. fn_setstatus
  988. if [ ! -v TRAVIS ]; then
  989. fn_print_info "Tidying up directories."
  990. rm -rfv "${serverfiles}"
  991. fi
  992. core_exit.sh