update_ts3.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/bin/bash
  2. # LinuxGSM command_ts3.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Handles updating of teamspeak 3 servers.
  6. local commandname="UPDATE"
  7. local commandaction="Update"
  8. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. fn_update_ts3_dl(){
  10. info_distro.sh
  11. if [ "${ts3arch}" == "amd64" ]; then
  12. latestts3releaselink=$(${curlpath} -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86_64.mirrors."teamspeak.com"')
  13. elif [ "${ts3arch}" == "x86" ]; then
  14. latestts3releaselink=$(${curlpath} -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86.mirrors."teamspeak.com"')
  15. fi
  16. fn_fetch_file "${latestts3releaselink}" "${tmpdir}" "teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  17. fn_dl_extract "${tmpdir}" "teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2" "${tmpdir}"
  18. echo -e "copying to ${serverfiles}...\c"
  19. fn_script_log "Copying to ${serverfiles}"
  20. cp -R "${tmpdir}/teamspeak3-server_linux_${ts3arch}/"* "${serverfiles}"
  21. local exitcode=$?
  22. if [ "${exitcode}" == "0" ]; then
  23. fn_print_ok_eol_nl
  24. else
  25. fn_print_fail_eol_nl
  26. fi
  27. }
  28. fn_update_ts3_currentbuild(){
  29. # Gets current build info
  30. # Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
  31. if [ ! -d "${serverfiles}/logs" ]||[ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; then
  32. fn_print_error "Checking for update: teamspeak.com"
  33. sleep 0.5
  34. fn_print_error_nl "Checking for update: teamspeak.com: No logs with server version found"
  35. fn_script_log_error "Checking for update: teamspeak.com: No logs with server version found"
  36. sleep 0.5
  37. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  38. fn_script_log_info "Checking for update: teamspeak.com: Forcing server restart"
  39. sleep 0.5
  40. exitbypass=1
  41. command_stop.sh
  42. exitbypass=1
  43. command_start.sh
  44. sleep 0.5
  45. # Check again and exit on failure.
  46. if [ ! -d "${serverfiles}/logs" ]||[ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log')" ]; then
  47. fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
  48. fn_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found"
  49. core_exit.sh
  50. fi
  51. fi
  52. # Get current build from logs
  53. currentbuild="$(cat "$(find "${serverfiles}/logs/"* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | sort -V)"
  54. if [ -z "${currentbuild}" ]; then
  55. fn_print_error_nl "Checking for update: teamspeak.com: Current build version not found"
  56. fn_script_log_error "Checking for update: teamspeak.com: Current build version not found"
  57. sleep 0.5
  58. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  59. fn_script_log_info "Checking for update: teamspeak.com: Forcing server restart"
  60. exitbypass=1
  61. command_stop.sh
  62. exitbypass=1
  63. command_start.sh
  64. currentbuild="$(cat "$(find "${serverfiles}/logs/"* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | sort -V)"
  65. if [ -z "${currentbuild}" ]; then
  66. fn_print_fail_nl "Checking for update: teamspeak.com: Current build version still not found"
  67. fn_script_log_fatal "Checking for update: teamspeak.com: Current build version still not found"
  68. core_exit.sh
  69. fi
  70. fi
  71. }
  72. fn_update_ts3_arch(){
  73. # Gets the teamspeak server architecture.
  74. info_distro.sh
  75. if [ "${arch}" == "x86_64" ]; then
  76. ts3arch="amd64"
  77. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  78. ts3arch="x86"
  79. else
  80. echo ""
  81. fn_print_failure "Unknown or unsupported architecture: ${arch}"
  82. fn_script_log_fatal "Unknown or unsupported architecture: ${arch}"
  83. core_exit.sh
  84. fi
  85. }
  86. fn_update_ts3_availablebuild(){
  87. # Gets latest build info.
  88. if [ "${arch}" == "x86_64" ]; then
  89. availablebuild="$(${curlpath} -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86_64.version')"
  90. elif [ "${arch}" == "x86" ]; then
  91. availablebuild="$(${curlpath} -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86.version')"
  92. fi
  93. ts3_version_number="${availablebuild}"
  94. # Checks if availablebuild variable has been set
  95. if [ -v "${availablebuild}" ]||[ "${availablebuild}" == "null" ]; then
  96. fn_print_fail "Checking for update: teamspeak.com"
  97. sleep 0.5
  98. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  99. fn_script_log_fatal "Checking for update: teamspeak.com: Not returning version info"
  100. core_exit.sh
  101. elif [ "${installer}" == "1" ]; then
  102. :
  103. else
  104. fn_print_ok_nl "Checking for update: teamspeak.com"
  105. fn_script_log_pass "Checking for update: teamspeak.com"
  106. sleep 0.5
  107. fi
  108. }
  109. fn_update_ts3_compare(){
  110. # Removes dots so if can compare version numbers
  111. currentbuilddigit=$(echo "${currentbuild}" | tr -cd '[:digit:]')
  112. availablebuilddigit=$(echo "${availablebuild}" | tr -cd '[:digit:]')
  113. if [ "${currentbuilddigit}" -lt "${availablebuilddigit}" ]; then
  114. echo -e "\n"
  115. echo -e "Update available:"
  116. sleep 0.5
  117. echo -e " Current build: ${red}${currentbuild} ${ts3arch}${default}"
  118. echo -e " Available build: ${green}${availablebuild} ${ts3arch}${default}"
  119. echo -e ""
  120. sleep 0.5
  121. echo -en "Applying update.\r"
  122. sleep 1
  123. echo -en "Applying update..\r"
  124. sleep 1
  125. echo -en "Applying update...\r"
  126. sleep 1
  127. echo -en "\n"
  128. fn_script_log "Update available"
  129. fn_script_log "Current build: ${currentbuild}"
  130. fn_script_log "Available build: ${availablebuild}"
  131. fn_script_log "${currentbuild} > ${availablebuild}"
  132. unset updateonstart
  133. check_status.sh
  134. if [ "${status}" == "0" ]; then
  135. fn_update_ts3_dl
  136. exitbypass=1
  137. command_start.sh
  138. exitbypass=1
  139. command_stop.sh
  140. else
  141. exitbypass=1
  142. command_stop.sh
  143. fn_update_ts3_dl
  144. exitbypass=1
  145. command_start.sh
  146. fi
  147. alert="update"
  148. alert.sh
  149. else
  150. echo -e "\n"
  151. echo -e "No update available:"
  152. echo -e " Current version: ${green}${currentbuild}${default}"
  153. echo -e " Available version: ${green}${availablebuild}${default}"
  154. echo -e ""
  155. fn_print_ok_nl "No update available"
  156. fn_script_log_info "Current build: ${currentbuild}"
  157. fn_script_log_info "Available build: ${availablebuild}"
  158. fi
  159. }
  160. fn_update_ts3_arch
  161. if [ "${installer}" == "1" ]; then
  162. fn_update_ts3_availablebuild
  163. fn_update_ts3_dl
  164. else
  165. # Checks for server update from teamspeak.com using a mirror dl.4players.de.
  166. fn_print_dots "Checking for update: teamspeak.com"
  167. fn_script_log_info "Checking for update: teamspeak.com"
  168. sleep 0.5
  169. fn_update_ts3_currentbuild
  170. fn_update_ts3_availablebuild
  171. fn_update_ts3_compare
  172. fi