tests_fctrserver.sh 32 KB

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