gmodserver 3.3 KB

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