update_mumble.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 latest build info.
  16. fn_print_info_nl "Checking latest build from github.com"
  17. fn_script_log "Checking latest build 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 latest build from github.com"
  23. sleep 1
  24. fn_print_fail "Checking latest build from github.com: Not returning version info"
  25. fn_script_log_fatal "Checking latest build from github.com: Not returning version info"
  26. core_exit.sh
  27. else
  28. fn_print_ok_nl "Checked latest build from github.com"
  29. fn_script_log_pass "Checked latest build from github.com"
  30. sleep 1
  31. fi
  32. }
  33. fn_update_mumble_currentbuild(){
  34. # Gets current build info
  35. fn_print_info "Checking installed 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. check_status.sh
  46. if [ "${status}" != "0" ]; then
  47. exitbypass=1
  48. command_stop.sh
  49. fi
  50. exitbypass=1
  51. command_start.sh
  52. exitbypass=1
  53. command_stopt.sh
  54. sleep 1
  55. # Check again and exit on failure.
  56. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  57. fn_print_fail_nl "Still no logs found, cannot retrieve server version"
  58. fn_script_log_fatal "Still no logs found, cannot retrieve server version"
  59. core_exit.sh
  60. else
  61. fn_print_ok_nl "Logs found"
  62. fn_script_log "Logs found"
  63. sleep 1
  64. fi
  65. fi
  66. # Get current build from logs
  67. 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}')
  68. if [ -z "${currentbuild}" ]; then
  69. fn_print_info_nl "Can't find current build version in logs"
  70. fn_script_log_error "Can't find current build version in logs"
  71. sleep 1
  72. fn_print_info_nl "Forcing server restart"
  73. fn_script_log_info "Forcing server restart"
  74. exitbypass=1
  75. command_stop.sh
  76. exitbypass=1
  77. command_start.sh
  78. 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}')
  79. if [ -z "${currentbuild}" ]; then
  80. fn_print_fail_nl "Sorry, current build version still not found"
  81. fn_script_log_fatal "Sorry, current build version still not found"
  82. core_exit.sh
  83. fi
  84. fi
  85. }
  86. fn_update_mumble_compare(){
  87. # Removes dots so if can compare version numbers
  88. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  89. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  90. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  91. echo -e "\n"
  92. echo -e "Update available:"
  93. sleep 1
  94. echo -e " Current build: ${red}${currentbuild} ${mumblearch}${default}"
  95. echo -e " Available build: ${green}${availablebuild} ${mumblearch}${default}"
  96. echo -e ""
  97. sleep 1
  98. echo ""
  99. echo -en "Applying update.\r"
  100. sleep 1
  101. echo -en "Applying update..\r"
  102. sleep 1
  103. echo -en "Applying update...\r"
  104. sleep 1
  105. echo -en "\n"
  106. fn_script_log "Update available"
  107. fn_script_log "Current build: ${currentbuild}"
  108. fn_script_log "Available build: ${availablebuild}"
  109. fn_script_log "${currentbuild} > ${availablebuild}"
  110. unset updateonstart
  111. check_status.sh
  112. if [ "${status}" == "0" ]; then
  113. fn_update_mumble_dl
  114. exitbypass=1
  115. command_start.sh
  116. exitbypass=1
  117. command_stop.sh
  118. else
  119. exitbypass=1
  120. command_stop.sh
  121. fn_update_mumble_dl
  122. exitbypass=1
  123. command_start.sh
  124. fi
  125. alert="update"
  126. alert.sh
  127. else
  128. echo -e "\n"
  129. echo -e "No update available:"
  130. echo -e " Current version: ${green}${currentbuild}${default}"
  131. echo -e " Available version: ${green}${availablebuild}${default}"
  132. echo -e ""
  133. fn_print_ok_nl "No update available"
  134. fn_script_log_info "Current build: ${currentbuild}"
  135. fn_script_log_info "Available build: ${availablebuild}"
  136. fi
  137. }
  138. fn_update_mumble_dl(){
  139. mumblebuildname="murmur-static_${mumblearch}-${availablebuild}"
  140. if [ ! -d "${lgsmdir}/tmp" ]; then
  141. mkdir "${lgsmdir}/tmp"
  142. fi
  143. fn_fetch_file "https://github.com/mumble-voip/mumble/releases/download/${availablebuild}/${mumblebuildname}.tar.bz2" "${lgsmdir}/tmp" "${mumblebuildname}.tar.bz2"
  144. fn_dl_extract "${lgsmdir}/tmp" "${mumblebuildname}.tar.bz2" "${lgsmdir}/tmp"
  145. echo -e "copying to ${filesdir}...\c"
  146. fn_script_log "Copying to ${filesdir}"
  147. cp -R "${lgsmdir}/tmp/${mumblebuildname}/"* "${filesdir}"
  148. rm -R "${lgsmdir}/tmp"
  149. local exitcode=$?
  150. if [ ${exitcode} -eq 0 ]; then
  151. fn_print_ok_eol_nl
  152. else
  153. fn_print_fail_eol_nl
  154. fi
  155. }
  156. fn_update_mumble_arch
  157. if [ "${installer}" == "1" ]; then
  158. fn_update_mumble_availablebuild
  159. fn_update_mumble_dl
  160. else
  161. # Checks for server update from github.com
  162. fn_print_dots "Checking for update: github.com"
  163. fn_script_log_info "Checking for update: github.com"
  164. sleep 1
  165. fn_update_mumble_currentbuild
  166. fn_update_mumble_availablebuild
  167. fn_update_mumble_compare
  168. fi