cssserver 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #!/bin/bash
  2. # Counter Strike: Source
  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="anonymous"
  14. steampass=""
  15. # Start Variables
  16. defaultmap="de_dust2"
  17. maxplayers="16"
  18. port="27015"
  19. sourcetvport="27020"
  20. clientport="27005"
  21. ip="0.0.0.0"
  22. # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
  23. fn_parms(){
  24. parms="-game cstrike -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
  25. }
  26. #### Advanced Variables ####
  27. # Steam
  28. appid="232330"
  29. # Server Details
  30. servicename="css-server"
  31. gamename="Counter Strike: Source"
  32. engine="source"
  33. # Directories
  34. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
  35. selfname="$0"
  36. lockselfname=$(echo ".${servicename}.lock")
  37. filesdir="${rootdir}/serverfiles"
  38. systemdir="${filesdir}/cstrike"
  39. executabledir="${filesdir}"
  40. executable="./srcds_run"
  41. servercfgdir="${systemdir}/cfg"
  42. servercfg="${servicename}.cfg"
  43. servercfgfullpath="${servercfgdir}/${servercfg}"
  44. defaultcfg="${servercfgdir}/server.cfg"
  45. backupdir="backups"
  46. # Server Details
  47. servername=$(grep -s hostname "${servercfgfullpath}"|sed 's/hostname //g'|sed 's/"//g')
  48. rcon=$(grep -s rcon_password "${servercfgfullpath}"|sed 's/rcon_password //g'|sed 's/"//g')
  49. # Logging
  50. logdays="7"
  51. gamelogdir="${systemdir}/logs"
  52. scriptlogdir="${rootdir}/log/script"
  53. consolelogdir="${rootdir}/log/console"
  54. scriptlog="${scriptlogdir}/${servicename}-script.log"
  55. consolelog="${consolelogdir}/${servicename}-console.log"
  56. emaillog="${scriptlogdir}/${servicename}-email.log"
  57. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  58. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  59. ##### Script #####
  60. # Do not edit
  61. # unless you know
  62. # what you are doing
  63. fn_scriptlog(){
  64. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
  65. }
  66. # [ FAIL ]
  67. fn_printfail(){
  68. echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  69. }
  70. fn_printfailnl(){
  71. echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  72. }
  73. # [ OK ]
  74. fn_printok(){
  75. echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  76. }
  77. fn_printoknl(){
  78. echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  79. }
  80. # [ INFO ]
  81. fn_printinfo(){
  82. echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  83. }
  84. fn_printinfonl(){
  85. echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  86. }
  87. # [ WARN ]
  88. fn_printwarn(){
  89. echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  90. }
  91. fn_printwarnnl(){
  92. echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  93. }
  94. # [ .... ]
  95. fn_printdots(){
  96. echo -en "\r\033[K[ .... ] $@"
  97. }
  98. fn_rootcheck(){
  99. functionfile="${FUNCNAME}"
  100. fn_runfunction
  101. }
  102. fn_syscheck(){
  103. if [ ! -e "${systemdir}" ]; then
  104. fn_printfailnl "Cannot access ${systemdir}: No such directory"
  105. exit
  106. fi
  107. }
  108. fn_autoip(){
  109. functionfile="${FUNCNAME}"
  110. fn_runfunction
  111. }
  112. fn_logmanager(){
  113. functionfile="${FUNCNAME}"
  114. fn_runfunction
  115. }
  116. fn_debugserver(){
  117. functionfile="${FUNCNAME}"
  118. fn_runfunction
  119. }
  120. fn_console(){
  121. functionfile="${FUNCNAME}"
  122. fn_runfunction
  123. }
  124. fn_backupserver(){
  125. functionfile="${FUNCNAME}"
  126. fn_runfunction
  127. }
  128. fn_distro(){
  129. functionfile="${FUNCNAME}"
  130. fn_runfunction
  131. }
  132. fn_uptime(){
  133. functionfile="${FUNCNAME}"
  134. fn_runfunction
  135. }
  136. fn_load(){
  137. functionfile="${FUNCNAME}"
  138. fn_runfunction
  139. }
  140. fn_emailnotification(){
  141. functionfile="${FUNCNAME}"
  142. fn_runfunction
  143. }
  144. fn_emailtest(){
  145. functionfile="${FUNCNAME}"
  146. fn_runfunction
  147. }
  148. fn_serverquery(){
  149. functionfile="${FUNCNAME}"
  150. fn_runfunction
  151. }
  152. fn_monitorserver(){
  153. functionfile="${FUNCNAME}"
  154. fn_runfunction
  155. }
  156. fn_updateserver(){
  157. functionfile="${FUNCNAME}"
  158. fn_runfunction
  159. }
  160. fn_validateserver(){
  161. functionfile="${FUNCNAME}"
  162. fn_runfunction
  163. }
  164. fn_restartserver(){
  165. fn_scriptlog "Restarting ${servername}"
  166. fn_stopserver
  167. fn_startserver
  168. }
  169. fn_stopserver(){
  170. functionfile="${FUNCNAME}"
  171. fn_runfunction
  172. }
  173. fn_startserver(){
  174. functionfile="${FUNCNAME}"
  175. fn_runfunction
  176. }
  177. fn_details(){
  178. functionfile="${FUNCNAME}"
  179. fn_runfunction
  180. }
  181. fn_runfunction(){
  182. # Download function if missing
  183. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  184. cd "${rootdir}"
  185. if [ ! -d "functions" ]; then
  186. mkdir functions
  187. fi
  188. echo "loading ${functionfile}..."
  189. cd functions
  190. wget --no-check-certificate -nv -N https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile}
  191. chmod +x "${functionfile}"
  192. cd "${rootdir}"
  193. sleep 1
  194. echo ""
  195. fi
  196. # Run function
  197. source "${rootdir}/functions/${functionfile}"
  198. }
  199. #
  200. ## Installer
  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_loginstall
  249. fn_getquery
  250. fn_serverconfig
  251. fn_header
  252. fn_details
  253. echo "================================="
  254. echo "Install Complete!"
  255. echo ""
  256. echo "To start server type:"
  257. echo "${selfname} start"
  258. echo ""
  259. }
  260. fn_autoinstall(){
  261. autoinstall=1
  262. fn_install
  263. }
  264. case "$1" in
  265. start)
  266. fn_startserver;;
  267. stop)
  268. fn_stopserver;;
  269. restart)
  270. fn_restartserver;;
  271. update)
  272. fn_updateserver;;
  273. update-restart)
  274. fn_stopserver
  275. fn_updateserver
  276. fn_startserver;;
  277. validate)
  278. fn_validateserver;;
  279. validate-restart)
  280. fn_stopserver
  281. fn_validateserver
  282. fn_startserver;;
  283. monitor)
  284. fn_monitorserver;;
  285. email-test)
  286. fn_emailtest;;
  287. details)
  288. fn_details;;
  289. backup)
  290. fn_backupserver;;
  291. console)
  292. fn_console;;
  293. debug)
  294. fn_debugserver;;
  295. install)
  296. fn_install;;
  297. auto-install)
  298. fn_autoinstall;;
  299. *)
  300. echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install}"
  301. exit 1;;
  302. esac
  303. exit