tests_ts3server.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2017 Daniel Gibbs
  5. # Purpose: TravisCI Tests: Teamspeak 3 | Server Management Script
  6. # Contributors: https://github.com/GameServerManagers/LinuxGSM/graphs/contributors
  7. # Documentation: https://github.com/GameServerManagers/LinuxGSM/wiki
  8. # Website: https://gameservermanagers.com
  9. # Debugging
  10. if [ -f ".dev-debug" ]; then
  11. exec 5>dev-debug.log
  12. BASH_XTRACEFD="5"
  13. set -x
  14. fi
  15. version="170501"
  16. ##########################
  17. ######## Settings ########
  18. ##########################
  19. ## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
  20. # Edit serverfiles/ts3-server.ini after installation
  21. #### LinuxGSM Settings ####
  22. ## Notification Alerts
  23. # (on|off)
  24. # Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
  25. emailalert="off"
  26. email="email@example.com"
  27. emailfrom=""
  28. # Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
  29. pushbulletalert="off"
  30. pushbullettoken="accesstoken"
  31. channeltag=""
  32. ## Updating | https://github.com/GameServerManagers/LinuxGSM/wiki/Update
  33. updateonstart="off"
  34. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  35. maxbackups="4"
  36. maxbackupdays="30"
  37. stoponbackup="on"
  38. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  39. consolelogging="on"
  40. logdays="7"
  41. #### LinuxGSM Advanced Settings ####
  42. ## Github Branch Select
  43. # Allows for the use of different function files
  44. # from a different repo and/or branch.
  45. githubuser="GameServerManagers"
  46. githubrepo="LinuxGSM"
  47. githubbranch="$TRAVIS_BRANCH"
  48. ## LinuxGSM Server Details
  49. # Do not edit
  50. gamename="TeamSpeak 3"
  51. servername="TeamSpeak 3 Server"
  52. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  53. servicename="ts3-server"
  54. #### Directories ####
  55. # Edit with care
  56. ## Server Specific Directories
  57. systemdir="${serverfiles}"
  58. executabledir="${serverfiles}"
  59. executable="./ts3server_startscript.sh"
  60. servercfg="${servicename}.ini"
  61. servercfgdefault="ts3server.ini"
  62. servercfgdir="${serverfiles}"
  63. servercfgfullpath="${servercfgdir}/${servercfg}"
  64. ## Backup Directory
  65. backupdir="${rootdir}/backups"
  66. ## Logging Directories
  67. gamelogdir="${serverfiles}/logs"
  68. lgsmlogdir="${rootdir}/log/script"
  69. lgsmlog="${lgsmlogdir}/${servicename}-script.log"
  70. emaillog="${lgsmlogdir}/${servicename}-email.log"
  71. ## Logs Naming
  72. lgsmlogdate="${lgsmlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  73. ########################
  74. ######## Script ########
  75. ###### Do not edit #####
  76. ########################
  77. # Fetches core_dl for file downloads
  78. fn_fetch_core_dl(){
  79. github_file_url_dir="lgsm/functions"
  80. github_file_url_name="${functionfile}"
  81. filedir="${functionsdir}"
  82. filename="${github_file_url_name}"
  83. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  84. # If the file is missing, then download
  85. if [ ! -f "${filedir}/${filename}" ]; then
  86. if [ ! -d "${filedir}" ]; then
  87. mkdir -p "${filedir}"
  88. fi
  89. echo -e " fetching ${filename}...\c"
  90. # Check curl exists and use available path
  91. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  92. for curlcmd in ${curlpaths}
  93. do
  94. if [ -x "${curlcmd}" ]; then
  95. break
  96. fi
  97. done
  98. # If curl exists download file
  99. if [ "$(basename ${curlcmd})" == "curl" ]; then
  100. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  101. if [ $? -ne 0 ]; then
  102. echo -e "\e[0;31mFAIL\e[0m\n"
  103. echo "${curlfetch}"
  104. echo -e "${githuburl}\n"
  105. exit 1
  106. else
  107. echo -e "\e[0;32mOK\e[0m"
  108. fi
  109. else
  110. echo -e "\e[0;31mFAIL\e[0m\n"
  111. echo "Curl is not installed!"
  112. echo -e ""
  113. exit 1
  114. fi
  115. chmod +x "${filedir}/${filename}"
  116. fi
  117. source "${filedir}/${filename}"
  118. }
  119. core_dl.sh(){
  120. # Functions are defined in core_functions.sh.
  121. functionfile="${FUNCNAME}"
  122. fn_fetch_core_dl
  123. }
  124. core_functions.sh(){
  125. # Functions are defined in core_functions.sh.
  126. functionfile="${FUNCNAME}"
  127. fn_fetch_core_dl
  128. }
  129. core_dl.sh
  130. core_functions.sh
  131. fn_currentstatus_tmux(){
  132. check_status.sh
  133. if [ "${status}" != "0" ]; then
  134. currentstatus="ONLINE"
  135. else
  136. currentstatus="OFFLINE"
  137. fi
  138. }
  139. fn_currentstatus_ts3(){
  140. check_status.sh
  141. if [ "${status}" != "0" ]; then
  142. currentstatus="ONLINE"
  143. else
  144. currentstatus="OFFLINE"
  145. fi
  146. }
  147. fn_setstatus(){
  148. fn_currentstatus_ts3
  149. echo""
  150. echo "Required status: ${requiredstatus}"
  151. counter=0
  152. echo "Current status: ${currentstatus}"
  153. while [ "${requiredstatus}" != "${currentstatus}" ]; do
  154. counter=$((counter+1))
  155. fn_currentstatus_ts3
  156. echo -ne "New status: ${currentstatus}\\r"
  157. if [ "${requiredstatus}" == "ONLINE" ]; then
  158. (command_start.sh > /dev/null 2>&1)
  159. else
  160. (command_stop.sh > /dev/null 2>&1)
  161. fi
  162. if [ "${counter}" -gt "5" ]; then
  163. currentstatus="FAIL"
  164. echo "Current status: ${currentstatus}"
  165. echo ""
  166. echo "Unable to start or stop server."
  167. exit 1
  168. fi
  169. done
  170. echo -ne "New status: ${currentstatus}\\r"
  171. echo -e "\n"
  172. echo "Test starting:"
  173. echo ""
  174. sleep 0.5
  175. }
  176. # End of every test will expect the result to either pass or fail
  177. # If the script does not do as intended the whole test will fail
  178. # if excpecting a pass
  179. fn_test_result_pass(){
  180. if [ $? != 0 ]; then
  181. echo "================================="
  182. echo "Expected result: PASS"
  183. echo "Actual result: FAIL"
  184. fn_print_fail_nl "TEST FAILED"
  185. exitcode=1
  186. core_exit.sh
  187. else
  188. echo "================================="
  189. echo "Expected result: PASS"
  190. echo "Actual result: PASS"
  191. fn_print_ok_nl "TEST PASSED"
  192. echo ""
  193. fi
  194. }
  195. # if excpecting a fail
  196. fn_test_result_fail(){
  197. if [ $? == 0 ]; then
  198. echo "================================="
  199. echo "Expected result: FAIL"
  200. echo "Actual result: PASS"
  201. fn_print_fail_nl "TEST FAILED"
  202. exitcode=1
  203. core_exit.sh
  204. else
  205. echo "================================="
  206. echo "Expected result: FAIL"
  207. echo "Actual result: FAIL"
  208. fn_print_ok_nl "TEST PASSED"
  209. echo ""
  210. fi
  211. }
  212. echo "================================="
  213. echo "TravisCI Tests"
  214. echo "Linux Game Server Manager"
  215. echo "by Daniel Gibbs"
  216. echo "https://gameservermanagers.com"
  217. echo "================================="
  218. echo ""
  219. echo "================================="
  220. echo "Server Tests"
  221. echo "Using: ${gamename}"
  222. echo "Testing Branch: $TRAVIS_BRANCH"
  223. echo "================================="
  224. echo ""
  225. echo "0.1 - Create log dir's"
  226. echo "================================="
  227. echo "Description:"
  228. echo "Create log dir's"
  229. echo ""
  230. (install_logs.sh)
  231. echo "0.2 - Enable dev-debug"
  232. echo "================================="
  233. echo "Description:"
  234. echo "Enable dev-debug"
  235. echo ""
  236. (command_dev_debug.sh)
  237. fn_test_result_pass
  238. echo "1.0 - start - no files"
  239. echo "================================="
  240. echo "Description:"
  241. echo "test script reaction to missing server files."
  242. echo "Command: ./ts3server start"
  243. echo ""
  244. (command_start.sh)
  245. fn_test_result_fail
  246. echo ""
  247. echo "1.1 - getopt"
  248. echo "================================="
  249. echo "Description:"
  250. echo "displaying options messages."
  251. echo "Command: ./ts3server"
  252. echo ""
  253. (core_getopt.sh)
  254. fn_test_result_pass
  255. echo ""
  256. echo "1.2 - getopt with incorrect args"
  257. echo "================================="
  258. echo "Description:"
  259. echo "displaying options messages."
  260. echo "Command: ./ts3server abc123"
  261. echo ""
  262. getopt="abc123"
  263. (core_getopt.sh)
  264. fn_test_result_fail
  265. echo ""
  266. echo "2.0 - install"
  267. echo "================================="
  268. echo "Description:"
  269. echo "install ${gamename} server."
  270. echo "Command: ./ts3server auto-install"
  271. (fn_autoinstall)
  272. fn_test_result_pass
  273. echo ""
  274. echo "3.1 - start"
  275. echo "================================="
  276. echo "Description:"
  277. echo "start ${gamename} server."
  278. echo "Command: ./ts3server start"
  279. requiredstatus="OFFLINE"
  280. fn_setstatus
  281. (command_start.sh)
  282. fn_test_result_pass
  283. echo ""
  284. echo "3.2 - start - online"
  285. echo "================================="
  286. echo "Description:"
  287. echo "start ${gamename} server while already running."
  288. echo "Command: ./ts3server start"
  289. requiredstatus="ONLINE"
  290. fn_setstatus
  291. (command_start.sh)
  292. fn_test_result_fail
  293. echo ""
  294. echo "3.3 - start - updateonstart"
  295. echo "================================="
  296. echo "Description:"
  297. echo "will update server on start."
  298. echo "Command: ./ts3server start"
  299. requiredstatus="OFFLINE"
  300. fn_setstatus
  301. (updateonstart="on";command_start.sh)
  302. fn_test_result_pass
  303. echo ""
  304. echo "3.4 - stop"
  305. echo "================================="
  306. echo "Description:"
  307. echo "stop ${gamename} server."
  308. echo "Command: ./ts3server stop"
  309. requiredstatus="ONLINE"
  310. fn_setstatus
  311. (command_stop.sh)
  312. fn_test_result_pass
  313. echo ""
  314. echo "3.5 - stop - offline"
  315. echo "================================="
  316. echo "Description:"
  317. echo "stop ${gamename} server while already stopped."
  318. echo "Command: ./ts3server stop"
  319. requiredstatus="OFFLINE"
  320. fn_setstatus
  321. (command_stop.sh)
  322. fn_test_result_fail
  323. echo ""
  324. echo "3.6 - restart"
  325. echo "================================="
  326. echo "Description:"
  327. echo "restart ${gamename}."
  328. echo "Command: ./ts3server restart"
  329. requiredstatus="ONLINE"
  330. fn_setstatus
  331. (command_restart.sh)
  332. fn_test_result_pass
  333. echo ""
  334. echo "3.7 - restart - offline"
  335. echo "================================="
  336. echo "Description:"
  337. echo "restart ${gamename} while already stopped."
  338. echo "Command: ./ts3server restart"
  339. requiredstatus="OFFLINE"
  340. fn_setstatus
  341. (command_restart.sh)
  342. fn_test_result_pass
  343. echo ""
  344. echo "4.1 - update"
  345. echo "================================="
  346. echo "Description:"
  347. echo "check for updates."
  348. echo "Command: ./jc2server update"
  349. requiredstatus="OFFLINE"
  350. fn_setstatus
  351. (command_update.sh)
  352. fn_test_result_pass
  353. echo ""
  354. echo "4.2 - update-functions"
  355. echo "================================="
  356. echo "Description:"
  357. echo "runs update-functions."
  358. echo ""
  359. echo "Command: ./jc2server update-functions"
  360. requiredstatus="OFFLINE"
  361. fn_setstatus
  362. (command_update_functions.sh)
  363. fn_test_result_pass
  364. echo ""
  365. echo "5.1 - monitor - online"
  366. echo "================================="
  367. echo "Description:"
  368. echo "run monitor server while already running."
  369. echo "Command: ./ts3server monitor"
  370. requiredstatus="ONLINE"
  371. fn_setstatus
  372. (command_monitor.sh)
  373. fn_test_result_pass
  374. echo ""
  375. echo "5.2 - monitor - offline - with lockfile"
  376. echo "================================="
  377. echo "Description:"
  378. echo "run monitor while server is offline with lockfile."
  379. echo "Command: ./ts3server monitor"
  380. requiredstatus="OFFLINE"
  381. fn_setstatus
  382. fn_print_info_nl "creating lockfile."
  383. date > "${rootdir}/${lockselfname}"
  384. (command_monitor.sh)
  385. fn_test_result_pass
  386. echo ""
  387. echo "5.3 - monitor - offline - no lockfile"
  388. echo "================================="
  389. echo "Description:"
  390. echo "run monitor while server is offline with no lockfile."
  391. echo "Command: ./ts3server monitor"
  392. requiredstatus="OFFLINE"
  393. fn_setstatus
  394. (command_monitor.sh)
  395. fn_test_result_fail
  396. echo ""
  397. echo "6.0 - details"
  398. echo "================================="
  399. echo "Description:"
  400. echo "display details."
  401. echo "Command: ./ts3server details"
  402. requiredstatus="ONLINE"
  403. fn_setstatus
  404. (command_details.sh)
  405. fn_test_result_pass
  406. echo ""
  407. echo "================================="
  408. echo "Server Tests - Complete!"
  409. echo "Using: ${gamename}"
  410. echo "================================="
  411. requiredstatus="OFFLINE"
  412. fn_setstatus
  413. sleep 1
  414. fn_print_info "Tidying up directories."
  415. sleep 1
  416. rm -rfv "${serverfiles}"
  417. core_exit.sh