ns2server 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. #!/bin/bash
  2. # Natural Selection 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="username"
  14. steampass="password"
  15. # Start Variables
  16. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
  17. defaultmap="ns2_summit"
  18. port="27015"
  19. maxplayers="24"
  20. ip="0.0.0.0"
  21. servername="NS2 Server"
  22. webadminuser="admin"
  23. webadminpass="admin"
  24. webadminport="8080"
  25. configpath="server1"
  26. modstorage="server1/Workshop"
  27. mods=""
  28. password=""
  29. # Add the following line to the parms if you want a private server. Ensuring
  30. # that the password variable above is not left empty.
  31. # -password \"${password}\"
  32. fn_parms(){
  33. parms="-name \"${servername}\" -port ${port} -webadmin -webdomain ${ip} -webuser ${webadminuser} -webpassword \"${webadminpass}\" -webport ${webadminport} -map ${defaultmap} -limit ${maxplayers} -config_path \"${rootdir}/${configpath}\" -modstorage \"${rootdir}/${modstorage}\" -mods \"${mods}\""
  34. }
  35. #### Advanced Variables ####
  36. # Steam
  37. appid="4940"
  38. # Server Details
  39. servicename="ns2-server"
  40. gamename="Natural Selection 2"
  41. engine="spark"
  42. # Directories
  43. selfname="$0"
  44. lockselfname=$(echo ".${servicename}.lock")
  45. filesdir="${rootdir}/serverfiles"
  46. systemdir="${filesdir}"
  47. executabledir="${filesdir}"
  48. executable="./server_linux32"
  49. backupdir="backups"
  50. # Logging
  51. logdays="7"
  52. gamelogdir="${systemdir}/logs"
  53. scriptlogdir="${rootdir}/log/script"
  54. consolelogdir="${rootdir}/log/console"
  55. scriptlog="${scriptlogdir}/${servicename}-script.log"
  56. consolelog="${consolelogdir}/${servicename}-console.log"
  57. emaillog="${scriptlogdir}/${servicename}-email.log"
  58. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  59. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  60. ##### Script #####
  61. # Do not edit
  62. # unless you know
  63. # what you are doing
  64. fn_scriptlog(){
  65. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
  66. }
  67. # [ FAIL ]
  68. fn_printfail(){
  69. echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  70. }
  71. fn_printfailnl(){
  72. echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  73. }
  74. # [ OK ]
  75. fn_printok(){
  76. echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  77. }
  78. fn_printoknl(){
  79. echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  80. }
  81. # [ INFO ]
  82. fn_printinfo(){
  83. echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  84. }
  85. fn_printinfonl(){
  86. echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  87. }
  88. # [ WARN ]
  89. fn_printwarn(){
  90. echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  91. }
  92. fn_printwarnnl(){
  93. echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  94. }
  95. # [ .... ]
  96. fn_printdots(){
  97. echo -en "\r\033[K[ .... ] $@"
  98. }
  99. fn_rootcheck(){
  100. functionfile="${FUNCNAME}"
  101. fn_runfunction
  102. }
  103. fn_syscheck(){
  104. if [ ! -e "${systemdir}" ]; then
  105. fn_printfailnl "Cannot access ${systemdir}: No such directory"
  106. exit
  107. fi
  108. }
  109. fn_autoip(){
  110. functionfile="${FUNCNAME}"
  111. fn_runfunction
  112. }
  113. fn_logmanager(){
  114. functionfile="${FUNCNAME}"
  115. fn_runfunction
  116. }
  117. fn_debugserver(){
  118. functionfile="${FUNCNAME}"
  119. fn_runfunction
  120. }
  121. fn_console(){
  122. functionfile="${FUNCNAME}"
  123. fn_runfunction
  124. }
  125. fn_backupserver(){
  126. functionfile="${FUNCNAME}"
  127. fn_runfunction
  128. }
  129. fn_distro(){
  130. functionfile="${FUNCNAME}"
  131. fn_runfunction
  132. }
  133. fn_uptime(){
  134. functionfile="${FUNCNAME}"
  135. fn_runfunction
  136. }
  137. fn_load(){
  138. functionfile="${FUNCNAME}"
  139. fn_runfunction
  140. }
  141. fn_emailnotification(){
  142. functionfile="${FUNCNAME}"
  143. fn_runfunction
  144. }
  145. fn_emailtest(){
  146. functionfile="${FUNCNAME}"
  147. fn_runfunction
  148. }
  149. fn_serverquery(){
  150. functionfile="${FUNCNAME}"
  151. fn_runfunction
  152. }
  153. fn_monitorserver(){
  154. functionfile="${FUNCNAME}"
  155. fn_runfunction
  156. }
  157. fn_updateserver(){
  158. functionfile="${FUNCNAME}"
  159. fn_runfunction
  160. }
  161. fn_validateserver(){
  162. functionfile="${FUNCNAME}"
  163. fn_runfunction
  164. }
  165. fn_restartserver(){
  166. fn_scriptlog "Restarting ${servername}"
  167. fn_stopserver
  168. fn_startserver
  169. }
  170. fn_stopserver(){
  171. functionfile="${FUNCNAME}"
  172. fn_runfunction
  173. }
  174. fn_startserver(){
  175. functionfile="${FUNCNAME}"
  176. fn_runfunction
  177. }
  178. fn_details(){
  179. functionfile="${FUNCNAME}"
  180. fn_runfunction
  181. }
  182. fn_runfunction(){
  183. # Download function if missing
  184. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  185. cd "${rootdir}"
  186. if [ ! -d "functions" ]; then
  187. mkdir functions
  188. fi
  189. echo "loading ${functionfile}..."
  190. cd functions
  191. wget --no-check-certificate -nv -N https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile}
  192. chmod +x "${functionfile}"
  193. cd "${rootdir}"
  194. sleep 1
  195. echo ""
  196. fi
  197. # Run function
  198. source "${rootdir}/functions/${functionfile}"
  199. }
  200. #
  201. ## Installer
  202. #
  203. fn_header(){
  204. functionfile="${FUNCNAME}"
  205. fn_runfunction
  206. }
  207. fn_steamdl(){
  208. functionfile="${FUNCNAME}"
  209. fn_runfunction
  210. }
  211. fn_steaminstall(){
  212. functionfile="${FUNCNAME}"
  213. fn_runfunction
  214. }
  215. fn_steamfix(){
  216. functionfile="${FUNCNAME}"
  217. fn_runfunction
  218. }
  219. fn_glibcfix(){
  220. functionfile="${FUNCNAME}"
  221. fn_runfunction
  222. }
  223. fn_loginstall(){
  224. functionfile="${FUNCNAME}"
  225. fn_runfunction
  226. }
  227. fn_getquery(){
  228. functionfile="${FUNCNAME}"
  229. fn_runfunction
  230. }
  231. fn_retryinstall(){
  232. functionfile="${FUNCNAME}"
  233. fn_runfunction
  234. }
  235. fn_serverdirectory(){
  236. functionfile="${FUNCNAME}"
  237. fn_runfunction
  238. }
  239. fn_install(){
  240. fn_rootcheck
  241. fn_header
  242. if [ -z "${autoinstall}" ]; then
  243. fn_serverdirectory
  244. fn_header
  245. fi
  246. fn_steamdl
  247. fn_steaminstall
  248. fn_steamfix
  249. fn_glibcfix
  250. fn_loginstall
  251. fn_getquery
  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