update_mumble.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/bin/bash
  2. # LinuxGSM update_mumble.sh function
  3. # Author: Daniel Gibbs
  4. # Contributor: UltimateByte
  5. # Website: https://linuxgsm.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 ${serverfiles}...\c"
  14. fn_script_log "Copying to ${serverfiles}"
  15. cp -R "${tmpdir}/murmur-static_${mumblearch}-${availablebuild}/"* "${serverfiles}"
  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 0.5
  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 0.5
  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 0.5
  35. exitbypass=1
  36. command_stop.sh
  37. exitbypass=1
  38. command_start.sh
  39. sleep 0.5
  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 | grep -E '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 0.5
  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 | grep -E '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=$(${curlpath} -s https://api.github.com/repos/mumble-voip/mumble/releases/latest | grep 'murmur-static_x86.*\.bz2"' | tail -1 | awk -F"/" '{ print $8 }')
  74. sleep 0.5
  75. # Checks if availablebuild variable has been set
  76. if [ -z "${availablebuild}" ]; then
  77. fn_print_fail "Checking for update: GitHub"
  78. sleep 0.5
  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 0.5
  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 0.5
  98. echo -e " Current build: ${red}${currentbuild} ${mumblearch}${default}"
  99. echo -e " Available build: ${green}${availablebuild} ${mumblearch}${default}"
  100. echo -e ""
  101. sleep 0.5
  102. echo -en "Applying update.\r"
  103. sleep 1
  104. echo -en "Applying update..\r"
  105. sleep 1
  106. echo -en "Applying update...\r"
  107. sleep 1
  108. echo -en "\n"
  109. fn_script_log "Update available"
  110. fn_script_log "Current build: ${currentbuild}"
  111. fn_script_log "Available build: ${availablebuild}"
  112. fn_script_log "${currentbuild} > ${availablebuild}"
  113. unset updateonstart
  114. check_status.sh
  115. if [ "${status}" == "0" ]; then
  116. fn_update_mumble_dl
  117. exitbypass=1
  118. command_start.sh
  119. exitbypass=1
  120. command_stop.sh
  121. else
  122. exitbypass=1
  123. command_stop.sh
  124. fn_update_mumble_dl
  125. exitbypass=1
  126. command_start.sh
  127. fi
  128. alert="update"
  129. alert.sh
  130. else
  131. echo -e "\n"
  132. echo -e "No update available:"
  133. echo -e " Current version: ${green}${currentbuild}${default}"
  134. echo -e " Available version: ${green}${availablebuild}${default}"
  135. echo -e ""
  136. fn_print_ok_nl "No update available"
  137. fn_script_log_info "Current build: ${currentbuild}"
  138. fn_script_log_info "Available build: ${availablebuild}"
  139. fi
  140. }
  141. fn_update_mumble_arch
  142. if [ "${installer}" == "1" ]; then
  143. fn_update_mumble_availablebuild
  144. fn_update_mumble_dl
  145. else
  146. # Checks for server update from github.com
  147. fn_print_dots "Checking for update: github.com"
  148. fn_script_log_info "Checking for update: github.com"
  149. sleep 0.5
  150. fn_update_mumble_currentbuild
  151. fn_update_mumble_availablebuild
  152. fn_update_mumble_compare
  153. fi