4
0

tests_ts3server.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #!/bin/bash
  2. # TravisCI Tests
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: https://gameservermanagers.com
  6. version="071115"
  7. #### Variables ####
  8. # Alert Email
  9. # (on|off)
  10. emailalert="off"
  11. email=""
  12. # Start Variables
  13. updateonstart="off"
  14. # Server Details
  15. gamename="Teamspeak 3"
  16. servername="Teamspeak 3 Server"
  17. servicename="ts3-server"
  18. # Directories
  19. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  20. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  21. lockselfname=".${servicename}.lock"
  22. filesdir="${rootdir}/serverfiles"
  23. systemdir="${filesdir}"
  24. executabledir="${filesdir}"
  25. executable="./ts3server_startscript.sh"
  26. servercfg="${servicename}.ini"
  27. servercfgdir="${filesdir}"
  28. servercfgfullpath="${servercfgdir}/${servercfg}"
  29. servercfgdefault="${servercfgdir}/lgsm-default.ini"
  30. backupdir="${rootdir}/backups"
  31. # Logging
  32. logdays="7"
  33. gamelogdir="${filesdir}/logs"
  34. scriptlogdir="${rootdir}/log/script"
  35. scriptlog="${scriptlogdir}/${servicename}-script.log"
  36. emaillog="${scriptlogdir}/${servicename}-email.log"
  37. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  38. #### Advanced Variables ####
  39. # Github Branch Select
  40. # Allows for the use of different function files
  41. # from a different repo and/or branch.
  42. githubuser="dgibbs64"
  43. githubrepo="linuxgsm"
  44. githubbranch="$TRAVIS_BRANCH"
  45. ##### Script #####
  46. # Do not edit
  47. fn_getgithubfile(){
  48. filename=$1
  49. exec=$2
  50. fileurl=${3:-$filename}
  51. filepath="${rootdir}/${filename}"
  52. filedir=$(dirname "${filepath}")
  53. # If the function file is missing, then download
  54. if [ ! -f "${filepath}" ]; then
  55. if [ ! -d "${filedir}" ]; then
  56. mkdir "${filedir}"
  57. fi
  58. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
  59. echo -e " fetching ${filename}...\c"
  60. if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then
  61. :
  62. else
  63. echo -e "\e[0;31mFAIL\e[0m\n"
  64. echo "Curl is not installed!"
  65. echo -e ""
  66. exit
  67. fi
  68. curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1)
  69. if [ $? -ne 0 ]; then
  70. echo -e "\e[0;31mFAIL\e[0m\n"
  71. echo "${curl}"
  72. echo -e "${githuburl}\n"
  73. exit
  74. else
  75. echo -e "\e[0;32mOK\e[0m"
  76. fi
  77. if [ "${exec}" ]; then
  78. chmod +x "${filepath}"
  79. fi
  80. fi
  81. if [ "${exec}" ]; then
  82. source "${filepath}"
  83. fi
  84. }
  85. fn_runfunction(){
  86. fn_getgithubfile "functions/${functionfile}" 1
  87. }
  88. core_functions.sh(){
  89. # Functions are defined in core_functions.sh.
  90. functionfile="${FUNCNAME}"
  91. fn_runfunction
  92. }
  93. core_functions.sh
  94. fn_currentstatus_tmux(){
  95. check_status.sh
  96. if [ "${status}" != "0" ]; then
  97. currentstatus="ONLINE"
  98. else
  99. currentstatus="OFFLINE"
  100. fi
  101. }
  102. fn_currentstatus_ts3(){
  103. check_status.sh
  104. if [ "${status}" != "0" ]; then
  105. currentstatus="ONLINE"
  106. else
  107. currentstatus="OFFLINE"
  108. fi
  109. }
  110. fn_setstatus(){
  111. fn_currentstatus_ts3
  112. echo""
  113. echo "Required status: ${requiredstatus}"
  114. counter=0
  115. echo "Current status: ${currentstatus}"
  116. while [ "${requiredstatus}" != "${currentstatus}" ]; do
  117. counter=$((counter+1))
  118. fn_currentstatus_ts3
  119. echo -ne "New status: ${currentstatus}\\r"
  120. if [ "${requiredstatus}" == "ONLINE" ]; then
  121. (command_start.sh)
  122. else
  123. (command_stop.sh)
  124. fi
  125. if [ "${counter}" -gt "5" ]; then
  126. currentstatus="FAIL"
  127. echo "Current status: ${currentstatus}"
  128. echo ""
  129. echo "Unable to start or stop server."
  130. exit 1
  131. fi
  132. done
  133. echo -ne "New status: ${currentstatus}\\r"
  134. echo -e "\n"
  135. echo "Test starting:"
  136. echo ""
  137. sleep 0.5
  138. }
  139. echo "================================="
  140. echo "TravisCI Tests"
  141. echo "Linux Game Server Manager"
  142. echo "by Daniel Gibbs"
  143. echo "https://gameservermanagers.com"
  144. echo "================================="
  145. echo ""
  146. sleep 1
  147. echo "================================="
  148. echo "Server Tests"
  149. echo "Using: ${gamename}"
  150. echo "================================="
  151. echo ""
  152. sleep 1
  153. echo "1.0 - start - no files"
  154. echo "================================="
  155. echo "Description:"
  156. echo "test script reaction to missing server files."
  157. echo ""
  158. (command_start.sh)
  159. echo ""
  160. echo "Test complete!"
  161. sleep 1
  162. echo ""
  163. echo "1.1 - getopt"
  164. echo "================================="
  165. echo "Description:"
  166. echo "displaying options messages."
  167. echo ""
  168. (core_getopt.sh)
  169. echo ""
  170. echo "Test complete!"
  171. sleep 1
  172. echo ""
  173. echo "2.0 - install"
  174. echo "================================="
  175. echo "Description:"
  176. echo "install ${gamename} server."
  177. fn_autoinstall
  178. echo ""
  179. echo "Test complete!"
  180. sleep 1
  181. echo ""
  182. echo "3.1 - start"
  183. echo "================================="
  184. echo "Description:"
  185. echo "start ${gamename} server."
  186. requiredstatus="OFFLINE"
  187. fn_setstatus
  188. command_start.sh
  189. echo ""
  190. echo "Test complete!"
  191. sleep 1
  192. echo ""
  193. echo "3.2 - start - online"
  194. echo "================================="
  195. echo "Description:"
  196. echo "start ${gamename} server while already running."
  197. requiredstatus="ONLINE"
  198. fn_setstatus
  199. (command_start.sh)
  200. echo ""
  201. echo "Test complete!"
  202. sleep 1
  203. echo ""
  204. echo "3.3 - start - updateonstart"
  205. echo "================================="
  206. echo "Description:"
  207. echo "will update server on start."
  208. requiredstatus="OFFLINE"
  209. fn_setstatus
  210. (
  211. updateonstart="on"
  212. command_start.sh
  213. )
  214. echo ""
  215. echo "Test complete!"
  216. sleep 1
  217. echo ""
  218. echo "3.4 - stop"
  219. echo "================================="
  220. echo "Description:"
  221. echo "stop ${gamename} server."
  222. requiredstatus="ONLINE"
  223. fn_setstatus
  224. command_stop.sh
  225. echo ""
  226. echo "Test complete!"
  227. sleep 1
  228. echo ""
  229. echo "3.5 - stop - offline"
  230. echo "================================="
  231. echo "Description:"
  232. echo "stop ${gamename} server while already stopped."
  233. requiredstatus="OFFLINE"
  234. fn_setstatus
  235. (command_stop.sh)
  236. echo ""
  237. echo "Test complete!"
  238. sleep 1
  239. echo ""
  240. echo "3.6 - restart"
  241. echo "================================="
  242. echo "Description:"
  243. echo "restart ${gamename}."
  244. requiredstatus="ONLINE"
  245. fn_setstatus
  246. fn_restart
  247. echo ""
  248. echo "Test complete!"
  249. sleep 1
  250. echo ""
  251. echo "3.7 - restart - offline"
  252. echo "================================="
  253. echo "Description:"
  254. echo "restart ${gamename} while already stopped."
  255. requiredstatus="OFFLINE"
  256. fn_setstatus
  257. fn_restart
  258. echo ""
  259. echo "Test complete!"
  260. sleep 1
  261. echo ""
  262. echo "4.1 - update"
  263. echo "================================="
  264. echo "Description:"
  265. echo "check for updates."
  266. requiredstatus="OFFLINE"
  267. fn_setstatus
  268. update_check.sh
  269. echo ""
  270. echo "Test complete!"
  271. sleep 1
  272. echo ""
  273. echo "4.1 - update - old version"
  274. echo "================================="
  275. echo "Description:"
  276. echo "change the version number tricking LGSM to update."
  277. requiredstatus="OFFLINE"
  278. sed -i 's/[0-9]\+/0/g' ${gamelogdir}/ts3server*_0.log
  279. fn_setstatus
  280. update_check.sh
  281. echo ""
  282. echo "Test complete!"
  283. sleep 1
  284. echo ""
  285. echo "5.1 - monitor - online"
  286. echo "================================="
  287. echo "Description:"
  288. echo "run monitor server while already running."
  289. requiredstatus="ONLINE"
  290. fn_setstatus
  291. (command_monitor.sh)
  292. echo ""
  293. echo "Test complete!"
  294. sleep 1
  295. echo ""
  296. echo "5.2 - monitor - offline - no lockfile"
  297. echo "================================="
  298. echo "Description:"
  299. echo "run monitor while server is offline with no lockfile."
  300. requiredstatus="OFFLINE"
  301. fn_setstatus
  302. (command_monitor.sh)
  303. echo ""
  304. echo "Test complete!"
  305. sleep 1
  306. echo ""
  307. echo "5.3 - monitor - offline - with lockfile"
  308. echo "================================="
  309. echo "Description:"
  310. echo "run monitor while server is offline with no lockfile."
  311. requiredstatus="OFFLINE"
  312. fn_setstatus
  313. fn_print_info_nl "creating lockfile."
  314. date > "${rootdir}/${lockselfname}"
  315. (command_monitor.sh)
  316. echo ""
  317. echo "Test complete!"
  318. sleep 1
  319. echo ""
  320. echo "5.4 - monitor - gsquery.py failure"
  321. echo "================================="
  322. echo "Description:"
  323. echo "gsquery.py will fail to query port."
  324. requiredstatus="ONLINE"
  325. fn_setstatus
  326. sed -i 's/[0-9]\+/0/' "${servercfgfullpath}"
  327. (command_monitor.sh)
  328. echo ""
  329. fn_print_info_nl "Reseting ${servercfg}."
  330. install_config.sh
  331. echo ""
  332. echo "Test complete!"
  333. sleep 1
  334. echo ""
  335. echo "6.0 - details"
  336. echo "================================="
  337. echo "Description:"
  338. echo "display details."
  339. requiredstatus="ONLINE"
  340. fn_setstatus
  341. command_details.sh
  342. echo ""
  343. echo "Test complete!"
  344. sleep 1
  345. echo ""
  346. echo "================================="
  347. echo "Server Tests - Complete!"
  348. echo "Using: ${gamename}"
  349. echo "================================="
  350. echo ""
  351. requiredstatus="OFFLINE"
  352. fn_setstatus
  353. sleep 1
  354. fn_print_info "Tidying up directories."
  355. sleep 1
  356. rm -rfv ${serverfiles}
  357. echo "END"