update_ts3.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/bash
  2. # LGSM commanf_update.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description:Handles updating of teamspeak 3 servers.
  6. local modulename="Update"
  7. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  8. fn_update_ts3_dl(){
  9. 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"
  10. fn_dl_extract "${lgsmdir}/tmp" "teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2" "${lgsmdir}/tmp"
  11. echo -e "copying to ${filesdir}...\c"
  12. fn_script_log "Copying to ${filesdir}"
  13. cp -R "${lgsmdir}/tmp/teamspeak3-server_linux_${ts3arch}/"* "${filesdir}"
  14. local exitcode=$?
  15. if [ ${exitcode} -eq 0 ]; then
  16. fn_print_ok_eol_nl
  17. else
  18. fn_print_fail_eol_nl
  19. fi
  20. }
  21. fn_update_ts3_currentbuild(){
  22. # Gets currentbuild info
  23. # Checks currentbuild info is available, if fails a server restart will be forced to generate logs.
  24. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  25. fn_print_fail "Checking for update: teamspeak.com"
  26. sleep 1
  27. fn_print_fail_nl "Checking for update: teamspeak.com: No logs with server version found"
  28. fn_script_log_warn "Checking for update: teamspeak.com: No logs with server version found"
  29. sleep 2
  30. fn_print_info_nl "Checking for update: teamspeak.com: Forcing server restart"
  31. fn_script_log_warn "Checking for update: teamspeak.com: Forcing server restart"
  32. sleep 2
  33. exitbypass=1
  34. command_stop.sh
  35. exitbypass=1
  36. command_start.sh
  37. sleep 1
  38. # Check again and exit on failure.
  39. if [ -z "$(find ./* -name 'ts3server*_0.log')" ]; then
  40. fn_print_fail_nl "Checking for update: teamspeak.com: Still No logs with server version found"
  41. fn_script_log_fatal "Checking for update: teamspeak.com: Still No logs with server version found"
  42. core_exit.sh
  43. fi
  44. fi
  45. 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}')
  46. }
  47. fn_update_ts3_arch(){
  48. # Gets the teamspeak server architecture.
  49. info_distro.sh
  50. if [ "${arch}" == "x86_64" ]; then
  51. ts3arch="amd64"
  52. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  53. ts3arch="x86"
  54. else
  55. echo ""
  56. fn_print_failure "unknown or unsupported architecture: ${arch}"
  57. fn_script_log_fatal "unknown or unsupported architecture: ${arch}"
  58. core_exit.sh
  59. fi
  60. }
  61. fn_update_ts3_availablebuild(){
  62. # Gets availablebuild info.
  63. # Creates tmp dir if missing
  64. if [ ! -d "${lgsmdir}/tmp" ]; then
  65. mkdir -p "${lgsmdir}/tmp"
  66. fi
  67. # Grabs all version numbers but not in correct order.
  68. 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"
  69. # Sort version numbers
  70. cat "${lgsmdir}/tmp/.ts3_version_numbers_unsorted.tmp" | sort -r --version-sort -o "${lgsmdir}/tmp/.ts3_version_numbers_sorted.tmp"
  71. # Finds directory with most recent server version.
  72. while read ts3_version_number; do
  73. wget --spider -q "http://dl.4players.de/ts/releases/${ts3_version_number}/teamspeak3-server_linux_${ts3arch}-${ts3_version_number}.tar.bz2"
  74. if [ $? -eq 0 ]; then
  75. availablebuild="${ts3_version_number}"
  76. # Break while-loop, if the latest release could be found.
  77. break
  78. fi
  79. done < "${lgsmdir}/tmp/.ts3_version_numbers_sorted.tmp"
  80. # Tidy up
  81. rm -f "${lgsmdir}/tmp/.ts3_version_numbers_unsorted.tmp"
  82. rm -f "${lgsmdir}/tmp/.ts3_version_numbers_sorted.tmp"
  83. # Checks availablebuild info is available
  84. if [ -z "${availablebuild}" ]; then
  85. fn_print_fail "Checking for update: teamspeak.com"
  86. sleep 1
  87. fn_print_fail "Checking for update: teamspeak.com: Not returning version info"
  88. fn_script_log_fatal "Failure! Checking for update: teamspeak.com: Not returning version info"
  89. core_exit.sh
  90. else
  91. fn_print_ok_nl "Checking for update: teamspeak.com"
  92. fn_script_log_pass "Checking for update: teamspeak.com"
  93. sleep 1
  94. fi
  95. }
  96. fn_update_ts3_compare(){
  97. # Removes dots so if can compare version numbers
  98. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  99. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  100. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  101. echo -e "\n"
  102. echo -e "Update available:"
  103. sleep 1
  104. echo -e " Current build: \e[0;31m${currentbuild} ${architecture}\e[0;39m"
  105. echo -e " Available build: \e[0;32m${availablebuild} ${architecture}\e[0;39m"
  106. echo -e ""
  107. sleep 1
  108. echo ""
  109. echo -en "Applying update.\r"
  110. sleep 1
  111. echo -en "Applying update..\r"
  112. sleep 1
  113. echo -en "Applying update...\r"
  114. sleep 1
  115. echo -en "\n"
  116. fn_script_log "Update available"
  117. fn_script_log "Current build: ${currentbuild}"
  118. fn_script_log "Available build: ${availablebuild}"
  119. fn_script_log "${currentbuild} > ${availablebuild}"
  120. unset updateonstart
  121. check_status.sh
  122. if [ "${status}" == "0" ]; then
  123. fn_update_ts3_dl
  124. exitbypass=1
  125. command_start.sh
  126. exitbypass=1
  127. command_stop.sh
  128. else
  129. exitbypass=1
  130. command_stop.sh
  131. fn_update_ts3_dl
  132. exitbypass=1
  133. command_start.sh
  134. fi
  135. alert="update"
  136. alert.sh
  137. else
  138. echo -e "\n"
  139. echo -e "No update available:"
  140. echo -e " Current version: \e[0;32m${currentbuild}\e[0;39m"
  141. echo -e " Available version: \e[0;32m${availablebuild}\e[0;39m"
  142. echo -e ""
  143. fn_print_ok_nl "No update available"
  144. fn_script_log_info "Current build: ${currentbuild}"
  145. fn_script_log_info "Available build: ${availablebuild}"
  146. fi
  147. }
  148. fn_update_ts3_arch
  149. if [ "${installer}" == "1" ]; then
  150. fn_update_ts3_availablebuild
  151. fn_update_ts3_dl
  152. else
  153. # Checks for server update from teamspeak.com using a mirror dl.4players.de.
  154. fn_print_dots "Checking for update: teamspeak.com"
  155. fn_script_log_info "Checking for update: teamspeak.com"
  156. sleep 1
  157. fn_update_ts3_currentbuild
  158. fn_update_ts3_availablebuild
  159. fn_update_ts3_compare
  160. fi