update_ts3.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/bin/bash
  2. # LGSM 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 ${filesdir}...\c"
  13. fn_script_log "Copying to ${filesdir}"
  14. cp -R "${tmpdir}/teamspeak3-server_linux_${ts3arch}/"* "${filesdir}"
  15. local exitcode=$?
  16. if [ ${exitcode} -eq 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 currentbuild info
  24. # Checks currentbuild info is available, if fails 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. # Grabs all version numbers but not in correct order.
  83. 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"
  84. # Sort version numbers
  85. cat "${tmpdir}/.ts3_version_numbers_unsorted.tmp" | sort -r --version-sort -o "${tmpdir}/.ts3_version_numbers_sorted.tmp"
  86. # Finds directory with most recent server version.
  87. while read ts3_version_number; do
  88. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  89. if [ $? -eq 0 ]; then
  90. availablebuild="${ts3_version_number}"
  91. # Break while-loop, if the latest release could be found.
  92. break
  93. fi
  94. done < "${tmpdir}/.ts3_version_numbers_sorted.tmp"
  95. # Tidy up
  96. rm -f "${tmpdir}/.ts3_version_numbers_unsorted.tmp"
  97. rm -f "${tmpdir}/.ts3_version_numbers_sorted.tmp"
  98. # Checks availablebuild info is available
  99. if [ -z "${availablebuild}" ]; then
  100. fn_print_fail "Checking for update: teamspeak.com"
  101. sleep 1
  102. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  103. fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
  104. core_exit.sh
  105. else
  106. fn_print_ok "Checking for update: teamspeak.com"
  107. fn_script_log_pass "Checking for update: teamspeak.com"
  108. sleep 1
  109. fi
  110. }
  111. fn_update_ts3_compare(){
  112. # Removes dots so if can compare version numbers
  113. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  114. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  115. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  116. echo -e "\n"
  117. echo -e "Update available:"
  118. sleep 1
  119. echo -e " Current build: ${red}${currentbuild} ${ts3arch}${default}"
  120. echo -e " Available build: ${green}${availablebuild} ${ts3arch}${default}"
  121. echo -e ""
  122. sleep 1
  123. echo ""
  124. echo -en "Applying update.\r"
  125. sleep 1
  126. echo -en "Applying update..\r"
  127. sleep 1
  128. echo -en "Applying update...\r"
  129. sleep 1
  130. echo -en "\n"
  131. fn_script_log "Update available"
  132. fn_script_log "Current build: ${currentbuild}"
  133. fn_script_log "Available build: ${availablebuild}"
  134. fn_script_log "${currentbuild} > ${availablebuild}"
  135. unset updateonstart
  136. check_status.sh
  137. if [ "${status}" == "0" ]; then
  138. fn_update_ts3_dl
  139. exitbypass=1
  140. command_start.sh
  141. exitbypass=1
  142. command_stop.sh
  143. else
  144. exitbypass=1
  145. command_stop.sh
  146. fn_update_ts3_dl
  147. exitbypass=1
  148. command_start.sh
  149. fi
  150. alert="update"
  151. alert.sh
  152. else
  153. echo -e "\n"
  154. echo -e "No update available:"
  155. echo -e " Current version: ${green}${currentbuild}${default}"
  156. echo -e " Available version: ${green}${availablebuild}${default}"
  157. echo -e ""
  158. fn_print_ok_nl "No update available"
  159. fn_script_log_info "Current build: ${currentbuild}"
  160. fn_script_log_info "Available build: ${availablebuild}"
  161. fi
  162. }
  163. fn_update_ts3_arch
  164. if [ "${installer}" == "1" ]; then
  165. fn_update_ts3_availablebuild
  166. fn_update_ts3_dl
  167. else
  168. # Checks for server update from teamspeak.com using a mirror dl.4players.de.
  169. fn_print_dots "Checking for update: teamspeak.com"
  170. fn_script_log_info "Checking for update: teamspeak.com"
  171. sleep 1
  172. fn_update_ts3_currentbuild
  173. fn_update_ts3_availablebuild
  174. fn_update_ts3_compare
  175. fi