ts3server 4.7 KB

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