csserver 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. # Counter-Strike
  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="060816"
  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="de_dust2"
  27. maxplayers="16"
  28. port="27015"
  29. clientport="27005"
  30. ip="0.0.0.0"
  31. updateonstart="off"
  32. # https://developer.valvesoftware.com/wiki/Command_Line_Options#Command-line_parameters_2
  33. fn_parms(){
  34. parms="-game cstrike -strictportbind +ip ${ip} -port ${port} +clientport ${clientport} +map ${defaultmap} -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="GameServerManagers"
  41. githubrepo="LinuxGSM"
  42. githubbranch="master"
  43. # Steam
  44. appid="90"
  45. appidmod="cstrike"
  46. # Server Details
  47. servicename="cs-server"
  48. gamename="Counter-Strike 1.6"
  49. engine="goldsource"
  50. # Directories
  51. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  52. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  53. lockselfname=".${servicename}.lock"
  54. lgsmdir="${rootdir}/lgsm"
  55. functionsdir="${lgsmdir}/functions"
  56. libdir="${lgsmdir}/lib"
  57. tmpdir="${lgsmdir}/tmp"
  58. filesdir="${rootdir}/serverfiles"
  59. systemdir="${filesdir}/cstrike"
  60. executabledir="${filesdir}"
  61. executable="./hlds_run"
  62. servercfg="${servicename}.cfg"
  63. servercfgdir="${systemdir}"
  64. servercfgfullpath="${servercfgdir}/${servercfg}"
  65. servercfgdefault="${servercfgdir}/lgsm-default.cfg"
  66. backupdir="${rootdir}/backups"
  67. # Logging
  68. logdays="7"
  69. gamelogdir="${systemdir}/logs"
  70. scriptlogdir="${rootdir}/log/script"
  71. consolelogdir="${rootdir}/log/console"
  72. consolelogging="on"
  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. # Fetches core_dl for file downloads
  81. fn_fetch_core_dl(){
  82. github_file_url_dir="lgsm/functions"
  83. github_file_url_name="${functionfile}"
  84. filedir="${functionsdir}"
  85. filename="${github_file_url_name}"
  86. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  87. # If the file is missing, then download
  88. if [ ! -f "${filedir}/${filename}" ]; then
  89. if [ ! -d "${filedir}" ]; then
  90. mkdir -p "${filedir}"
  91. fi
  92. echo -e " fetching ${filename}...\c"
  93. # Check curl exists and use available path
  94. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  95. for curlcmd in ${curlpaths}
  96. do
  97. if [ -x "${curlcmd}" ]; then
  98. break
  99. fi
  100. done
  101. # If curl exists download file
  102. if [ "$(basename ${curlcmd})" == "curl" ]; then
  103. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  104. if [ $? -ne 0 ]; then
  105. echo -e "\e[0;31mFAIL\e[0m\n"
  106. echo "${curlfetch}"
  107. echo -e "${githuburl}\n"
  108. exit 1
  109. else
  110. echo -e "\e[0;32mOK\e[0m"
  111. fi
  112. else
  113. echo -e "\e[0;31mFAIL\e[0m\n"
  114. echo "Curl is not installed!"
  115. echo -e ""
  116. exit 1
  117. fi
  118. chmod +x "${filedir}/${filename}"
  119. fi
  120. source "${filedir}/${filename}"
  121. }
  122. core_dl.sh(){
  123. # Functions are defined in core_functions.sh.
  124. functionfile="${FUNCNAME}"
  125. fn_fetch_core_dl
  126. }
  127. core_functions.sh(){
  128. # Functions are defined in core_functions.sh.
  129. functionfile="${FUNCNAME}"
  130. fn_fetch_core_dl
  131. }
  132. core_dl.sh
  133. core_functions.sh
  134. getopt=$1
  135. core_getopt.sh