update_ts3.sh 5.1 KB

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