gmodserver 4.3 KB

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