q2server 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/bin/bash
  2. # Project: Game Server Managers - LinuxGSM
  3. # Author: Daniel Gibbs
  4. # License: MIT License, Copyright (c) 2017 Daniel Gibbs
  5. # Purpose: Quake 2 | Server Management Script
  6. # Contributors: https://github.com/GameServerManagers/LinuxGSM/graphs/contributors
  7. # Documentation: https://github.com/GameServerManagers/LinuxGSM/wiki
  8. # Website: https://gameservermanagers.com
  9. # Debugging
  10. if [ -f ".dev-debug" ]; then
  11. exec 5>dev-debug.log
  12. BASH_XTRACEFD="5"
  13. set -x
  14. fi
  15. version="161224"
  16. ##########################
  17. ######## Settings ########
  18. ##########################
  19. #### Server Settings ####
  20. ## Server Start Settings | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters
  21. defaultmap="q2dm1"
  22. ip="0.0.0.0"
  23. port="27910"
  24. ## Server Start Command | https://github.com/GameServerManagers/LinuxGSM/wiki/Start-Parameters#additional-parameters
  25. fn_parms(){
  26. parms="+set dedicated 1 +set ip ${ip} +set port ${port} +exec ${servercfg} +set deathmatch 1 +map ${defaultmap}"
  27. }
  28. #### LinuxGSM Settings ####
  29. ## Notification Alerts
  30. # (on|off)
  31. # Email Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Email
  32. emailalert="off"
  33. email="email@example.com"
  34. emailfrom=""
  35. # Pushbullet Alerts | https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet
  36. pushbulletalert="off"
  37. pushbullettoken="accesstoken"
  38. channeltag=""
  39. ## Backup | https://github.com/GameServerManagers/LinuxGSM/wiki/Backup
  40. maxbackups="4"
  41. maxbackupdays="30"
  42. stoponbackup="on"
  43. ## Logging | https://github.com/GameServerManagers/LinuxGSM/wiki/Logging
  44. consolelogging="on"
  45. logdays="7"
  46. #### LinuxGSM Advanced Settings ####
  47. ## Github Branch Select
  48. # Allows for the use of different function files
  49. # from a different repo and/or branch.
  50. githubuser="GameServerManagers"
  51. githubrepo="LinuxGSM"
  52. githubbranch="master"
  53. ## LinuxGSM Server Details
  54. # Do not edit
  55. gamename="Quake 2"
  56. engine="idtech2"
  57. ## Service Name | https://github.com/GameServerManagers/LinuxGSM/wiki/Multiple-Servers
  58. servicename="quake2server"
  59. #### Directories ####
  60. # Edit with care
  61. ## Work Directories
  62. rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
  63. selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  64. lockselfname=".${servicename}.lock"
  65. lgsmdir="${rootdir}/lgsm"
  66. functionsdir="${lgsmdir}/functions"
  67. libdir="${lgsmdir}/lib"
  68. tmpdir="${lgsmdir}/tmp"
  69. filesdir="${rootdir}/serverfiles"
  70. ## Server Specific Directories
  71. systemdir="${filesdir}/baseq2"
  72. executabledir="${filesdir}"
  73. executable="./quake2"
  74. servercfg="${servicename}.cfg"
  75. servercfgdefault="server.cfg"
  76. servercfgdir="${systemdir}"
  77. servercfgfullpath="${servercfgdir}/${servercfg}"
  78. ## Backup Directory
  79. backupdir="${rootdir}/backups"
  80. ## Logging Directories
  81. gamelogdir="${filesdir}/Logs"
  82. scriptlogdir="${rootdir}/log/script"
  83. consolelogdir="${rootdir}/log/console"
  84. scriptlog="${scriptlogdir}/${servicename}-script.log"
  85. consolelog="${consolelogdir}/${servicename}-console.log"
  86. emaillog="${scriptlogdir}/${servicename}-email.log"
  87. ## Logs Naming
  88. scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%Y-%m-%d-%H:%M:%S').log"
  89. consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%Y-%m-%d-%H:%M:%S').log"
  90. ########################
  91. ######## Script ########
  92. ###### Do not edit #####
  93. ########################
  94. # Fetches core_dl for file downloads
  95. fn_fetch_core_dl(){
  96. github_file_url_dir="lgsm/functions"
  97. github_file_url_name="${functionfile}"
  98. filedir="${functionsdir}"
  99. filename="${github_file_url_name}"
  100. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  101. # If the file is missing, then download
  102. if [ ! -f "${filedir}/${filename}" ]; then
  103. if [ ! -d "${filedir}" ]; then
  104. mkdir -p "${filedir}"
  105. fi
  106. echo -e " fetching ${filename}...\c"
  107. # Check curl exists and use available path
  108. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  109. for curlcmd in ${curlpaths}
  110. do
  111. if [ -x "${curlcmd}" ]; then
  112. break
  113. fi
  114. done
  115. # If curl exists download file
  116. if [ "$(basename ${curlcmd})" == "curl" ]; then
  117. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  118. if [ $? -ne 0 ]; then
  119. echo -e "\e[0;31mFAIL\e[0m\n"
  120. echo "${curlfetch}"
  121. echo -e "${githuburl}\n"
  122. exit 1
  123. else
  124. echo -e "\e[0;32mOK\e[0m"
  125. fi
  126. else
  127. echo -e "\e[0;31mFAIL\e[0m\n"
  128. echo "Curl is not installed!"
  129. echo -e ""
  130. exit 1
  131. fi
  132. chmod +x "${filedir}/${filename}"
  133. fi
  134. source "${filedir}/${filename}"
  135. }
  136. core_dl.sh(){
  137. # Functions are defined in core_functions.sh.
  138. functionfile="${FUNCNAME}"
  139. fn_fetch_core_dl
  140. }
  141. core_functions.sh(){
  142. # Functions are defined in core_functions.sh.
  143. functionfile="${FUNCNAME}"
  144. fn_fetch_core_dl
  145. }
  146. # Prevent from running this script as root.
  147. if [ "$(whoami)" = "root" ]; then
  148. if [ ! -f "${functionsdir}/core_functions.sh" ]||[ ! -f "${functionsdir}/check_root.sh" ]||[ ! -f "${functionsdir}/core_messages.sh" ]||[ ! -f "${functionsdir}/core_exit.sh" ]; then
  149. echo "[ FAIL ] Do NOT run this script as root!"
  150. exit 1
  151. else
  152. core_functions.sh
  153. check_root.sh
  154. fi
  155. fi
  156. core_dl.sh
  157. core_functions.sh
  158. getopt=$1
  159. core_getopt.sh