4
0

update_ts3.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/bin/bash
  2. # LinuxGSM command_ts3.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Handles updating of Teamspeak 3 servers.
  6. functionselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  7. fn_update_ts3_dl(){
  8. if [ "${ts3arch}" == "amd64" ]; then
  9. remotebuildurl=$(curl -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86_64.mirrors."teamspeak.com"')
  10. elif [ "${ts3arch}" == "x86" ]; then
  11. remotebuildurl=$(curl -s 'https://www.teamspeak.com/versions/server.json' | jq -r '.linux.x86.mirrors."teamspeak.com"')
  12. fi
  13. fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "teamspeak3-server_linux_${ts3arch}-${remotebuild}.tar.bz2" "" "norun" "noforce" "nomd5"
  14. fn_dl_extract "${tmpdir}" "teamspeak3-server_linux_${ts3arch}-${remotebuild}.tar.bz2" "${tmpdir}"
  15. echo -e "copying to ${serverfiles}...\c"
  16. cp -R "${tmpdir}/teamspeak3-server_linux_${ts3arch}/"* "${serverfiles}"
  17. local exitcode=$?
  18. if [ "${exitcode}" == "0" ]; then
  19. fn_print_ok_eol_nl
  20. fn_script_log_pass "Copying to ${serverfiles}"
  21. fn_clear_tmp
  22. else
  23. fn_print_fail_eol_nl
  24. fn_script_log_fatal "Copying to ${serverfiles}"
  25. core_exit.sh
  26. fi
  27. }
  28. fn_update_ts3_localbuild(){
  29. # Gets local build info.
  30. fn_print_dots "Checking local build: ${remotelocation}"
  31. # Uses log file to gather info.
  32. # Gives time for log file to generate.
  33. if [ ! -d "${serverfiles}/logs" ]||[ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; then
  34. fn_print_error "Checking local build: ${remotelocation}"
  35. fn_print_error_nl "Checking local build: ${remotelocation}: no log files containing version info"
  36. fn_print_info_nl "Checking local build: ${remotelocation}: forcing server restart"
  37. fn_script_log_error "No log files containing version info"
  38. fn_script_log_info "Forcing server restart"
  39. exitbypass=1
  40. command_stop.sh
  41. exitbypass=1
  42. command_start.sh
  43. totalseconds=0
  44. # Check again, allow time to generate logs.
  45. while [ ! -d "${serverfiles}/logs" ]||[ -z "$(find "${serverfiles}/logs/"* -name 'ts3server*_0.log' 2> /dev/null)" ]; do
  46. sleep 1
  47. fn_print_info "Checking local build: ${remotelocation}: waiting for log file: ${totalseconds}"
  48. if [ -v "${loopignore}" ]; then
  49. loopignore=1
  50. fn_script_log_info "Waiting for log file to generate"
  51. fi
  52. if [ "${totalseconds}" -gt "120" ]; then
  53. localbuild="0"
  54. fn_print_error "Checking local build: ${remotelocation}: waiting for log file: missing log file"
  55. fn_script_log_error "Missing log file"
  56. fn_script_log_error "Set localbuild to 0"
  57. fi
  58. totalseconds=$((totalseconds + 1))
  59. done
  60. fi
  61. if [ -z "${localbuild}" ]; then
  62. localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1)
  63. fi
  64. if [ -z "${localbuild}" ]; then
  65. # Gives time for var to generate.
  66. totalseconds=0
  67. for seconds in {1..120}; do
  68. fn_print_info "Checking local build: ${remotelocation}: waiting for local build: ${totalseconds}"
  69. if [ -z "${loopignore}" ]; then
  70. loopignore=1
  71. fn_script_log_info "Waiting for local build to generate"
  72. fi
  73. localbuild=$(cat "$(find ./* -name "ts3server*_0.log" 2> /dev/null | sort | tail -1)" | grep -Eo "TeamSpeak 3 Server ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | grep -Eo "((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}" | tail -1)
  74. if [ "${localbuild}" ]||[ "${seconds}" == "120" ]; then
  75. break
  76. fi
  77. sleep 1
  78. totalseconds=$((totalseconds + 1))
  79. done
  80. fi
  81. if [ -z "${localbuild}" ]; then
  82. localbuild="0"
  83. fn_print_error "Checking local build: ${remotelocation}: waiting for local build: missing local build info"
  84. fn_script_log_error "Missing local build info"
  85. fn_script_log_error "Set localbuild to 0"
  86. else
  87. fn_print_ok "Checking local build: ${remotelocation}"
  88. fn_script_log_pass "Checking local build"
  89. fi
  90. }
  91. fn_update_ts3_remotebuild(){
  92. # Gets remote build info.
  93. if [ "${arch}" == "x86_64" ]; then
  94. remotebuild=$(curl -s "https://www.teamspeak.com/versions/server.json" | jq -r '.linux.x86_64.version')
  95. elif [ "${arch}" == "x86" ]; then
  96. remotebuild=$(curl -s "https://www.teamspeak.com/versions/server.json" | jq -r '.linux.x86.version')
  97. fi
  98. if [ "${installer}" != "1" ]; then
  99. fn_print_dots "Checking remote build: ${remotelocation}"
  100. # Checks if remotebuild variable has been set.
  101. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  102. fn_print_fail "Checking remote build: ${remotelocation}"
  103. fn_script_log_fatal "Checking remote build"
  104. core_exit.sh
  105. else
  106. fn_print_ok "Checking remote build: ${remotelocation}"
  107. fn_script_log_pass "Checking remote build"
  108. fi
  109. else
  110. # Checks if remotebuild variable has been set.
  111. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  112. fn_print_failure "Unable to get remote build"
  113. fn_script_log_fatal "Unable to get remote build"
  114. core_exit.sh
  115. fi
  116. fi
  117. }
  118. fn_update_ts3_compare(){
  119. # Removes dots so if statement can compare version numbers.
  120. fn_print_dots "Checking for update: ${remotelocation}"
  121. localbuilddigit=$(echo -e "${localbuild}" | tr -cd '[:digit:]')
  122. remotebuilddigit=$(echo -e "${remotebuild}" | tr -cd '[:digit:]')
  123. if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ]||[ "${forceupdate}" == "1" ]; then
  124. fn_print_ok_nl "Checking for update: ${remotelocation}"
  125. echo -en "\n"
  126. echo -e "Update available"
  127. echo -e "* Local build: ${red}${localbuild}${default}"
  128. echo -e "* Remote build: ${green}${remotebuild}${default}"
  129. fn_script_log_info "Update available"
  130. fn_script_log_info "Local build: ${localbuild}"
  131. fn_script_log_info "Remote build: ${remotebuild}"
  132. fn_script_log_info "${localbuild} > ${remotebuild}"
  133. unset updateonstart
  134. check_status.sh
  135. # If server stopped.
  136. if [ "${status}" == "0" ]; then
  137. exitbypass=1
  138. fn_update_ts3_dl
  139. exitbypass=1
  140. command_start.sh
  141. exitbypass=1
  142. command_stop.sh
  143. # If server started.
  144. else
  145. fn_stop_warning
  146. exitbypass=1
  147. command_stop.sh
  148. exitbypass=1
  149. fn_update_ts3_dl
  150. exitbypass=1
  151. command_start.sh
  152. fi
  153. alert="update"
  154. alert.sh
  155. else
  156. fn_print_ok_nl "Checking for update: ${remotelocation}"
  157. echo -en "\n"
  158. echo -e "No update available"
  159. echo -e "* Local build: ${green}${localbuild}${default}"
  160. echo -e "* Remote build: ${green}${remotebuild}${default}"
  161. fn_script_log_info "No update available"
  162. fn_script_log_info "Local build: ${localbuild}"
  163. fn_script_log_info "Remote build: ${remotebuild}"
  164. fi
  165. }
  166. # Game server architecture.
  167. info_distro.sh
  168. if [ "${arch}" == "x86_64" ]; then
  169. ts3arch="amd64"
  170. elif [ "${arch}" == "i386" ]||[ "${arch}" == "i686" ]; then
  171. ts3arch="x86"
  172. else
  173. fn_print_failure "Unknown or unsupported architecture: ${arch}"
  174. fn_script_log_fatal "Unknown or unsupported architecture: ${arch}"
  175. core_exit.sh
  176. fi
  177. fn_stop_warning(){
  178. fn_print_warn "Updating server: SteamCMD: ${selfname} will be stopped during update"
  179. fn_script_log_warn "Updating server: SteamCMD: ${selfname} will be stopped during update"
  180. totalseconds=3
  181. for seconds in {3..1}; do
  182. fn_print_warn "Updating server: SteamCMD: ${selfname} will be stopped during update: ${totalseconds}"
  183. totalseconds=$((totalseconds - 1))
  184. sleep 1
  185. if [ "${seconds}" == "0" ]; then
  186. break
  187. fi
  188. done
  189. fn_print_warn_nl "Updating server: SteamCMD: ${selfname} will be stopped during update"
  190. }
  191. # The location where the builds are checked and downloaded.
  192. remotelocation="teamspeak.com"
  193. if [ "${installer}" == "1" ]; then
  194. fn_update_ts3_remotebuild
  195. fn_update_ts3_dl
  196. else
  197. fn_print_dots "Checking for update: ${remotelocation}"
  198. fn_script_log_info "Checking for update: ${remotelocation}"
  199. fn_update_ts3_localbuild
  200. fn_update_ts3_remotebuild
  201. fn_update_ts3_compare
  202. fi