update_mumble.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/bash
  2. # LinuxGSM update_mumble.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Handles updating of Mumble servers.
  6. local commandname="UPDATE"
  7. local commandaction="Update"
  8. local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  9. fn_update_mumble_dl(){
  10. fn_fetch_file "https://github.com/mumble-voip/mumble/releases/download/${remotebuild}/murmur-static_${mumblearch}-${remotebuild}.tar.bz2" "${tmpdir}" "murmur-static_${mumblearch}-${remotebuild}.tar.bz2"
  11. fn_dl_extract "${tmpdir}" "murmur-static_${mumblearch}-${remotebuild}.tar.bz2" "${tmpdir}"
  12. echo -e "copying to ${serverfiles}...\c"
  13. cp -R "${tmpdir}/murmur-static_${mumblearch}-${remotebuild}/"* "${serverfiles}"
  14. local exitcode=$?
  15. if [ "${exitcode}" == "0" ]; then
  16. fn_print_ok_eol_nl
  17. fn_script_log_pass "Copying to ${serverfiles}"
  18. fn_clear_tmp
  19. else
  20. fn_print_fail_eol_nl
  21. fn_script_log_fatal "Copying to ${serverfiles}"
  22. core_exit.sh
  23. fi
  24. }
  25. fn_update_mumble_localbuild(){
  26. # Gets local build info.
  27. fn_print_dots "Checking for update: ${remotelocation}: checking local build"
  28. sleep 0.5
  29. # Uses executable to find local build.
  30. cd "${executabledir}" || exit
  31. if [ -f "${executable}" ]; then
  32. localbuild=$(${executable} -version 2>&1 >/dev/null | awk '{print $5}')
  33. fn_print_ok "Checking for update: ${remotelocation}: checking local build"
  34. fn_script_log_pass "Checking local build"
  35. else
  36. localbuild="0"
  37. fn_print_error "Checking for update: ${remotelocation}: checking local build"
  38. fn_script_log_error "Checking local build"
  39. fi
  40. sleep 0.5
  41. }
  42. fn_update_mumble_remotebuild(){
  43. # Gets remote build info.
  44. remotebuild=$(${curlpath} -s "https://api.github.com/repos/mumble-voip/mumble/releases/latest" | grep 'murmur-static_x86.*\.bz2"' | tail -1 | awk -F"/" '{ print $8 }')
  45. if [ "${installer}" != "1" ]; then
  46. fn_print_dots "Checking for update: ${remotelocation}: checking remote build"
  47. sleep 0.5
  48. # Checks if remotebuild variable has been set.
  49. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  50. fn_print_fail "Checking for update: ${remotelocation}: checking remote build"
  51. fn_script_log_fatal "Checking remote build"
  52. core_exit.sh
  53. else
  54. fn_print_ok "Checking for update: ${remotelocation}: checking remote build"
  55. fn_script_log_pass "Checking remote build"
  56. sleep 0.5
  57. fi
  58. else
  59. # Checks if remotebuild variable has been set.
  60. if [ -z "${remotebuild}" ]||[ "${remotebuild}" == "null" ]; then
  61. fn_print_failure "Unable to get remote build"
  62. fn_script_log_fatal "Unable to get remote build"
  63. core_exit.sh
  64. fi
  65. fi
  66. }
  67. fn_update_mumble_compare(){
  68. # Removes dots so if statement can compare version numbers.
  69. fn_print_dots "Checking for update: ${remotelocation}"
  70. sleep 0.5
  71. localbuilddigit=$(echo "${localbuild}" | tr -cd '[:digit:]')
  72. remotebuilddigit=$(echo "${remotebuild}" | tr -cd '[:digit:]')
  73. if [ "${localbuilddigit}" -ne "${remotebuilddigit}" ]||[ "${forceupdate}" == "1" ]; then
  74. fn_print_ok_nl "Checking for update: ${remotelocation}"
  75. sleep 0.5
  76. echo -en "\n"
  77. echo -e "Update available"
  78. echo -e "* Local build: ${red}${localbuild} ${mumblearch}${default}"
  79. echo -e "* Remote build: ${green}${remotebuild} ${mumblearch}${default}"
  80. fn_script_log_info "Update available"
  81. fn_script_log_info "Local build: ${localbuild} ${mumblearch}"
  82. fn_script_log_info "Remote build: ${remotebuild} ${mumblearch}"
  83. fn_script_log_info "${localbuild} > ${remotebuild}"
  84. sleep 0.5
  85. echo -en "\n"
  86. echo -en "applying update.\r"
  87. sleep 1
  88. echo -en "applying update..\r"
  89. sleep 1
  90. echo -en "applying update...\r"
  91. sleep 1
  92. echo -en "\n"
  93. unset updateonstart
  94. check_status.sh
  95. # If server stopped.
  96. if [ "${status}" == "0" ]; then
  97. exitbypass=1
  98. fn_update_mumble_dl
  99. exitbypass=1
  100. command_start.sh
  101. exitbypass=1
  102. command_stop.sh
  103. # If server started.
  104. else
  105. exitbypass=1
  106. command_stop.sh
  107. exitbypass=1
  108. fn_update_mumble_dl
  109. exitbypass=1
  110. command_start.sh
  111. fi
  112. alert="update"
  113. alert.sh
  114. else
  115. fn_print_ok_nl "Checking for update: ${remotelocation}"
  116. sleep 0.5
  117. echo -en "\n"
  118. echo -e "No update available"
  119. echo -e "* Local build: ${green}${localbuild} ${mumblearch}${default}"
  120. echo -e "* Remote build: ${green}${remotebuild} ${mumblearch}${default}"
  121. fn_script_log_info "No update available"
  122. fn_script_log_info "Local build: ${localbuild} ${mumblearch}"
  123. fn_script_log_info "Remote build: ${remotebuild} ${mumblearch}"
  124. fi
  125. }
  126. # The location where the builds are checked and downloaded.
  127. remotelocation="mumble.info"
  128. # Game server architecture.
  129. mumblearch="x86"
  130. if [ "${installer}" == "1" ]; then
  131. fn_update_mumble_remotebuild
  132. fn_update_mumble_dl
  133. else
  134. fn_print_dots "Checking for update: ${remotelocation}"
  135. fn_script_log_info "Checking for update: ${remotelocation}"
  136. sleep 0.5
  137. fn_update_mumble_localbuild
  138. fn_update_mumble_remotebuild
  139. fn_update_mumble_compare
  140. fi