update_ts3.sh 6.9 KB

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