tests_jc2server.sh 30 KB

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