update_ts3.sh 5.6 KB

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