kfserver 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #!/bin/bash
  2. # Killing Floor
  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. # Steam
  16. appid="215360"
  17. # Directories
  18. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
  19. selfname="$0"
  20. lockselfname=$(echo ".${servicename}.lock")
  21. filesdir="${rootdir}/serverfiles"
  22. systemdir="${filesdir}/System"
  23. executabledir="${systemdir}"
  24. executable="./ucc-bin"
  25. compressedmapsdir="${rootdir}/Maps-Compressed"
  26. defaultcfg="${systemdir}/Default.ini"
  27. backupdir="backups"
  28. # Server Details
  29. servicename="kf-server"
  30. gamename="Killing Floor"
  31. engine="unreal2"
  32. ini="${servicename}.ini"
  33. servername=$(grep -s ServerName= ${systemdir}/${ini}|sed 's/ServerName=//g')
  34. ip="0.0.0.0"
  35. # Logging
  36. logdays="7"
  37. gamelogdir="${rootdir}/log/server"
  38. scriptlogdir="${rootdir}/log/script"
  39. consolelogdir="${rootdir}/log/console"
  40. gamelog="${gamelogdir}/${servicename}-game.log"
  41. scriptlog="${scriptlogdir}/${servicename}-script.log"
  42. consolelog="${consolelogdir}/${servicename}-console.log"
  43. emaillog="${scriptlogdir}/${servicename}-email.log"
  44. gamelogdate="${gamelogdir}/${servicename}-game-$(date '+%d-%m-%Y-%H-%M-%S').log"
  45. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  46. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  47. # Start Variables
  48. fn_parms(){
  49. defaultmap="KF-BioticsLab.rom"
  50. parms="server ${defaultmap}?game=KFmod.KFGameType?VACSecured=true -nohomedir ini=${ini} log=${gamelog}"
  51. # Start Variables for Objective mode
  52. #defaultmap="KFO-Steamland"
  53. #parms="server ${defaultmap}?Game=KFStoryGame.KFStoryGame?VACSecured=true -nohomedir ini=${ini} log=${gamelog}"
  54. }
  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. fn_unreal2compressmaps(){
  196. functionfile="${FUNCNAME}"
  197. fn_runfunction
  198. }
  199. #
  200. ## Installer
  201. #
  202. fn_kffix(){
  203. functionfile="${FUNCNAME}"
  204. fn_runfunction
  205. }
  206. fn_header(){
  207. functionfile="${FUNCNAME}"
  208. fn_runfunction
  209. }
  210. fn_steamdl(){
  211. functionfile="${FUNCNAME}"
  212. fn_runfunction
  213. }
  214. fn_steaminstall(){
  215. functionfile="${FUNCNAME}"
  216. fn_runfunction
  217. }
  218. fn_steamfix(){
  219. functionfile="${FUNCNAME}"
  220. fn_runfunction
  221. }
  222. fn_loginstall(){
  223. functionfile="${FUNCNAME}"
  224. fn_runfunction
  225. }
  226. fn_getquery(){
  227. functionfile="${FUNCNAME}"
  228. fn_runfunction
  229. }
  230. fn_retryinstall(){
  231. functionfile="${FUNCNAME}"
  232. fn_runfunction
  233. }
  234. fn_serverdirectory(){
  235. functionfile="${FUNCNAME}"
  236. fn_runfunction
  237. }
  238. fn_serverconfig(){
  239. functionfile="${FUNCNAME}"
  240. fn_runfunction
  241. }
  242. fn_install(){
  243. fn_rootcheck
  244. fn_header
  245. if [ -z "${autoinstall}" ]; then
  246. fn_serverdirectory
  247. fn_header
  248. fi
  249. fn_steamdl
  250. fn_steaminstall
  251. fn_steamfix
  252. fn_loginstall
  253. fn_getquery
  254. fn_serverconfig
  255. fn_kffix
  256. fn_header
  257. fn_details
  258. echo "================================="
  259. echo "Install Complete!"
  260. echo ""
  261. echo "To start server type:"
  262. echo "${selfname} start"
  263. echo ""
  264. }
  265. fn_autoinstall(){
  266. autoinstall=1
  267. fn_install
  268. }
  269. case "$1" in
  270. start)
  271. fn_startserver;;
  272. stop)
  273. fn_stopserver;;
  274. restart)
  275. fn_restartserver;;
  276. update)
  277. fn_updateserver;;
  278. update-restart)
  279. fn_stopserver
  280. fn_updateserver
  281. fn_startserver;;
  282. validate)
  283. fn_validateserver;;
  284. validate-restart)
  285. fn_stopserver
  286. fn_validateserver
  287. fn_startserver;;
  288. monitor)
  289. fn_monitorserver;;
  290. email-test)
  291. fn_emailtest;;
  292. details)
  293. fn_details;;
  294. backup)
  295. fn_backupserver;;
  296. console)
  297. fn_console;;
  298. debug)
  299. fn_debugserver;;
  300. install)
  301. fn_install;;
  302. auto-install)
  303. fn_autoinstall;;
  304. map-compressor)
  305. fn_unreal2compressmaps;;
  306. *)
  307. echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install|map-compressor}"
  308. exit 1;;
  309. esac
  310. exit