update_ts3.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/bin/bash
  2. # LinuxGSM command_ts3.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.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. fn_fetch_file "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2" "${tmpdir}" "teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  11. fn_dl_extract "${tmpdir}" "teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2" "${tmpdir}"
  12. echo -e "copying to ${serverfiles}...\c"
  13. fn_script_log "Copying to ${serverfiles}"
  14. cp -R "${tmpdir}/teamspeak3-server_linux_${ts3arch}/"* "${serverfiles}"
  15. local exitcode=$?
  16. if [ "${exitcode}" == "0" ]; then
  17. fn_print_ok_eol_nl
  18. else
  19. fn_print_fail_eol_nl
  20. fi
  21. }
  22. fn_update_ts3_currentbuild(){
  23. # Gets current build info
  24. # Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
  25. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  26. fn_print_error "Checking for update: teamspeak.com"
  27. sleep 1
  28. fn_print_error_nl "Checking for update: teamspeak.com: No logs with server version found"
  29. fn_script_log_error "Checking for update: teamspeak.com: No logs with server version found"
  30. sleep 1
  31. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  32. fn_script_log_info "Checking for update: teamspeak.com: Forcing server restart"
  33. sleep 1
  34. exitbypass=1
  35. command_stop.sh
  36. exitbypass=1
  37. command_start.sh
  38. sleep 1
  39. # Check again and exit on failure.
  40. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  41. fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
  42. fn_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found"
  43. core_exit.sh
  44. fi
  45. fi
  46. # Get current build from logs
  47. currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | sort -V | tail -1)
  48. if [ -z "${currentbuild}" ]; then
  49. fn_print_error_nl "Checking for update: teamspeak.com: Current build version not found"
  50. fn_script_log_error "Checking for update: teamspeak.com: Current build version not found"
  51. sleep 1
  52. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  53. fn_script_log_info "Checking for update: teamspeak.com: Forcing server restart"
  54. exitbypass=1
  55. command_stop.sh
  56. exitbypass=1
  57. command_start.sh
  58. currentbuild=$(cat $(find ./* -name 'ts3server*_0.log' 2> /dev/null | sort | egrep -E -v '${rootdir}/.ts3version' | tail -1) | egrep -o 'TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | egrep -o '((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}')
  59. if [ -z "${currentbuild}" ]; then
  60. fn_print_fail_nl "Checking for update: teamspeak.com: Current build version still not found"
  61. fn_script_log_fatal "Checking for update: teamspeak.com: Current build version still not found"
  62. core_exit.sh
  63. fi
  64. fi
  65. }
  66. fn_update_ts3_arch(){
  67. # Gets the teamspeak server architecture.
  68. info_distro.sh
  69. if [ "${arch}" == "x86_64" ]; then
  70. ts3arch="amd64"
  71. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  72. ts3arch="x86"
  73. else
  74. echo ""
  75. fn_print_failure "Unknown or unsupported architecture: ${arch}"
  76. fn_script_log_fatal "Unknown or unsupported architecture: ${arch}"
  77. core_exit.sh
  78. fi
  79. }
  80. fn_update_ts3_availablebuild(){
  81. # Gets latest build info.
  82. if [ "${arch}" == "x86_64" ]; then
  83. availablebuild=$(${curlpath} -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86_64.version')
  84. elif [ "${arch}" == "x86" ]; then
  85. availablebuild=$(${curlpath} -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86.version')
  86. fi
  87. # Checks if availablebuild variable has been set
  88. if [ -z "${availablebuild}" ]; then
  89. fn_print_fail "Checking for update: teamspeak.com"
  90. sleep 0.5
  91. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  92. fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
  93. core_exit.sh
  94. elif [ "${installer}" == "1" ]; then
  95. :
  96. else
  97. fn_print_ok_nl "Checking for update: teamspeak.com"
  98. fn_script_log_pass "Checking for update: teamspeak.com"
  99. sleep 0.5
  100. fi
  101. }
  102. fn_update_ts3_availablebuild_legacy(){
  103. # Gets latest build info.
  104. # Grabs all version numbers but not in correct order.
  105. wget "http://dl.4players.de/ts/releases/?C=M;O=D" -q -O -| grep -i dir | egrep -o '<a href=\".*\/\">.*\/<\/a>' | egrep -o '[0-9\.?]+'|uniq > "${tmpdir}/.ts3_version_numbers_unsorted.tmp"
  106. # Sort version numbers
  107. cat "${tmpdir}/.ts3_version_numbers_unsorted.tmp" | sort -r --version-sort -o "${tmpdir}/.ts3_version_numbers_sorted.tmp"
  108. # Finds directory with most recent server version.
  109. while read ts3_version_number; do
  110. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  111. if [ $? -eq 0 ]; then
  112. availablebuild="${ts3_version_number}"
  113. # Break while-loop, if the latest release could be found.
  114. break
  115. fi
  116. done < "${tmpdir}/.ts3_version_numbers_sorted.tmp"
  117. # Tidy up
  118. rm -f "${tmpdir}/.ts3_version_numbers_unsorted.tmp"
  119. rm -f "${tmpdir}/.ts3_version_numbers_sorted.tmp"
  120. # Checks availablebuild info is available
  121. if [ -z "${availablebuild}" ]; then
  122. fn_print_fail "Checking for update: teamspeak.com"
  123. sleep 1
  124. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  125. fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
  126. core_exit.sh
  127. elif [ "${installer}" == "1" ]; then
  128. :
  129. else
  130. fn_print_ok "Checking for update: teamspeak.com"
  131. fn_script_log_pass "Checking for update: teamspeak.com"
  132. sleep 1
  133. fi
  134. }
  135. fn_update_ts3_compare(){
  136. # Removes dots so if can compare version numbers
  137. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  138. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  139. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  140. echo -e "\n"
  141. echo -e "Update available:"
  142. sleep 1
  143. echo -e " Current build: ${red}${currentbuild} ${ts3arch}${default}"
  144. echo -e " Available build: ${green}${availablebuild} ${ts3arch}${default}"
  145. echo -e ""
  146. sleep 1
  147. echo ""
  148. echo -en "Applying update.\r"
  149. sleep 1
  150. echo -en "Applying update..\r"
  151. sleep 1
  152. echo -en "Applying update...\r"
  153. sleep 1
  154. echo -en "\n"
  155. fn_script_log "Update available"
  156. fn_script_log "Current build: ${currentbuild}"
  157. fn_script_log "Available build: ${availablebuild}"
  158. fn_script_log "${currentbuild} > ${availablebuild}"
  159. unset updateonstart
  160. check_status.sh
  161. if [ "${status}" == "0" ]; then
  162. fn_update_ts3_dl
  163. exitbypass=1
  164. command_start.sh
  165. exitbypass=1
  166. command_stop.sh
  167. else
  168. exitbypass=1
  169. command_stop.sh
  170. fn_update_ts3_dl
  171. exitbypass=1
  172. command_start.sh
  173. fi
  174. alert="update"
  175. alert.sh
  176. else
  177. echo -e "\n"
  178. echo -e "No update available:"
  179. echo -e " Current version: ${green}${currentbuild}${default}"
  180. echo -e " Available version: ${green}${availablebuild}${default}"
  181. echo -e ""
  182. fn_print_ok_nl "No update available"
  183. fn_script_log_info "Current build: ${currentbuild}"
  184. fn_script_log_info "Available build: ${availablebuild}"
  185. fi
  186. }
  187. fn_update_ts3_arch
  188. if [ "${installer}" == "1" ]; then
  189. # if jq available uses json update checker
  190. if [ "$(command -v jq)" ]||[ "$(which jq >/dev/null 2>&1)" ]; then
  191. fn_update_ts3_availablebuild
  192. else
  193. fn_update_ts3_availablebuild_legacy
  194. fi
  195. fn_update_ts3_dl
  196. else
  197. # Checks for server update from teamspeak.com using a mirror dl.4players.de.
  198. fn_print_dots "Checking for update: teamspeak.com"
  199. fn_script_log_info "Checking for update: teamspeak.com"
  200. sleep 1
  201. fn_update_ts3_currentbuild
  202. fn_update_ts3_availablebuild
  203. fn_update_ts3_compare
  204. fi