ts3server 4.7 KB

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