update_mumble.sh 4.7 KB

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