gmodserver 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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="190216"
  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. updateonstart="off"
  33. # Optional: Game Server Login Token
  34. # GSLT can be used for running a public server.
  35. # More info: http://gameservermanagers.com/gslt
  36. gslt=""
  37. # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
  38. fn_parms(){
  39. parms="-game garrysmod -strictportbind -ip ${ip} -port ${port} +host_workshop_collection ${workshopcollectionid} -authkey ${workshopauth} +clientport ${clientport} +tv_port ${sourcetvport} +gamemode ${gamemode} +map ${defaultmap} +sv_setsteamaccount ${gslt} +servercfgfile ${servercfg} -maxplayers ${maxplayers}"
  40. }
  41. #### Advanced Variables ####
  42. # Github Branch Select
  43. # Allows for the use of different function files
  44. # from a different repo and/or branch.
  45. githubuser="dgibbs64"
  46. githubrepo="linuxgsm"
  47. githubbranch="master"
  48. # Steam
  49. appid="4020"
  50. # Server Details
  51. servicename="gmod-server"
  52. gamename="Garry's Mod"
  53. engine="source"
  54. # Directories
  55. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  56. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  57. lockselfname=".${servicename}.lock"
  58. filesdir="${rootdir}/serverfiles"
  59. systemdir="${filesdir}/garrysmod"
  60. addonsdir="${systemdir}/addons"
  61. executabledir="${filesdir}"
  62. executable="./srcds_run"
  63. servercfg="${servicename}.cfg"
  64. servercfgdir="${systemdir}/cfg"
  65. servercfgfullpath="${servercfgdir}/${servercfg}"
  66. servercfgdefault="${servercfgdir}/lgsm-default.cfg"
  67. backupdir="${rootdir}/backups"
  68. # Logging
  69. logdays="7"
  70. gamelogdir="${systemdir}/logs"
  71. scriptlogdir="${rootdir}/log/script"
  72. consolelogdir="${rootdir}/log/console"
  73. scriptlog="${scriptlogdir}/${servicename}-script.log"
  74. consolelog="${consolelogdir}/${servicename}-console.log"
  75. emaillog="${scriptlogdir}/${servicename}-email.log"
  76. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  77. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  78. ##### Script #####
  79. # Do not edit
  80. fn_getgithubfile(){
  81. filename=$1
  82. exec=$2
  83. fileurl=${3:-$filename}
  84. filepath="${rootdir}/${filename}"
  85. filedir=$(dirname "${filepath}")
  86. # If the function file is missing, then download
  87. if [ ! -f "${filepath}" ]; then
  88. if [ ! -d "${filedir}" ]; then
  89. mkdir "${filedir}"
  90. fi
  91. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${fileurl}"
  92. echo -e " fetching ${filename}...\c"
  93. if [ "$(command -v curl)" ]||[ "$(which curl >/dev/null 2>&1)" ]||[ -f "/usr/bin/curl" ]||[ -f "/bin/curl" ]; then
  94. :
  95. else
  96. echo -e "\e[0;31mFAIL\e[0m\n"
  97. echo "Curl is not installed!"
  98. echo -e ""
  99. exit
  100. fi
  101. curl=$(curl --fail -o "${filepath}" "${githuburl}" 2>&1)
  102. if [ $? -ne 0 ]; then
  103. echo -e "\e[0;31mFAIL\e[0m\n"
  104. echo "${curl}"
  105. echo -e "${githuburl}\n"
  106. exit
  107. else
  108. echo -e "\e[0;32mOK\e[0m"
  109. fi
  110. if [ "${exec}" ]; then
  111. chmod +x "${filepath}"
  112. fi
  113. fi
  114. if [ "${exec}" ]; then
  115. source "${filepath}"
  116. fi
  117. }
  118. fn_runfunction(){
  119. fn_getgithubfile "functions/${functionfile}" 1
  120. }
  121. core_functions.sh(){
  122. # Functions are defined in core_functions.sh.
  123. functionfile="${FUNCNAME}"
  124. fn_runfunction
  125. }
  126. core_functions.sh
  127. getopt=$1
  128. core_getopt.sh