arma3server 5.8 KB

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