gmodserver 4.4 KB

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