tests_jc2server.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/bash
  2. # TravisCI Tests
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: https://gameservermanagers.com
  6. version="101716"
  7. #### Advanced Variables ####
  8. # Github Branch Select
  9. # Allows for the use of different function files
  10. # from a different repo and/or branch.
  11. githubuser="dgibbs64"
  12. githubrepo="linuxgsm"
  13. githubbranch="$TRAVIS_BRANCH"
  14. ##### Script #####
  15. # Directories
  16. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  17. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  18. lockselfname=".${servicename}.lock"
  19. lgsmdir="${rootdir}/lgsm"
  20. functionsdir="${lgsmdir}/functions"
  21. libdir="${lgsmdir}/lib"
  22. filesdir="${rootdir}/serverfiles"
  23. systemdir="${filesdir}"
  24. executabledir="${filesdir}"
  25. executable="./Jcmp-Server"
  26. servercfg="config.lua"
  27. servercfgdir="${filesdir}"
  28. servercfgfullpath="${servercfgdir}/${servercfg}"
  29. servercfgdefault="${servercfgdir}/default_config.lua"
  30. backupdir="${rootdir}/backups"
  31. # Fetches core_dl for file downloads
  32. fn_fetch_core_dl(){
  33. github_file_url_dir="lgsm/functions"
  34. github_file_url_name="${functionfile}"
  35. filedir="${functionsdir}"
  36. filename="${github_file_url_name}"
  37. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  38. # If the file is missing, then download
  39. if [ ! -f "${filedir}/${filename}" ]; then
  40. if [ ! -d "${filedir}" ]; then
  41. mkdir -p "${filedir}"
  42. fi
  43. echo -e " fetching ${filename}...\c"
  44. # Check curl exists and use available path
  45. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  46. for curlcmd in ${curlpaths}
  47. do
  48. if [ -x "${curlcmd}" ]; then
  49. break
  50. fi
  51. done
  52. # If curl exists download file
  53. if [ "$(basename ${curlcmd})" == "curl" ]; then
  54. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  55. if [ $? -ne 0 ]; then
  56. echo -e "\e[0;31mFAIL\e[0m\n"
  57. echo "${curlfetch}"
  58. echo -e "${githuburl}\n"
  59. exit 1
  60. else
  61. echo -e "\e[0;32mOK\e[0m"
  62. fi
  63. else
  64. echo -e "\e[0;31mFAIL\e[0m\n"
  65. echo "Curl is not installed!"
  66. echo -e ""
  67. exit 1
  68. fi
  69. chmod +x "${filedir}/${filename}"
  70. fi
  71. source "${filedir}/${filename}"
  72. }
  73. core_dl.sh(){
  74. # Functions are defined in core_functions.sh.
  75. functionfile="${FUNCNAME}"
  76. fn_fetch_core_dl
  77. }
  78. core_functions.sh(){
  79. # Functions are defined in core_functions.sh.
  80. functionfile="${FUNCNAME}"
  81. fn_fetch_core_dl
  82. }
  83. core_dl.sh
  84. core_functions.sh
  85. # End of every test will expect the result to either pass or fail
  86. # If the script does not do as intended the whole test will fail
  87. # if excpecting a pass
  88. fn_test_result_pass(){
  89. if [ $? != 0 ]; then
  90. fn_print_fail "Test Failed"
  91. exitcode=1
  92. core_exit.sh
  93. else
  94. fn_print_ok "Test Passed"
  95. fi
  96. }
  97. # if excpecting a fail
  98. fn_test_result_fail(){
  99. if [ $? == 0 ]; then
  100. fn_print_fail "Test Failed"
  101. exitcode=1
  102. core_exit.sh
  103. else
  104. fn_print_ok "Test Passed"
  105. fi
  106. }
  107. echo "================================="
  108. echo "TravisCI Tests"
  109. echo "Linux Game Server Manager"
  110. echo "by Daniel Gibbs"
  111. echo "https://gameservermanagers.com"
  112. echo "================================="
  113. echo ""
  114. echo "================================="
  115. echo "Server Tests"
  116. echo "Using: ${gamename}"
  117. echo "Testing Branch: $TRAVIS_BRANCH"
  118. echo "================================="
  119. echo ""
  120. echo "0.0 - Preparing Enviroment"
  121. echo "================================="
  122. echo "Description:"
  123. echo "Preparing Enviroment to run tests"
  124. echo "Downloading jc2server"
  125. wget https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/JustCause2/jc2server
  126. chmod +x jc2server
  127. echo "Create log dir"
  128. mkdir -pv log/script/
  129. echo "Enable dev-debug"
  130. ./jc2server dev-debug
  131. echo "1.0 - start - no files"
  132. echo "================================="
  133. echo "Description:"
  134. echo "test script reaction to missing server files."
  135. echo ""
  136. ./jc2server start
  137. fn_test_result_fail
  138. echo ""
  139. echo "1.1 - getopt"
  140. echo "================================="
  141. echo "Description:"
  142. echo "displaying options messages."
  143. echo ""
  144. ./jc2server
  145. fn_test_result_pass
  146. echo ""
  147. echo "1.2 - getopt with incorrect args"
  148. echo "================================="
  149. echo "Description:"
  150. echo "displaying options messages."
  151. echo ""
  152. ./jc2server abc123
  153. fn_test_result_fail
  154. echo "2.0 - install"
  155. echo "================================="
  156. echo "Description:"
  157. echo "install Just Cause 2 server."
  158. ./jc2server auto-install
  159. fn_test_result_pass