4
0

tests_ts3server.sh 11 KB

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