4
0

gmodserver 6.4 KB

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