tests_mcserver.sh 31 KB

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