gmodserver 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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="130316"
  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. filesdir="${rootdir}/serverfiles"
  63. systemdir="${filesdir}/garrysmod"
  64. addonsdir="${systemdir}/addons"
  65. executabledir="${filesdir}"
  66. executable="./srcds_run"
  67. servercfg="${servicename}.cfg"
  68. servercfgdir="${systemdir}/cfg"
  69. servercfgfullpath="${servercfgdir}/${servercfg}"
  70. servercfgdefault="${servercfgdir}/lgsm-default.cfg"
  71. backupdir="${rootdir}/backups"
  72. # Logging
  73. logdays="7"
  74. gamelogdir="${systemdir}/logs"
  75. scriptlogdir="${rootdir}/log/script"
  76. consolelogdir="${rootdir}/log/console"
  77. scriptlog="${scriptlogdir}/${servicename}-script.log"
  78. consolelog="${consolelogdir}/${servicename}-console.log"
  79. emaillog="${scriptlogdir}/${servicename}-email.log"
  80. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  81. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  82. ##### Script #####
  83. # Do not edit
  84. fn_getgithubfile(){
  85. filename=$1
  86. exec=$2
  87. fileurl=${3:-$filename}
  88. filepath="${rootdir}/${filename}"
  89. filedir=$(dirname "${filepath}")
  90. # If the function file is missing, then download
  91. if [ ! -f "${filepath}" ]; then
  92. if [ ! -d "${filedir}" ]; then
  93. mkdir "${filedir}"
  94. fi
  95. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
  96. echo -e " fetching ${filename}...\c"
  97. if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then
  98. :
  99. else
  100. echo -e "\e[0;31mFAIL\e[0m\n"
  101. echo "Curl is not installed!"
  102. echo -e ""
  103. exit
  104. fi
  105. curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1)
  106. if [ $? -ne 0 ]; then
  107. echo -e "\e[0;31mFAIL\e[0m\n"
  108. echo "${curl}"
  109. echo -e "${githuburl}\n"
  110. exit
  111. else
  112. echo -e "\e[0;32mOK\e[0m"
  113. fi
  114. if [ "${exec}" ]; then
  115. chmod +x "${filepath}"
  116. fi
  117. fi
  118. if [ "${exec}" ]; then
  119. source "${filepath}"
  120. fi
  121. }
  122. fn_runfunction(){
  123. fn_getgithubfile "functions/${functionfile}" 1
  124. }
  125. core_functions.sh(){
  126. # Functions are defined in core_functions.sh.
  127. functionfile="${FUNCNAME}"
  128. fn_runfunction
  129. }
  130. core_functions.sh
  131. getopt=$1
  132. core_getopt.sh