gmodserver 3.5 KB

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