ts3server 4.9 KB

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