update_mumble.sh 4.9 KB

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