gmodserver 4.8 KB

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