update_mumble.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. # LGSM update_mumble.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://gameservermanagers.com
  6. # Description: Handles updating of mumble servers.
  7. local commandname="UPDATE"
  8. local commandaction="Update"
  9. local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. fn_update_mumble_arch(){
  11. # Mumble is x86 only for now
  12. mumblearch="x86"
  13. }
  14. fn_update_mumble_availablebuild(){
  15. # Gets available build info.
  16. fn_print_info_nl "Checking for update from github.com"
  17. fn_script_log "Checking for update from github.com"
  18. availablebuild=$(curl -s https://api.github.com/repos/mumble-voip/mumble/releases/latest | grep 'murmur-static_x86.*\.bz2"' | tail -1 | awk -F"/" '{ print $8 }')
  19. sleep 1
  20. # Checks if availablebuild variable has been set
  21. if [ -z "${availablebuild}" ]; then
  22. fn_print_fail "Checking for update from github.com"
  23. sleep 1
  24. fn_print_fail "Checking for update: github.com: Not returning version info"
  25. fn_script_log_fatal "Failure! Checking for update: github.com Not returning version info"
  26. core_exit.sh
  27. else
  28. fn_print_ok_nl "Checking for update from github.com"
  29. fn_script_log_pass "Checking for update from github.com"
  30. sleep 1
  31. fi
  32. }
  33. fn_update_mumble_currentbuild(){
  34. # Gets current build info
  35. fn_print_info "Checking current server build"
  36. sleep 1
  37. # Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
  38. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  39. fn_print_info_nl "No current log found, can't retrieve current server build"
  40. fn_script_log_info "No current log found, can't retrieve current server build"
  41. sleep 1
  42. fn_print_info_nl "Forcing server restart"
  43. fn_script_log_info "Forcing server restart"
  44. sleep 1
  45. exitbypass=1
  46. command_stop.sh
  47. exitbypass=1
  48. command_start.sh
  49. sleep 1
  50. # Check again and exit on failure.
  51. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  52. fn_print_fail_nl "Still no logs found, cannot retrieve server version"
  53. fn_script_log_fatal "Still no logs found, cannot retrieve server version"
  54. core_exit.sh
  55. else
  56. fn_print_ok_nl "Logs found"
  57. fn_script_log "Logs found"
  58. sleep 1
  59. fi
  60. fi
  61. # Get current build from logs
  62. currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | egrep 'Murmur ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | awk '{print $4}')
  63. if [ -z "${currentbuild}" ]; then
  64. fn_print_info_nl "Can't find current build version in logs"
  65. fn_script_log_error "Can't find current build version in logs"
  66. sleep 1
  67. fn_print_info_nl "Forcing server restart"
  68. fn_script_log_info "Forcing server restart"
  69. exitbypass=1
  70. command_stop.sh
  71. exitbypass=1
  72. command_start.sh
  73. currentbuild=$(cat "${consolelogdir}"/"${servicename}"-console.log 2> /dev/null | sort | egrep 'Murmur ((\.)?[0-9]{1,3}){1,3}\.[0-9]{1,3}' | awk '{print $4}')
  74. if [ -z "${currentbuild}" ]; then
  75. fn_print_fail_nl "Sorry, current build version still not found"
  76. fn_script_log_fatal "Sorry, current build version still not found"
  77. core_exit.sh
  78. fi
  79. fi
  80. }
  81. fn_update_mumble_compare(){
  82. # Removes dots so if can compare version numbers
  83. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  84. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  85. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  86. echo -e "\n"
  87. echo -e "Update available:"
  88. sleep 1
  89. echo -e " Current build: ${red}${currentbuild} ${mumblearch}${default}"
  90. echo -e " Available build: ${green}${availablebuild} ${mumblearch}${default}"
  91. echo -e ""
  92. sleep 1
  93. echo ""
  94. echo -en "Applying update.\r"
  95. sleep 1
  96. echo -en "Applying update..\r"
  97. sleep 1
  98. echo -en "Applying update...\r"
  99. sleep 1
  100. echo -en "\n"
  101. fn_script_log "Update available"
  102. fn_script_log "Current build: ${currentbuild}"
  103. fn_script_log "Available build: ${availablebuild}"
  104. fn_script_log "${currentbuild} > ${availablebuild}"
  105. unset updateonstart
  106. check_status.sh
  107. if [ "${status}" == "0" ]; then
  108. fn_update_mumble_dl
  109. exitbypass=1
  110. command_start.sh
  111. exitbypass=1
  112. command_stop.sh
  113. else
  114. exitbypass=1
  115. command_stop.sh
  116. fn_update_mumble_dl
  117. exitbypass=1
  118. command_start.sh
  119. fi
  120. alert="update"
  121. alert.sh
  122. else
  123. echo -e "\n"
  124. echo -e "No update available:"
  125. echo -e " Current version: ${green}${currentbuild}${default}"
  126. echo -e " Available version: ${green}${availablebuild}${default}"
  127. echo -e ""
  128. fn_print_ok_nl "No update available"
  129. fn_script_log_info "Current build: ${currentbuild}"
  130. fn_script_log_info "Available build: ${availablebuild}"
  131. fi
  132. }
  133. fn_update_mumble_dl(){
  134. mumblebuildname="murmur-static_${mumblearch}-${availablebuild}"
  135. if [ ! -f "${lgsmdir}/tmp" ]; then
  136. mkdir "${lgsmdir}/tmp"
  137. fi
  138. fn_fetch_file "https://github.com/mumble-voip/mumble/releases/download/${availablebuild}/${mumblebuildname}.tar.bz2" "${lgsmdir}/tmp" "${mumblebuildname}.tar.bz2"
  139. fn_dl_extract "${lgsmdir}/tmp" "${mumblebuildname}" "${lgsmdir}/tmp"
  140. echo -e "copying to ${filesdir}...\c"
  141. fn_script_log "Copying to ${filesdir}"
  142. cp -R "${lgsmdir}/tmp/${mumblebuildname}/"* "${filesdir}"
  143. rm -R "${lgsmdir}/tmp"
  144. local exitcode=$?
  145. if [ ${exitcode} -eq 0 ]; then
  146. fn_print_ok_eol_nl
  147. else
  148. fn_print_fail_eol_nl
  149. fi
  150. }
  151. fn_update_mumble_arch
  152. if [ "${installer}" == "1" ]; then
  153. fn_update_mumble_availablebuild
  154. fn_update_mumble_dl
  155. else
  156. # Checks for server update from teamspeak.com using a mirror dl.4players.de.
  157. fn_print_dots "Checking for update: github.com"
  158. fn_script_log_info "Checking for update: github.com"
  159. sleep 1
  160. fn_update_mumble_currentbuild
  161. fn_update_mumble_availablebuild
  162. fn_update_mumble_compare
  163. fi