gmodserver 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2016 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="161125"
  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. # Edit with care | https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
  41. fn_parms(){
  42. 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}"
  43. }
  44. #### LinuxGSM Settings ####
  45. ## Notification Alerts
  46. # (on|off]
  47. # Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
  48. emailalert="off"
  49. email="email@example.com"
  50. emailfrom=""
  51. # Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
  52. pushbulletalert="off"
  53. pushbullettoken="accesstoken"
  54. channeltag=""
  55. ## Updating | https://github.com/GameServerManagers/LinuxGSM/wiki/Update
  56. updateonstart="off"
  57. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  58. maxbackups="4"
  59. maxbackupdays="30"
  60. stoponbackup="on"
  61. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  62. consolelogging="on"
  63. logdays="7"
  64. #### LinuxGSM Advanced Settings ####
  65. ## SteamCMD Settings
  66. # Server appid
  67. appid="4020"
  68. # Steam App Branch Select
  69. # Allows to opt into the various Steam app branches. Default branch is "".
  70. # Example: "-beta latest_experimental"
  71. branch=""
  72. ## Github Branch Select
  73. # Allows for the use of different function files
  74. # from a different repo and/or branch.
  75. githubuser="GameServerManagers"
  76. githubrepo="LinuxGSM"
  77. githubbranch="master"
  78. ## LinuxGSM Server Details
  79. # Do not edit
  80. gamename="Garry's Mod"
  81. engine="source"
  82. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  83. servicename="gmod-server"
  84. #### Directories ####
  85. # Edit with care
  86. ## Work Directories
  87. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  88. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  89. lockselfname=".${servicename}.lock"
  90. lgsmdir="${rootdir}/lgsm"
  91. functionsdir="${lgsmdir}/functions"
  92. libdir="${lgsmdir}/lib"
  93. tmpdir="${lgsmdir}/tmp"
  94. filesdir="${rootdir}/serverfiles"
  95. ## Server Specific Directories
  96. systemdir="${filesdir}/garrysmod"
  97. addonsdir="${systemdir}/addons"
  98. executabledir="${filesdir}"
  99. executable="./srcds_run"
  100. servercfg="${servicename}.cfg"
  101. servercfgdefault="server.cfg"
  102. servercfgdir="${systemdir}/cfg"
  103. servercfgfullpath="${servercfgdir}/${servercfg}"
  104. ## Backup Directory
  105. backupdir="${rootdir}/backups"
  106. ## Logging Directories
  107. gamelogdir="${systemdir}/logs"
  108. scriptlogdir="${rootdir}/log/script"
  109. consolelogdir="${rootdir}/log/console"
  110. scriptlog="${scriptlogdir}/${servicename}-script.log"
  111. consolelog="${consolelogdir}/${servicename}-console.log"
  112. emaillog="${scriptlogdir}/${servicename}-email.log"
  113. ## Logs Naming
  114. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  115. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
  116. ########################
  117. ######## Script ########
  118. ###### Do not edit #####
  119. ########################
  120. # Fetches core_dl for file downloads
  121. fn_fetch_core_dl(){
  122. github_file_url_dir="lgsm/functions"
  123. github_file_url_name="${functionfile}"
  124. filedir="${functionsdir}"
  125. filename="${github_file_url_name}"
  126. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  127. # If the file is missing, then download
  128. if [ ! -f "${filedir}/${filename}" ]; then
  129. if [ ! -d "${filedir}" ]; then
  130. mkdir -p "${filedir}"
  131. fi
  132. echo -e " fetching ${filename}...\c"
  133. # Check curl exists and use available path
  134. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  135. for curlcmd in ${curlpaths}
  136. do
  137. if [ -x "${curlcmd}" ]; then
  138. break
  139. fi
  140. done
  141. # If curl exists download file
  142. if [ "$(basename ${curlcmd})" == "curl" ]; then
  143. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  144. if [ $? -ne 0 ]; then
  145. echo -e "\e[0;31mFAIL\e[0m\n"
  146. echo "${curlfetch}"
  147. echo -e "${githuburl}\n"
  148. exit 1
  149. else
  150. echo -e "\e[0;32mOK\e[0m"
  151. fi
  152. else
  153. echo -e "\e[0;31mFAIL\e[0m\n"
  154. echo "Curl is not installed!"
  155. echo -e ""
  156. exit 1
  157. fi
  158. chmod +x "${filedir}/${filename}"
  159. fi
  160. source "${filedir}/${filename}"
  161. }
  162. core_dl.sh(){
  163. # Functions are defined in core_functions.sh.
  164. functionfile="${FUNCNAME}"
  165. fn_fetch_core_dl
  166. }
  167. core_functions.sh(){
  168. # Functions are defined in core_functions.sh.
  169. functionfile="${FUNCNAME}"
  170. fn_fetch_core_dl
  171. }
  172. # Prevent from running this script as root.
  173. if [ "$(whoami)" = "root" ]; then
  174. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  175. echo "[ FAIL ] Do NOT run this script as root!"
  176. exit 1
  177. else
  178. core_functions.sh
  179. check_root.sh
  180. fi
  181. fi
  182. core_dl.sh
  183. core_functions.sh
  184. getopt=$1
  185. core_getopt.sh