ut2k4server 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #!/bin/bash
  2. # Unreal Tournament 2004
  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. # Directories
  13. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
  14. selfname="$0"
  15. lockselfname=$(echo ".${servicename}.lock")
  16. filesdir="${rootdir}/serverfiles"
  17. systemdir="${filesdir}/System"
  18. executabledir="${systemdir}"
  19. executable="./ucc-bin"
  20. compressedmapsdir="${rootdir}/Maps-Compressed"
  21. defaultcfg="${systemdir}/UT2004.ini"
  22. backupdir="backups"
  23. # Server Details
  24. servicename="ut2k4-server"
  25. gamename="Unreal Tournament 2004"
  26. engine="unreal2"
  27. ini="${servicename}.ini"
  28. servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
  29. ip="0.0.0.0"
  30. # Logging
  31. logdays="7"
  32. gamelogdir="${rootdir}/log/server"
  33. scriptlogdir="${rootdir}/log/script"
  34. consolelogdir="${rootdir}/log/console"
  35. gamelog="${gamelogdir}/${servicename}-game.log"
  36. scriptlog="${scriptlogdir}/${servicename}-script.log"
  37. consolelog="${consolelogdir}/${servicename}-console.log"
  38. emaillog="${scriptlogdir}/${servicename}-email.log"
  39. gamelogdate="${gamelogdir}/${servicename}-game-$(date '+%d-%m-%Y-%H-%M-%S').log"
  40. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  41. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  42. # Start Variables
  43. fn_parms(){
  44. defaultmap="DM-Rankin"
  45. parms="server ${defaultmap}?game=XGame.xDeathMatch -nohomedir ini=${ini} log=${gamelog}"
  46. }
  47. ##### Script #####
  48. # Do not edit
  49. # unless you know
  50. # what you are doing
  51. fn_scriptlog(){
  52. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
  53. }
  54. # [ FAIL ]
  55. fn_printfail(){
  56. echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  57. }
  58. fn_printfailnl(){
  59. echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  60. }
  61. # [ OK ]
  62. fn_printok(){
  63. echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  64. }
  65. fn_printoknl(){
  66. echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  67. }
  68. # [ INFO ]
  69. fn_printinfo(){
  70. echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  71. }
  72. fn_printinfonl(){
  73. echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  74. }
  75. # [ WARN ]
  76. fn_printwarn(){
  77. echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  78. }
  79. fn_printwarnnl(){
  80. echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  81. }
  82. # [ .... ]
  83. fn_printdots(){
  84. echo -en "\r\033[K[ .... ] $@"
  85. }
  86. fn_rootcheck(){
  87. functionfile="${FUNCNAME}"
  88. fn_runfunction
  89. }
  90. fn_syscheck(){
  91. if [ ! -e "${systemdir}" ]; then
  92. fn_printfailnl "Cannot access ${systemdir}: No such directory"
  93. exit
  94. fi
  95. }
  96. fn_autoip(){
  97. functionfile="${FUNCNAME}"
  98. fn_runfunction
  99. }
  100. fn_logmanager(){
  101. functionfile="${FUNCNAME}"
  102. fn_runfunction
  103. }
  104. fn_debugserver(){
  105. functionfile="${FUNCNAME}"
  106. fn_runfunction
  107. }
  108. fn_console(){
  109. functionfile="${FUNCNAME}"
  110. fn_runfunction
  111. }
  112. fn_backupserver(){
  113. functionfile="${FUNCNAME}"
  114. fn_runfunction
  115. }
  116. fn_distro(){
  117. functionfile="${FUNCNAME}"
  118. fn_runfunction
  119. }
  120. fn_uptime(){
  121. functionfile="${FUNCNAME}"
  122. fn_runfunction
  123. }
  124. fn_load(){
  125. functionfile="${FUNCNAME}"
  126. fn_runfunction
  127. }
  128. fn_emailnotification(){
  129. functionfile="${FUNCNAME}"
  130. fn_runfunction
  131. }
  132. fn_emailtest(){
  133. functionfile="${FUNCNAME}"
  134. fn_runfunction
  135. }
  136. fn_serverquery(){
  137. functionfile="${FUNCNAME}"
  138. fn_runfunction
  139. }
  140. fn_monitorserver(){
  141. functionfile="${FUNCNAME}"
  142. fn_runfunction
  143. }
  144. fn_restartserver(){
  145. fn_scriptlog "Restarting ${servername}"
  146. fn_stopserver
  147. fn_startserver
  148. }
  149. fn_stopserver(){
  150. functionfile="${FUNCNAME}"
  151. fn_runfunction
  152. }
  153. fn_startserver(){
  154. functionfile="${FUNCNAME}"
  155. fn_runfunction
  156. }
  157. fn_details(){
  158. functionfile="${FUNCNAME}"
  159. fn_runfunction
  160. }
  161. fn_runfunction(){
  162. # Download function if missing
  163. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  164. cd "${rootdir}"
  165. if [ ! -d "functions" ]; then
  166. mkdir functions
  167. fi
  168. echo "loading ${functionfile}..."
  169. cd functions
  170. wget --no-check-certificate -nv -N https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile}
  171. chmod +x "${functionfile}"
  172. cd "${rootdir}"
  173. sleep 1
  174. echo ""
  175. fi
  176. # Run function
  177. source "${rootdir}/functions/${functionfile}"
  178. }
  179. fn_unreal2compressmaps(){
  180. functionfile="${FUNCNAME}"
  181. fn_runfunction
  182. }
  183. #
  184. ## Installer
  185. #
  186. fn_ut2k4fix(){
  187. functionfile="${FUNCNAME}"
  188. fn_runfunction
  189. }
  190. fn_header(){
  191. functionfile="${FUNCNAME}"
  192. fn_runfunction
  193. }
  194. fn_ut2k4filesdl(){
  195. functionfile="${FUNCNAME}"
  196. fn_runfunction
  197. }
  198. fn_ut2k4key(){
  199. functionfile="${FUNCNAME}"
  200. fn_runfunction
  201. }
  202. fn_ut2k4install(){
  203. functionfile="${FUNCNAME}"
  204. fn_runfunction
  205. }
  206. fn_loginstall(){
  207. functionfile="${FUNCNAME}"
  208. fn_runfunction
  209. }
  210. fn_getquery(){
  211. functionfile="${FUNCNAME}"
  212. fn_runfunction
  213. }
  214. fn_retryinstall(){
  215. functionfile="${FUNCNAME}"
  216. fn_runfunction
  217. }
  218. fn_serverdirectory(){
  219. functionfile="${FUNCNAME}"
  220. fn_runfunction
  221. }
  222. fn_serverconfig(){
  223. functionfile="${FUNCNAME}"
  224. fn_runfunction
  225. }
  226. fn_install(){
  227. fn_rootcheck
  228. fn_header
  229. if [ -z "${autoinstall}" ]; then
  230. fn_serverdirectory
  231. fn_header
  232. fi
  233. fn_ut2k4filesdl
  234. fn_ut2k4install
  235. fn_ut2k4key
  236. fn_loginstall
  237. fn_getquery
  238. fn_serverconfig
  239. fn_ut2k4fix
  240. fn_header
  241. fn_details
  242. echo "================================="
  243. echo "Install Complete!"
  244. echo ""
  245. echo "To start server type:"
  246. echo "${selfname} start"
  247. echo ""
  248. }
  249. case "$1" in
  250. start)
  251. fn_startserver;;
  252. stop)
  253. fn_stopserver;;
  254. restart)
  255. fn_restartserver;;
  256. monitor)
  257. fn_monitorserver;;
  258. email-test)
  259. fn_emailtest;;
  260. details)
  261. fn_details;;
  262. backup)
  263. fn_backupserver;;
  264. console)
  265. fn_console;;
  266. debug)
  267. fn_debugserver;;
  268. install)
  269. fn_install;;
  270. map-compressor)
  271. fn_unreal2compressmaps;;
  272. *)
  273. echo "Usage: $0 {start|stop|restart|monitor|email-test|details|backup|console|debug|install|map-compressor}"
  274. exit 1;;
  275. esac
  276. exit