gmodserver 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2017 Daniel Gibbs
  5. # Purpose: Garry's Mod | Server Management Script
  6. # Contributors: https://github.com/GameServerManagers/LinuxGSM/graphs/contributors
  7. # Documentation: https://github.com/GameServerManagers/LinuxGSM/wiki
  8. # Website: https://gameservermanagers.com
  9. # Debugging
  10. if [ -f ".dev-debug" ]; then
  11. exec 5>dev-debug.log
  12. BASH_XTRACEFD="5"
  13. set -x
  14. fi
  15. version="170530"
  16. ##########################
  17. ######## Settings ########
  18. ##########################
  19. #### Server Settings ####
  20. ## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
  21. defaultmap="gm_construct"
  22. gamemode="sandbox"
  23. maxplayers="16"
  24. port="27015"
  25. sourcetvport="27020"
  26. clientport="27005"
  27. tickrate="66"
  28. ip="0.0.0.0"
  29. ## Workshop Parameters | http://wiki.garrysmod.com/page/Workshop_for_Dedicated_Servers
  30. workshopauth=""
  31. workshopcollectionid=""
  32. ## Custom Start Parameters
  33. # Default +r_hunkalloclightmaps 0, fixes a start issue on maps with many lights
  34. customparms="+r_hunkalloclightmaps 0"
  35. ## Optional: Game Server Login Token
  36. # GSLT can be used for running a public server.
  37. # More info: https://gameservermanagers.com/gslt
  38. gslt=""
  39. ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
  40. fn_parms(){
  41. parms="-game garrysmod -strictportbind -ip ${ip} -port ${port} -tickrate ${tickrate} +host_workshop_collection ${workshopcollectionid} -authkey ${workshopauth} +clientport ${clientport} +tv_port ${sourcetvport} +gamemode ${gamemode} +map ${defaultmap} +sv_setsteamaccount ${gslt} +servercfgfile ${servercfg} -maxplayers ${maxplayers} ${customparms}"
  42. }
  43. #### LinuxGSM Settings ####
  44. ## Notification Alerts
  45. # (on|off)
  46. # Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
  47. emailalert="off"
  48. email="email@example.com"
  49. emailfrom=""
  50. # Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
  51. pushbulletalert="off"
  52. pushbullettoken="accesstoken"
  53. channeltag=""
  54. ## Updating | https://github.com/GameServerManagers/LinuxGSM/wiki/Update
  55. updateonstart="off"
  56. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  57. maxbackups="4"
  58. maxbackupdays="30"
  59. stoponbackup="on"
  60. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  61. consolelogging="on"
  62. logdays="7"
  63. #### LinuxGSM Advanced Settings ####
  64. ## SteamCMD Settings
  65. # Server appid
  66. appid="4020"
  67. # Steam App Branch Select
  68. # Allows to opt into the various Steam app branches. Default branch is "".
  69. # Example: "-beta latest_experimental"
  70. branch=""
  71. ## Github Branch Select
  72. # Allows for the use of different function files
  73. # from a different repo and/or branch.
  74. githubuser="GameServerManagers"
  75. githubrepo="LinuxGSM"
  76. githubbranch="master"
  77. ## LinuxGSM Server Details
  78. # Do not edit
  79. gamename="Garry's Mod"
  80. engine="source"
  81. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  82. servicename="gmod-server"
  83. #### Directories ####
  84. # Edit with care
  85. ## Work Directories
  86. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  87. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  88. lockselfname=".${servicename}.lock"
  89. lgsmdir="${rootdir}/lgsm"
  90. functionsdir="${lgsmdir}/functions"
  91. libdir="${lgsmdir}/lib"
  92. tmpdir="${lgsmdir}/tmp"
  93. filesdir="${rootdir}/serverfiles"
  94. ## Server Specific Directories
  95. systemdir="${filesdir}/garrysmod"
  96. addonsdir="${systemdir}/addons"
  97. executabledir="${filesdir}"
  98. executable="./srcds_run"
  99. servercfg="${servicename}.cfg"
  100. servercfgdefault="server.cfg"
  101. servercfgdir="${systemdir}/cfg"
  102. servercfgfullpath="${servercfgdir}/${servercfg}"
  103. ## Backup Directory
  104. backupdir="${rootdir}/backups"
  105. ## Logging Directories
  106. gamelogdir="${systemdir}/logs"
  107. scriptlogdir="${rootdir}/log/script"
  108. consolelogdir="${rootdir}/log/console"
  109. scriptlog="${scriptlogdir}/${servicename}-script.log"
  110. consolelog="${consolelogdir}/${servicename}-console.log"
  111. emaillog="${scriptlogdir}/${servicename}-email.log"
  112. ## Logs Naming
  113. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  114. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
  115. ########################
  116. ######## Script ########
  117. ###### Do not edit #####
  118. ########################
  119. # Fetches core_dl for file downloads
  120. fn_fetch_core_dl(){
  121. github_file_url_dir="lgsm/functions"
  122. github_file_url_name="${functionfile}"
  123. filedir="${functionsdir}"
  124. filename="${github_file_url_name}"
  125. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  126. # If the file is missing, then download
  127. if [ ! -f "${filedir}/${filename}" ]; then
  128. if [ ! -d "${filedir}" ]; then
  129. mkdir -p "${filedir}"
  130. fi
  131. echo -e " fetching ${filename}...\c"
  132. # Check curl exists and use available path
  133. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  134. for curlcmd in ${curlpaths}
  135. do
  136. if [ -x "${curlcmd}" ]; then
  137. break
  138. fi
  139. done
  140. # If curl exists download file
  141. if [ "$(basename ${curlcmd})" == "curl" ]; then
  142. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  143. if [ $? -ne 0 ]; then
  144. echo -e "\e[0;31mFAIL\e[0m\n"
  145. echo "${curlfetch}"
  146. echo -e "${githuburl}\n"
  147. exit 1
  148. else
  149. echo -e "\e[0;32mOK\e[0m"
  150. fi
  151. else
  152. echo -e "\e[0;31mFAIL\e[0m\n"
  153. echo "Curl is not installed!"
  154. echo -e ""
  155. exit 1
  156. fi
  157. chmod +x "${filedir}/${filename}"
  158. fi
  159. source "${filedir}/${filename}"
  160. }
  161. core_dl.sh(){
  162. # Functions are defined in core_functions.sh.
  163. functionfile="${FUNCNAME}"
  164. fn_fetch_core_dl
  165. }
  166. core_functions.sh(){
  167. # Functions are defined in core_functions.sh.
  168. functionfile="${FUNCNAME}"
  169. fn_fetch_core_dl
  170. }
  171. # Prevent from running this script as root.
  172. if [ "$(whoami)" = "root" ]; then
  173. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  174. echo "[ FAIL ] Do NOT run this script as root!"
  175. exit 1
  176. else
  177. core_functions.sh
  178. check_root.sh
  179. fi
  180. fi
  181. core_dl.sh
  182. core_functions.sh
  183. getopt=$1
  184. core_getopt.sh