csgoserver 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #!/bin/bash
  2. # Counter Strike: Global Offensive
  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. # https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Dedicated_Servers#Starting_the_Server
  17. # [Game Modes] gametype gamemode
  18. # Arms Race 1 0
  19. # Classic Casual 0 0
  20. # Classic Competitive 0 1
  21. # Demolition 1 1
  22. # Deathmatch 1 2
  23. gamemode="0"
  24. gametype="0"
  25. defaultmap="de_dust2"
  26. mapgroup="random_classic"
  27. maxplayers="16"
  28. tickrate="64"
  29. port="27015"
  30. sourcetvport="27020"
  31. clientport="27005"
  32. ip="0.0.0.0"
  33. # Optional: Workshop Parameters
  34. # https://developer.valvesoftware.com/wiki/CSGO_Workshop_For_Server_Operators
  35. # To get an authkey visit - http://steamcommunity.com/dev/apikey
  36. # authkey=""
  37. # ws_collection_id=""
  38. # ws_start_map=""
  39. # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
  40. fn_parms(){
  41. parms="-game csgo -usercon -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +tv_port ${sourcetvport} -tickrate ${tickrate} +map ${defaultmap} +servercfgfile ${servercfg} -maxplayers_override ${maxplayers} +mapgroup ${mapgroup} +game_mode ${gamemode} +game_type ${gametype} +host_workshop_collection ${ws_collection_id} +workshop_start_map ${ws_start_map} -authkey ${authkey}"
  42. }
  43. #### Advanced Variables ####
  44. # Steam
  45. appid="740"
  46. # Server Details
  47. servicename="csgo-server"
  48. gamename="Counter Strike: Global Offensive"
  49. engine="source"
  50. # Directories
  51. rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )"
  52. selfname="$0"
  53. lockselfname=$(echo ".${servicename}.lock")
  54. filesdir="${rootdir}/serverfiles"
  55. systemdir="${filesdir}/csgo"
  56. executabledir="${filesdir}"
  57. executable="./srcds_run"
  58. servercfgdir="${systemdir}/cfg"
  59. servercfg="${servicename}.cfg"
  60. servercfgfullpath="${servercfgdir}/${servercfg}"
  61. defaultcfg="${servercfgdir}/server.cfg"
  62. backupdir="backups"
  63. # Server Details
  64. servername=$(grep -s hostname "${servercfgfullpath}"|sed 's/hostname //g'|sed 's/"//g')
  65. rcon=$(grep -s rcon_password "${servercfgfullpath}"|sed 's/rcon_password //g'|sed 's/"//g')
  66. # Logging
  67. logdays="7"
  68. gamelogdir="${systemdir}/logs"
  69. scriptlogdir="${rootdir}/log/script"
  70. consolelogdir="${rootdir}/log/console"
  71. scriptlog="${scriptlogdir}/${servicename}-script.log"
  72. consolelog="${consolelogdir}/${servicename}-console.log"
  73. emaillog="${scriptlogdir}/${servicename}-email.log"
  74. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  75. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  76. ##### Script #####
  77. # Do not edit
  78. # unless you know
  79. # what you are doing
  80. fn_scriptlog(){
  81. echo -e "$(date '+%b %d %H:%M:%S') ${servicename}: ${1}" >> "${scriptlog}"
  82. }
  83. # [ FAIL ]
  84. fn_printfail(){
  85. echo -en "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  86. }
  87. fn_printfailnl(){
  88. echo -e "\r\033[K[\e[0;31m FAIL \e[0;39m] $@"
  89. }
  90. # [ OK ]
  91. fn_printok(){
  92. echo -en "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  93. }
  94. fn_printoknl(){
  95. echo -e "\r\033[K[\e[0;32m OK \e[0;39m] $@"
  96. }
  97. # [ INFO ]
  98. fn_printinfo(){
  99. echo -en "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  100. }
  101. fn_printinfonl(){
  102. echo -e "\r\033[K[\e[0;36m INFO \e[0;39m] $@"
  103. }
  104. # [ WARN ]
  105. fn_printwarn(){
  106. echo -en "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  107. }
  108. fn_printwarnnl(){
  109. echo -e "\r\033[K[\e[1;33m WARN \e[0;39m] $@"
  110. }
  111. # [ .... ]
  112. fn_printdots(){
  113. echo -en "\r\033[K[ .... ] $@"
  114. }
  115. fn_rootcheck(){
  116. functionfile="${FUNCNAME}"
  117. fn_runfunction
  118. }
  119. fn_syscheck(){
  120. if [ ! -e "${systemdir}" ]; then
  121. fn_printfailnl "Cannot access ${systemdir}: No such directory"
  122. exit
  123. fi
  124. }
  125. fn_autoip(){
  126. functionfile="${FUNCNAME}"
  127. fn_runfunction
  128. }
  129. fn_logmanager(){
  130. functionfile="${FUNCNAME}"
  131. fn_runfunction
  132. }
  133. fn_debugserver(){
  134. functionfile="${FUNCNAME}"
  135. fn_runfunction
  136. }
  137. fn_console(){
  138. functionfile="${FUNCNAME}"
  139. fn_runfunction
  140. }
  141. fn_backupserver(){
  142. functionfile="${FUNCNAME}"
  143. fn_runfunction
  144. }
  145. fn_distro(){
  146. functionfile="${FUNCNAME}"
  147. fn_runfunction
  148. }
  149. fn_uptime(){
  150. functionfile="${FUNCNAME}"
  151. fn_runfunction
  152. }
  153. fn_load(){
  154. functionfile="${FUNCNAME}"
  155. fn_runfunction
  156. }
  157. fn_emailnotification(){
  158. functionfile="${FUNCNAME}"
  159. fn_runfunction
  160. }
  161. fn_emailtest(){
  162. functionfile="${FUNCNAME}"
  163. fn_runfunction
  164. }
  165. fn_serverquery(){
  166. functionfile="${FUNCNAME}"
  167. fn_runfunction
  168. }
  169. fn_monitorserver(){
  170. functionfile="${FUNCNAME}"
  171. fn_runfunction
  172. }
  173. fn_updateserver(){
  174. functionfile="${FUNCNAME}"
  175. fn_runfunction
  176. }
  177. fn_validateserver(){
  178. functionfile="${FUNCNAME}"
  179. fn_runfunction
  180. }
  181. fn_restartserver(){
  182. fn_scriptlog "Restarting ${servername}"
  183. fn_stopserver
  184. fn_startserver
  185. }
  186. fn_stopserver(){
  187. functionfile="${FUNCNAME}"
  188. fn_runfunction
  189. }
  190. fn_startserver(){
  191. functionfile="${FUNCNAME}"
  192. fn_runfunction
  193. }
  194. fn_details(){
  195. functionfile="${FUNCNAME}"
  196. fn_runfunction
  197. }
  198. fn_runfunction(){
  199. # Download function if missing
  200. if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
  201. cd "${rootdir}"
  202. if [ ! -d "functions" ]; then
  203. mkdir functions
  204. fi
  205. echo "loading ${functionfile}..."
  206. cd functions
  207. wget --no-check-certificate -nv -N https://raw.githubusercontent.com/dgibbs64/linuxgameservers/master/functions/${functionfile}
  208. chmod +x "${functionfile}"
  209. cd "${rootdir}"
  210. sleep 1
  211. echo ""
  212. fi
  213. # Run function
  214. source "${rootdir}/functions/${functionfile}"
  215. }
  216. #
  217. ## Installer
  218. #
  219. fn_csgofix(){
  220. functionfile="${FUNCNAME}"
  221. fn_runfunction
  222. }
  223. fn_header(){
  224. functionfile="${FUNCNAME}"
  225. fn_runfunction
  226. }
  227. fn_steamdl(){
  228. functionfile="${FUNCNAME}"
  229. fn_runfunction
  230. }
  231. fn_steaminstall(){
  232. functionfile="${FUNCNAME}"
  233. fn_runfunction
  234. }
  235. fn_steamfix(){
  236. functionfile="${FUNCNAME}"
  237. fn_runfunction
  238. }
  239. fn_loginstall(){
  240. functionfile="${FUNCNAME}"
  241. fn_runfunction
  242. }
  243. fn_getquery(){
  244. functionfile="${FUNCNAME}"
  245. fn_runfunction
  246. }
  247. fn_retryinstall(){
  248. functionfile="${FUNCNAME}"
  249. fn_runfunction
  250. }
  251. fn_serverdirectory(){
  252. functionfile="${FUNCNAME}"
  253. fn_runfunction
  254. }
  255. fn_serverconfig(){
  256. functionfile="${FUNCNAME}"
  257. fn_runfunction
  258. }
  259. fn_install(){
  260. fn_rootcheck
  261. fn_header
  262. if [ -z "${autoinstall}" ]; then
  263. fn_serverdirectory
  264. fn_header
  265. fi
  266. fn_steamdl
  267. fn_steaminstall
  268. fn_steamfix
  269. fn_loginstall
  270. fn_getquery
  271. fn_serverconfig
  272. fn_csgofix
  273. fn_header
  274. fn_details
  275. echo "================================="
  276. echo "Install Complete!"
  277. echo ""
  278. echo "To start server type:"
  279. echo "${selfname} start"
  280. echo ""
  281. }
  282. fn_autoinstall(){
  283. autoinstall=1
  284. fn_install
  285. }
  286. case "$1" in
  287. start)
  288. fn_startserver;;
  289. stop)
  290. fn_stopserver;;
  291. restart)
  292. fn_restartserver;;
  293. update)
  294. fn_updateserver;;
  295. update-restart)
  296. fn_stopserver
  297. fn_updateserver
  298. fn_startserver;;
  299. validate)
  300. fn_validateserver;;
  301. validate-restart)
  302. fn_stopserver
  303. fn_validateserver
  304. fn_startserver;;
  305. monitor)
  306. fn_monitorserver;;
  307. email-test)
  308. fn_emailtest;;
  309. details)
  310. fn_details;;
  311. backup)
  312. fn_backupserver;;
  313. console)
  314. fn_console;;
  315. debug)
  316. fn_debugserver;;
  317. install)
  318. fn_install;;
  319. auto-install)
  320. fn_autoinstall;;
  321. *)
  322. echo "Usage: $0 {start|stop|restart|update|update-restart|validate|validate-restart|monitor|email-test|details|backup|console|debug|install|auto-install}"
  323. exit 1;;
  324. esac
  325. exit