update_mumble.sh 4.6 KB

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