arma3server 6.1 KB

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