gmodserver 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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="210516"
  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. # Server Details
  65. servicename="gmod-server"
  66. gamename="Garry's Mod"
  67. engine="source"
  68. # Directories
  69. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  70. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  71. lockselfname=".${servicename}.lock"
  72. lgsmdir="${rootdir}/lgsm"
  73. functionsdir="${lgsmdir}/functions"
  74. libdir="${lgsmdir}/lib"
  75. filesdir="${rootdir}/serverfiles"
  76. systemdir="${filesdir}/garrysmod"
  77. addonsdir="${systemdir}/addons"
  78. executabledir="${filesdir}"
  79. executable="./srcds_run"
  80. servercfg="${servicename}.cfg"
  81. servercfgdir="${systemdir}/cfg"
  82. servercfgfullpath="${servercfgdir}/${servercfg}"
  83. servercfgdefault="${servercfgdir}/lgsm-default.cfg"
  84. backupdir="${rootdir}/backups"
  85. # Logging
  86. logdays="7"
  87. gamelogdir="${systemdir}/logs"
  88. scriptlogdir="${rootdir}/log/script"
  89. consolelogdir="${rootdir}/log/console"
  90. consolelogging="on"
  91. scriptlog="${scriptlogdir}/${servicename}-script.log"
  92. consolelog="${consolelogdir}/${servicename}-console.log"
  93. emaillog="${scriptlogdir}/${servicename}-email.log"
  94. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  95. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  96. ##### Script #####
  97. # Do not edit
  98. # Fetches core_dl for file downloads
  99. fn_fetch_core_dl(){
  100. github_file_url_dir="lgsm/functions"
  101. github_file_url_name="${functionfile}"
  102. filedir="${functionsdir}"
  103. filename="${github_file_url_name}"
  104. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  105. # If the file is missing, then download
  106. if [ ! -f "${filedir}/${filename}" ]; then
  107. if [ ! -d "${filedir}" ]; then
  108. mkdir -p "${filedir}"
  109. fi
  110. echo -e " fetching ${filename}...\c"
  111. # Check curl exists and use available path
  112. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  113. for curlcmd in ${curlpaths}
  114. do
  115. if [ -x "${curlcmd}" ]; then
  116. break
  117. fi
  118. done
  119. # If curl exists download file
  120. if [ "$(basename ${curlcmd})" == "curl" ]; then
  121. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  122. if [ $? -ne 0 ]; then
  123. echo -e "\e[0;31mFAIL\e[0m\n"
  124. echo "${curlfetch}"
  125. echo -e "${githuburl}\n"
  126. exit 1
  127. else
  128. echo -e "\e[0;32mOK\e[0m"
  129. fi
  130. else
  131. echo -e "\e[0;31mFAIL\e[0m\n"
  132. echo "Curl is not installed!"
  133. echo -e ""
  134. exit 1
  135. fi
  136. chmod +x "${filedir}/${filename}"
  137. fi
  138. source "${filedir}/${filename}"
  139. }
  140. core_dl.sh(){
  141. # Functions are defined in core_functions.sh.
  142. functionfile="${FUNCNAME}"
  143. fn_fetch_core_dl
  144. }
  145. core_functions.sh(){
  146. # Functions are defined in core_functions.sh.
  147. functionfile="${FUNCNAME}"
  148. fn_fetch_core_dl
  149. }
  150. core_dl.sh
  151. core_functions.sh
  152. getopt=$1
  153. core_getopt.sh