q2server 5.0 KB

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