jc2server 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #!/bin/bash
  2. # Just Cause 2
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: http://danielgibbs.co.uk
  6. # Version: 011214
  7. #### Variables ####
  8. # Notification Email
  9. # (on|off)
  10. emailnotification="off"
  11. email="email@example.com"
  12. # Steam login
  13. steamuser="anonymous"
  14. steampass=""
  15. # Start Variables
  16. maxplayers="10"
  17. port="7777"
  18. ip="0.0.0.0"
  19. fn_parms(){
  20. parms="--maxplayers ${maxplayers} --bindip ${ip} --bindport ${port}"
  21. }
  22. #### Advanced Variables ####
  23. # Steam
  24. appid="261140"
  25. # Server Details
  26. servicename="jc2-server"
  27. gamename="Just Cause 2"
  28. engine="avalanche"
  29. # Directories
  30. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
  31. selfname="$0"
  32. lockselfname=$(echo ".${servicename}.lock")
  33. filesdir="${rootdir}/serverfiles"
  34. systemdir="${filesdir}"
  35. executabledir="${filesdir}"
  36. executable="./Jcmp-Server"
  37. servercfgdir="${filesdir}"
  38. servercfg="config.lua"
  39. servercfgfullpath="${servercfgdir}/${servercfg}"
  40. backupdir="backups"
  41. # Server Details
  42. servername=$(grep -s hostname "${servercfgfullpath}"|sed 's/hostname //g'|sed 's/"//g')
  43. # Logging
  44. logdays="7"
  45. #gamelogdir="" # No server logs available
  46. scriptlogdir="${rootdir}/log/script"
  47. consolelogdir="${rootdir}/log/console"
  48. scriptlog="${scriptlogdir}/${servicename}-script.log"
  49. consolelog="${consolelogdir}/${servicename}-console.log"
  50. emaillog="${scriptlogdir}/${servicename}-email.log"
  51. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  52. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  53. ##### Script #####
  54. # Do not edit
  55. # unless you know
  56. # what you are doing
  57. fn_scriptlog(){
  58. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
  59. }
  60. # [ FAIL ]
  61. fn_printfail(){
  62. echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  63. }
  64. fn_printfailnl(){
  65. echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  66. }
  67. # [ OK ]
  68. fn_printok(){
  69. echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  70. }
  71. fn_printoknl(){
  72. echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  73. }
  74. # [ INFO ]
  75. fn_printinfo(){
  76. echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  77. }
  78. fn_printinfonl(){
  79. echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  80. }
  81. # [ WARN ]
  82. fn_printwarn(){
  83. echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  84. }
  85. fn_printwarnnl(){
  86. echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  87. }
  88. # [ .... ]
  89. fn_printdots(){
  90. echo -en "\r\033[K[ .... ] $@"
  91. }
  92. fn_rootcheck(){
  93. functionfile="${FUNCNAME}"
  94. fn_runfunction
  95. }
  96. fn_syscheck(){
  97. if [ ! -e "${systemdir}" ]; then
  98. fn_printfailnl "Cannot access ${systemdir}: No such directory"
  99. exit
  100. fi
  101. }
  102. fn_autoip(){
  103. functionfile="${FUNCNAME}"
  104. fn_runfunction
  105. }
  106. fn_logmanager(){
  107. functionfile="${FUNCNAME}"
  108. fn_runfunction
  109. }
  110. fn_debugserver(){
  111. functionfile="${FUNCNAME}"
  112. fn_runfunction
  113. }
  114. fn_console(){
  115. functionfile="${FUNCNAME}"
  116. fn_runfunction
  117. }
  118. fn_backupserver(){
  119. functionfile="${FUNCNAME}"
  120. fn_runfunction
  121. }
  122. fn_distro(){
  123. functionfile="${FUNCNAME}"
  124. fn_runfunction
  125. }
  126. fn_uptime(){
  127. functionfile="${FUNCNAME}"
  128. fn_runfunction
  129. }
  130. fn_load(){
  131. functionfile="${FUNCNAME}"
  132. fn_runfunction
  133. }
  134. fn_emailnotification(){
  135. functionfile="${FUNCNAME}"
  136. fn_runfunction
  137. }
  138. fn_emailtest(){
  139. functionfile="${FUNCNAME}"
  140. fn_runfunction
  141. }
  142. fn_serverquery(){
  143. functionfile="${FUNCNAME}"
  144. fn_runfunction
  145. }
  146. fn_monitorserver(){
  147. functionfile="${FUNCNAME}"
  148. fn_runfunction
  149. }
  150. fn_updateserver(){
  151. functionfile="${FUNCNAME}"
  152. fn_runfunction
  153. }
  154. fn_validateserver(){
  155. functionfile="${FUNCNAME}"
  156. fn_runfunction
  157. }
  158. fn_restartserver(){
  159. fn_scriptlog "Restarting ${servername}"
  160. fn_stopserver
  161. fn_startserver
  162. }
  163. fn_stopserver(){
  164. functionfile="${FUNCNAME}"
  165. fn_runfunction
  166. }
  167. fn_startserver(){
  168. functionfile="${FUNCNAME}"
  169. fn_runfunction
  170. }
  171. fn_details(){
  172. functionfile="${FUNCNAME}"
  173. fn_runfunction
  174. }
  175. fn_runfunction(){
  176. # Download function if missing
  177. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  178. cd "${rootdir}"
  179. if [ ! -d "functions" ]; then
  180. mkdir functions
  181. fi
  182. echo "loading ${functionfile}..."
  183. cd functions
  184. wget --no-check-certificate -nv -N https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile}
  185. chmod +x "${functionfile}"
  186. cd "${rootdir}"
  187. sleep 1
  188. echo ""
  189. fi
  190. # Run function
  191. source "${rootdir}/functions/${functionfile}"
  192. }
  193. #
  194. ## Installer
  195. #
  196. fn_header(){
  197. functionfile="${FUNCNAME}"
  198. fn_runfunction
  199. }
  200. fn_steamdl(){
  201. functionfile="${FUNCNAME}"
  202. fn_runfunction
  203. }
  204. fn_steaminstall(){
  205. functionfile="${FUNCNAME}"
  206. fn_runfunction
  207. }
  208. fn_glibcfix(){
  209. functionfile="${FUNCNAME}"
  210. fn_runfunction
  211. }
  212. fn_loginstall(){
  213. functionfile="${FUNCNAME}"
  214. fn_runfunction
  215. }
  216. fn_getquery(){
  217. functionfile="${FUNCNAME}"
  218. fn_runfunction
  219. }
  220. fn_retryinstall(){
  221. functionfile="${FUNCNAME}"
  222. fn_runfunction
  223. }
  224. fn_serverdirectory(){
  225. functionfile="${FUNCNAME}"
  226. fn_runfunction
  227. }
  228. fn_serverconfig(){
  229. functionfile="${FUNCNAME}"
  230. fn_runfunction
  231. }
  232. fn_install(){
  233. fn_rootcheck
  234. fn_header
  235. if [ -z "${autoinstall}" ]; then
  236. fn_serverdirectory
  237. fn_header
  238. fi
  239. fn_steamdl
  240. fn_steaminstall
  241. fn_glibcfix
  242. fn_loginstall
  243. fn_getquery
  244. fn_serverconfig
  245. fn_header
  246. fn_details
  247. echo "================================="
  248. echo "Install Complete!"
  249. echo ""
  250. echo "To start server type:"
  251. echo "${selfname} start"
  252. echo ""
  253. }
  254. fn_autoinstall(){
  255. autoinstall=1
  256. fn_install
  257. }
  258. case "$1" in
  259. start)
  260. fn_startserver;;
  261. stop)
  262. fn_stopserver;;
  263. restart)
  264. fn_restartserver;;
  265. update)
  266. fn_updateserver;;
  267. update-restart)
  268. fn_stopserver
  269. fn_updateserver
  270. fn_startserver;;
  271. validate)
  272. fn_validateserver;;
  273. validate-restart)
  274. fn_stopserver
  275. fn_validateserver
  276. fn_startserver;;
  277. monitor)
  278. fn_monitorserver;;
  279. email-test)
  280. fn_emailtest;;
  281. details)
  282. fn_details;;
  283. backup)
  284. fn_backupserver;;
  285. console)
  286. fn_console;;
  287. debug)
  288. fn_debugserver;;
  289. install)
  290. fn_install;;
  291. auto-install)
  292. fn_autoinstall;;
  293. *)
  294. echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install}"
  295. exit 1;;
  296. esac
  297. exit