update_mumble.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_dl(){
  11. fn_fetch_file "https://github.com/mumble-voip/mumble/releases/download/${availablebuild}/murmur-static_${mumblearch}-${availablebuild}.tar.bz2" "${tmpdir}" "murmur-static_${mumblearch}-${availablebuild}.tar.bz2"
  12. fn_dl_extract "${tmpdir}" "murmur-static_${mumblearch}-${availablebuild}.tar.bz2" "${tmpdir}"
  13. echo -e "copying to ${filesdir}...\c"
  14. fn_script_log "Copying to ${filesdir}"
  15. cp -R "${tmpdir}/murmur-static_${mumblearch}-${availablebuild}/"* "${filesdir}"
  16. local exitcode=$?
  17. if [ ${exitcode} -eq 0 ]; then
  18. fn_print_ok_eol_nl
  19. else
  20. fn_print_fail_eol_nl
  21. fi
  22. }
  23. fn_update_mumble_currentbuild(){
  24. # Gets current build info
  25. # Checks if current build info is available. If it fails, then a server restart will be forced to generate logs.
  26. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  27. fn_print_error "Checking for update: GitHub"
  28. sleep 1
  29. fn_print_error_nl "Checking for update: GitHub: No logs with server version found"
  30. fn_script_log_error "Checking for update: GitHub: No logs with server version found"
  31. sleep 1
  32. fn_print_info_nl "Checking for update: GitHub: Forcing server restart"
  33. fn_script_log_info "Checking for update: GitHub: Forcing server restart"
  34. sleep 1
  35. exitbypass=1
  36. command_stop.sh
  37. exitbypass=1
  38. command_start.sh
  39. sleep 1
  40. # Check again and exit on failure.
  41. if [ ! -f "${consolelogdir}/${servicename}-console.log" ]; then
  42. fn_print_fail_nl "Checking for update: GitHub: Still No logs with server version found"
  43. fn_script_log_fatal "Checking for update: GitHub: Still No logs with server version found"
  44. core_exit.sh
  45. fi
  46. fi
  47. # Get current build from logs
  48. 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}')
  49. if [ -z "${currentbuild}" ]; then
  50. fn_print_error_nl "Checking for update: GitHub: Current build version not found"
  51. fn_script_log_error "Checking for update: GitHub: Current build version not found"
  52. sleep 1
  53. fn_print_info_nl "Checking for update: GitHub: Forcing server restart"
  54. fn_script_log_info "Checking for update: GitHub: Forcing server restart"
  55. exitbypass=1
  56. command_stop.sh
  57. exitbypass=1
  58. command_start.sh
  59. 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}')
  60. if [ -z "${currentbuild}" ]; then
  61. fn_print_fail_nl "Checking for update: GitHub: Current build version still not found"
  62. fn_script_log_fatal "Checking for update: GitHub: Current build version still not found"
  63. core_exit.sh
  64. fi
  65. fi
  66. }
  67. fn_update_mumble_arch(){
  68. # Mumble is x86 only for now
  69. mumblearch="x86"
  70. }
  71. fn_update_mumble_availablebuild(){
  72. # Gets latest build info.
  73. availablebuild=$(curl -s https://api.github.com/repos/mumble-voip/mumble/releases/latest | grep 'murmur-static_x86.*\.bz2"' | tail -1 | awk -F"/" '{ print $8 }')
  74. sleep 1
  75. # Checks if availablebuild variable has been set
  76. if [ -z "${availablebuild}" ]; then
  77. fn_print_fail "Checking for update: GitHub"
  78. sleep 1
  79. fn_print_fail "Checking for update: GitHub: Not returning version info"
  80. fn_script_log_fatal "Failure! Checking for update: GitHub: Not returning version info"
  81. core_exit.sh
  82. elif [ "${installer}" == "1" ]; then
  83. :
  84. else
  85. fn_print_ok "Checking for update: GitHub"
  86. fn_script_log_pass "Checking for update: GitHub"
  87. sleep 1
  88. fi
  89. }
  90. fn_update_mumble_compare(){
  91. # Removes dots so if can compare version numbers
  92. currentbuilddigit=$(echo "${currentbuild}"|tr -cd '[:digit:]')
  93. availablebuilddigit=$(echo "${availablebuild}"|tr -cd '[:digit:]')
  94. if [ "${currentbuilddigit}" -ne "${availablebuilddigit}" ]; then
  95. echo -e "\n"
  96. echo -e "Update available:"
  97. sleep 1
  98. echo -e " Current build: ${red}${currentbuild} ${mumblearch}${default}"
  99. echo -e " Available build: ${green}${availablebuild} ${mumblearch}${default}"
  100. echo -e ""
  101. sleep 1
  102. echo ""
  103. echo -en "Applying update.\r"
  104. sleep 1
  105. echo -en "Applying update..\r"
  106. sleep 1
  107. echo -en "Applying update...\r"
  108. sleep 1
  109. echo -en "\n"
  110. fn_script_log "Update available"
  111. fn_script_log "Current build: ${currentbuild}"
  112. fn_script_log "Available build: ${availablebuild}"
  113. fn_script_log "${currentbuild} > ${availablebuild}"
  114. unset updateonstart
  115. check_status.sh
  116. if [ "${status}" == "0" ]; then
  117. fn_update_mumble_dl
  118. exitbypass=1
  119. command_start.sh
  120. exitbypass=1
  121. command_stop.sh
  122. else
  123. exitbypass=1
  124. command_stop.sh
  125. fn_update_mumble_dl
  126. exitbypass=1
  127. command_start.sh
  128. fi
  129. alert="update"
  130. alert.sh
  131. else
  132. echo -e "\n"
  133. echo -e "No update available:"
  134. echo -e " Current version: ${green}${currentbuild}${default}"
  135. echo -e " Available version: ${green}${availablebuild}${default}"
  136. echo -e ""
  137. fn_print_ok_nl "No update available"
  138. fn_script_log_info "Current build: ${currentbuild}"
  139. fn_script_log_info "Available build: ${availablebuild}"
  140. fi
  141. }
  142. fn_update_mumble_arch
  143. if [ "${installer}" == "1" ]; then
  144. fn_update_mumble_availablebuild
  145. fn_update_mumble_dl
  146. else
  147. # Checks for server update from github.com
  148. fn_print_dots "Checking for update: github.com"
  149. fn_script_log_info "Checking for update: github.com"
  150. sleep 1
  151. fn_update_mumble_currentbuild
  152. fn_update_mumble_availablebuild
  153. fn_update_mumble_compare
  154. fi