l4d2server 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/bin/bash
  2. # Left 4 Dead 2
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: https://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="210516"
  12. #### Variables ####
  13. # Notification Alerts
  14. # (on|off)
  15. # Email
  16. emailalert="off"
  17. email="email@example.com"
  18. # Pushbullet
  19. # https://www.pushbullet.com/#settings
  20. pushbulletalert="off"
  21. pushbullettoken="accesstoken"
  22. # Steam login
  23. steamuser="anonymous"
  24. steampass=""
  25. # Start Variables
  26. defaultmap="c5m1_waterfront"
  27. maxplayers="8"
  28. port="27015"
  29. clientport="27005"
  30. ip="0.0.0.0"
  31. updateonstart="off"
  32. # https://developer.valvesoftware.com/wiki/Command_Line_Options#Source_Dedicated_Server
  33. fn_parms(){
  34. parms="-game left4dead2 -strictportbind -ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} +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="222860"
  45. # Server Details
  46. servicename="l4d2-server"
  47. gamename="Left 4 Dead 2"
  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. lgsmdir="${rootdir}/lgsm"
  54. functionsdir="${lgsmdir}/functions"
  55. filesdir="${rootdir}/serverfiles"
  56. systemdir="${filesdir}/left4dead2"
  57. executabledir="${filesdir}"
  58. executable="./srcds_run"
  59. servercfg="${servicename}.cfg"
  60. servercfgdir="${systemdir}/cfg"
  61. servercfgfullpath="${servercfgdir}/${servercfg}"
  62. servercfgdefault="${servercfgdir}/lgsm-default.cfg"
  63. backupdir="${rootdir}/backups"
  64. # Logging
  65. logdays="7"
  66. gamelogdir="${systemdir}/logs"
  67. scriptlogdir="${rootdir}/log/script"
  68. consolelogdir="${rootdir}/log/console"
  69. consolelogging="on"
  70. scriptlog="${scriptlogdir}/${servicename}-script.log"
  71. consolelog="${consolelogdir}/${servicename}-console.log"
  72. emaillog="${scriptlogdir}/${servicename}-email.log"
  73. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
  74. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
  75. ##### Script #####
  76. # Do not edit
  77. # Fetches core_dl for file downloads
  78. fn_fetch_core_dl(){
  79. github_file_url_dir="lgsm/functions"
  80. github_file_url_name="${functionfile}"
  81. filedir="${functionsdir}"
  82. filename="${github_file_url_name}"
  83. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  84. # If the file is missing, then download
  85. if [ ! -f "${filedir}/${filename}" ]; then
  86. if [ ! -d "${filedir}" ]; then
  87. mkdir -p "${filedir}"
  88. fi
  89. echo -e " fetching ${filename}...\c"
  90. # Check curl exists and use available path
  91. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  92. for curlcmd in ${curlpaths}
  93. do
  94. if [ -x "${curlcmd}" ]; then
  95. break
  96. fi
  97. done
  98. # If curl exists download file
  99. if [ "$(basename ${curlcmd})" == "curl" ]; then
  100. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  101. if [ $? -ne 0 ]; then
  102. echo -e "\e[0;31mFAIL\e[0m\n"
  103. echo "${curlfetch}"
  104. echo -e "${githuburl}\n"
  105. exit 1
  106. else
  107. echo -e "\e[0;32mOK\e[0m"
  108. fi
  109. else
  110. echo -e "\e[0;31mFAIL\e[0m\n"
  111. echo "Curl is not installed!"
  112. echo -e ""
  113. exit 1
  114. fi
  115. chmod +x "${filedir}/${filename}"
  116. fi
  117. source "${filedir}/${filename}"
  118. }
  119. core_dl.sh(){
  120. # Functions are defined in core_functions.sh.
  121. functionfile="${FUNCNAME}"
  122. fn_fetch_core_dl
  123. }
  124. core_functions.sh(){
  125. # Functions are defined in core_functions.sh.
  126. functionfile="${FUNCNAME}"
  127. fn_fetch_core_dl
  128. }
  129. core_dl.sh
  130. core_functions.sh
  131. getopt=$1
  132. core_getopt.sh