test.sh 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. #!/bin/bash
  2. # Just Cause 2
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: http://gameservermanagers.com
  6. version="150715"
  7. #### Variables ####
  8. # Notification Email
  9. # (on|off)
  10. emailnotification="on"
  11. email="me@danielgibbs.co.uk"
  12. # Steam login
  13. steamuser="anonymous"
  14. steampass=""
  15. # Start Variables
  16. updateonstart="off"
  17. fn_parms(){
  18. parms=""
  19. }
  20. #### Advanced Variables ####
  21. # Steam
  22. appid="261140"
  23. # Server Details
  24. servicename="jc2-server"
  25. gamename="Just Cause 2"
  26. engine="avalanche"
  27. # Directories
  28. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  29. selfname="$(basename $0)"
  30. lockselfname=".${servicename}.lock"
  31. filesdir="${rootdir}/serverfiles"
  32. systemdir="${filesdir}"
  33. executabledir="${filesdir}"
  34. executable="./Jcmp-Server"
  35. servercfg="config.lua"
  36. servercfgdir="${filesdir}"
  37. servercfgfullpath="${servercfgdir}/${servercfg}"
  38. servercfgdefault="${servercfgdir}/default_config.lua"
  39. backupdir="${rootdir}/backups"
  40. # Logging
  41. logdays="7"
  42. #gamelogdir="" # No server logs available
  43. scriptlogdir="${rootdir}/log/script"
  44. consolelogdir="${rootdir}/log/console"
  45. scriptlog="${scriptlogdir}/${servicename}-script.log"
  46. consolelog="${consolelogdir}/${servicename}-console.log"
  47. emaillog="${scriptlogdir}/${servicename}-email.log"
  48. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  49. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  50. ##### Script #####
  51. # Do not edit
  52. fn_runfunction(){
  53. # Functions are downloaded and run with this function
  54. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  55. cd "${rootdir}"
  56. if [ ! -d "functions" ]; then
  57. mkdir functions
  58. fi
  59. cd functions
  60. echo -e " loading ${functionfile}...\c"
  61. wget -N /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
  62. chmod +x "${functionfile}"
  63. cd "${rootdir}"
  64. fi
  65. source "${rootdir}/functions/${functionfile}"
  66. }
  67. fn_functions(){
  68. # Functions are defined in fn_functions.
  69. functionfile="${FUNCNAME}"
  70. fn_runfunction
  71. }
  72. fn_functions
  73. getopt=$1
  74. fn_currentstatus(){
  75. pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
  76. if [ "${pid}" == "0" ]; then
  77. currentstatus="OFFLINE"
  78. else
  79. currentstatus="ONLINE"
  80. fi
  81. }
  82. fn_setstatus(){
  83. fn_currentstatus
  84. echo""
  85. echo "Required status: ${requiredstatus}"
  86. counter=0
  87. while [ "${requiredstatus}" != "${currentstatus}" ]; do
  88. counter=$((counter+1))
  89. fn_currentstatus
  90. echo -ne "Current status: ${currentstatus}\\r"
  91. if [ "${requiredstatus}" == "ONLINE" ]; then
  92. (fn_start > /dev/null 2>&1)
  93. else
  94. (fn_stop > /dev/null 2>&1)
  95. fi
  96. if [ "${counter}" -gt "5" ]; then
  97. currentstatus="FAIL"
  98. echo "Current status: ${currentstatus}"
  99. echo ""
  100. echo "Unable to start or stop server."
  101. exit
  102. fi
  103. done
  104. echo -ne "Current status: ${currentstatus}\\r"
  105. echo -e "\n"
  106. echo "Test starting:"
  107. echo ""
  108. sleep 0.5
  109. }
  110. echo "================================="
  111. echo "TravisCI Tests"
  112. echo "Linux Game Server Manager"
  113. echo "by Daniel Gibbs"
  114. echo "http://gameservermanagers.com"
  115. echo "================================="
  116. echo ""
  117. echo "1.0 - start - no files"
  118. echo "================================="
  119. echo "Description:"
  120. echo "Test script reaction to missing server files."
  121. requiredstatus="OFFLINE"
  122. fn_setstatus
  123. (fn_start)
  124. echo ""
  125. echo "Test complete!"
  126. sleep 1
  127. echo ""
  128. echo "2.0 - install"
  129. echo "================================="
  130. echo "Description:"
  131. echo "install ${gamename} server."
  132. requiredstatus="OFFLINE"
  133. fn_setstatus
  134. fn_autoinstall
  135. echo ""
  136. echo "Test complete!"
  137. sleep 1
  138. echo ""
  139. echo "3.1 - start"
  140. echo "================================="
  141. echo "Description:"
  142. echo "start ${gamename} server."
  143. requiredstatus="OFFLINE"
  144. fn_setstatus
  145. fn_start
  146. echo ""
  147. echo "Test complete!"
  148. sleep 1
  149. echo ""
  150. echo "3.2 - start - online"
  151. echo "================================="
  152. echo "Description:"
  153. echo "start ${gamename} server while already running."
  154. requiredstatus="ONLINE"
  155. fn_setstatus
  156. (fn_start)
  157. echo ""
  158. echo "Test complete!"
  159. sleep 1
  160. echo ""
  161. echo "3.3 - stop"
  162. echo "================================="
  163. echo "Description:"
  164. echo "stop ${gamename} server."
  165. requiredstatus="ONLINE"
  166. fn_setstatus
  167. fn_stop
  168. echo ""
  169. echo "Test complete!"
  170. sleep 1
  171. echo ""
  172. echo "3.4 - stop - offline"
  173. echo "================================="
  174. echo "Description:"
  175. echo "stop ${gamename} server while already stopped."
  176. requiredstatus="OFFLINE"
  177. fn_setstatus
  178. (fn_stop)
  179. echo ""
  180. echo "Test complete!"
  181. sleep 1
  182. echo ""
  183. echo "3.5 - restart"
  184. echo "================================="
  185. echo "Description:"
  186. echo "restart ${gamename}."
  187. requiredstatus="ONLINE"
  188. fn_setstatus
  189. fn_restart
  190. echo ""
  191. echo "Test complete!"
  192. sleep 1
  193. echo ""
  194. echo "3.5 - restart - offline"
  195. echo "================================="
  196. echo "Description:"
  197. echo "restart ${gamename} while already stopped."
  198. requiredstatus="OFFLINE"
  199. fn_setstatus
  200. fn_restart
  201. echo ""
  202. echo "Test complete!"
  203. sleep 1
  204. echo ""
  205. echo "4.1 - update"
  206. echo "================================="
  207. echo "Description:"
  208. echo "check for updates."
  209. requiredstatus="OFFLINE"
  210. fn_setstatus
  211. fn_update_check
  212. echo ""
  213. echo "Test complete!"
  214. sleep 1
  215. echo ""
  216. echo "4.2 - update - change buildid"
  217. echo "================================="
  218. echo "Description:"
  219. echo "change the buildid tricking SteamCMD to update."
  220. requiredstatus="OFFLINE"
  221. fn_setstatus
  222. fn_printinfonl "changed buildid to 0."
  223. sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf
  224. fn_update_check
  225. echo ""
  226. echo "Test complete!"
  227. sleep 1
  228. echo ""
  229. echo "4.3 - update - change buildid - online"
  230. echo "================================="
  231. echo "Description:"
  232. echo "change the buildid tricking SteamCMD to update server while already running."
  233. requiredstatus="ONLINE"
  234. fn_setstatus
  235. fn_printinfonl "changed buildid to 0."
  236. sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf
  237. fn_update_check
  238. echo ""
  239. echo "Test complete!"
  240. sleep 1
  241. echo ""
  242. echo "4.4 - update - remove appmanifest file"
  243. echo "================================="
  244. echo "Description:"
  245. echo "removing appmanifest file will cause script to repair."
  246. requiredstatus="OFFLINE"
  247. fn_setstatus
  248. fn_printinfonl "removed appmanifest_${appid}.acf."
  249. rm --verbose "${filesdir}/steamapps/appmanifest_${appid}.acf"
  250. fn_update_check
  251. echo ""
  252. echo "Test complete!"
  253. sleep 1
  254. echo ""
  255. echo "4.5 - force-update"
  256. echo "================================="
  257. echo "Description:"
  258. echo "force-update bypassing update check."
  259. requiredstatus="OFFLINE"
  260. fn_setstatus
  261. fn_update_check
  262. echo ""
  263. echo "Test complete!"
  264. sleep 1
  265. echo ""
  266. echo "4.6 - force-update - online"
  267. echo "================================="
  268. echo "Description:"
  269. echo "force-update bypassing update check server while already running."
  270. requiredstatus="ONLINE"
  271. fn_setstatus
  272. fn_update_check
  273. echo ""
  274. echo "Test complete!"
  275. sleep 1
  276. echo ""
  277. echo "4.7 - validate"
  278. echo "================================="
  279. echo "Description:"
  280. echo "validate server files."
  281. requiredstatus="OFFLINE"
  282. fn_setstatus
  283. fn_validate
  284. echo ""
  285. echo "Test complete!"
  286. sleep 1
  287. echo ""
  288. echo "4.8 - validate - online"
  289. echo "================================="
  290. echo "Description:"
  291. echo "validate server files while server while already running."
  292. requiredstatus="ONLINE"
  293. fn_setstatus
  294. fn_validate
  295. echo ""
  296. echo "Test complete!"
  297. sleep 1
  298. echo ""
  299. echo "5.1 - monitor - online"
  300. echo "================================="
  301. echo "Description:"
  302. echo "run monitor server while already running."
  303. requiredstatus="ONLINE"
  304. fn_setstatus
  305. (fn_monitor)
  306. echo ""
  307. echo "Test complete!"
  308. sleep 1
  309. echo ""
  310. echo "5.2 - monitor - offline - no lockfile"
  311. echo "================================="
  312. echo "Description:"
  313. echo "run monitor while server is offline with no lockfile."
  314. requiredstatus="OFFLINE"
  315. fn_setstatus
  316. (fn_monitor)
  317. echo ""
  318. echo "Test complete!"
  319. sleep 1
  320. echo ""
  321. echo "5.3 - monitor - offline - with lockfile"
  322. echo "================================="
  323. echo "Description:"
  324. echo "run monitor while server is offline with no lockfile."
  325. requiredstatus="OFFLINE"
  326. fn_setstatus
  327. fn_printinfonl "creating lockfile."
  328. date > "${rootdir}/${lockselfname}"
  329. (fn_monitor)
  330. echo ""
  331. echo "Test complete!"
  332. sleep 1
  333. echo ""
  334. echo "5.4 - monitor - gsquery.py failure"
  335. echo "================================="
  336. echo "Description:"
  337. echo "gsquery.py will fail to query port."
  338. requiredstatus="ONLINE"
  339. fn_setstatus
  340. sed -i 's/[0-9]\+/0/' "${servercfgfullpath}"
  341. fn_monitor
  342. echo ""
  343. fn_printinfonl "Reseting ${servercfg}."
  344. fn_install_config
  345. echo ""
  346. echo "Test complete!"
  347. sleep 1
  348. echo ""
  349. echo "6.0 - details"
  350. echo "================================="
  351. echo "Description:"
  352. echo "gsquery.py will fail to query port."
  353. requiredstatus="ONLINE"
  354. fn_setstatus
  355. fn_details
  356. echo ""
  357. echo "Test complete!"
  358. sleep 1
  359. echo ""