update_ut99.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/bash
  2. # LinuxGSM command_ut99.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Handles updating of Unreal Tournament 99 servers.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_update_dl() {
  9. # Download and extract files to serverfiles.
  10. fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "nohash"
  11. fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
  12. echo "${remotebuildversion}" > "${serverfiles}/build.txt"
  13. fn_clear_tmp
  14. }
  15. fn_update_localbuild() {
  16. # Gets local build info.
  17. fn_print_dots "Checking local build: ${remotelocation}"
  18. # Uses build file to get local build.
  19. localbuild=$(head -n 1 "${serverfiles}/build.txt" 2> /dev/null)
  20. if [ -z "${localbuild}" ]; then
  21. fn_print_error "Checking local build: ${remotelocation}: missing local build info"
  22. fn_script_log_error "Missing local build info"
  23. fn_script_log_error "Set localbuild to 0"
  24. localbuild="0"
  25. else
  26. fn_print_ok "Checking local build: ${remotelocation}"
  27. fn_script_log_pass "Checking local build"
  28. fi
  29. }
  30. fn_update_remotebuild() {
  31. # Gets remote build info.
  32. apiurl="https://api.github.com/repos/OldUnreal/UnrealTournamentPatches/releases/latest"
  33. remotebuildresponse=$(curl -s "${apiurl}")
  34. remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .name')
  35. remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[]|select(.browser_download_url | contains("Linux-amd64")) | .browser_download_url')
  36. remotebuildversion=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
  37. if [ "${firstcommandname}" != "INSTALL" ]; then
  38. fn_print_dots "Checking remote build: ${remotelocation}"
  39. # Checks if remotebuildversion variable has been set.
  40. if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
  41. fn_print_fail "Checking remote build: ${remotelocation}"
  42. fn_script_log_fail "Checking remote build"
  43. core_exit.sh
  44. else
  45. fn_print_ok "Checking remote build: ${remotelocation}"
  46. fn_script_log_pass "Checking remote build"
  47. fi
  48. else
  49. # Checks if remotebuild variable has been set.
  50. if [ -z "${remotebuildversion}" ] || [ "${remotebuildversion}" == "null" ]; then
  51. fn_print_failure "Unable to get remote build"
  52. fn_script_log_fail "Unable to get remote build"
  53. core_exit.sh
  54. fi
  55. fi
  56. }
  57. fn_update_compare() {
  58. fn_print_dots "Checking for update: ${remotelocation}"
  59. # Update has been found or force update.
  60. if [ "${localbuild}" != "${remotebuildversion}" ] || [ "${forceupdate}" == "1" ]; then
  61. # Create update lockfile.
  62. date '+%s' > "${lockdir:?}/update.lock"
  63. fn_print_ok_nl "Checking for update: ${remotelocation}"
  64. echo -en "\n"
  65. echo -e "Update available"
  66. echo -e "* Local build: ${red}${localbuild}${default}"
  67. echo -e "* Remote build: ${green}${remotebuildversion}${default}"
  68. if [ -n "${branch}" ]; then
  69. echo -e "* Branch: ${branch}"
  70. fi
  71. if [ -f "${rootdir}/.dev-debug" ]; then
  72. echo -e "Remote build info"
  73. echo -e "* apiurl: ${apiurl}"
  74. echo -e "* remotebuildfilename: ${remotebuildfilename}"
  75. echo -e "* remotebuildurl: ${remotebuildurl}"
  76. echo -e "* remotebuildversion: ${remotebuildversion}"
  77. fi
  78. echo -en "\n"
  79. fn_script_log_info "Update available"
  80. fn_script_log_info "Local build: ${localbuild}"
  81. fn_script_log_info "Remote build: ${remotebuildversion}"
  82. if [ -n "${branch}" ]; then
  83. fn_script_log_info "Branch: ${branch}"
  84. fi
  85. fn_script_log_info "${localbuild} > ${remotebuildversion}"
  86. if [ "${commandname}" == "UPDATE" ]; then
  87. date +%s > "${lockdir}/last-updated.lock"
  88. unset updateonstart
  89. check_status.sh
  90. # If server stopped.
  91. if [ "${status}" == "0" ]; then
  92. fn_update_dl
  93. if [ "${localbuild}" == "0" ]; then
  94. exitbypass=1
  95. command_start.sh
  96. fn_firstcommand_reset
  97. exitbypass=1
  98. fn_sleep_time_5
  99. command_stop.sh
  100. fn_firstcommand_reset
  101. fi
  102. # If server started.
  103. else
  104. fn_print_restart_warning
  105. exitbypass=1
  106. command_stop.sh
  107. fn_firstcommand_reset
  108. exitbypass=1
  109. fn_update_dl
  110. exitbypass=1
  111. command_start.sh
  112. fn_firstcommand_reset
  113. fi
  114. unset exitbypass
  115. alert="update"
  116. elif [ "${commandname}" == "CHECK-UPDATE" ]; then
  117. alert="check-update"
  118. fi
  119. alert.sh
  120. else
  121. fn_print_ok_nl "Checking for update: ${remotelocation}"
  122. echo -en "\n"
  123. echo -e "No update available"
  124. echo -e "* Local build: ${green}${localbuild}${default}"
  125. echo -e "* Remote build: ${green}${remotebuildversion}${default}"
  126. if [ -n "${branch}" ]; then
  127. echo -e "* Branch: ${branch}"
  128. fi
  129. echo -en "\n"
  130. fn_script_log_info "No update available"
  131. fn_script_log_info "Local build: ${localbuild}"
  132. fn_script_log_info "Remote build: ${remotebuildversion}"
  133. if [ -n "${branch}" ]; then
  134. fn_script_log_info "Branch: ${branch}"
  135. fi
  136. if [ -f "${rootdir}/.dev-debug" ]; then
  137. echo -e "Remote build info"
  138. echo -e "* apiurl: ${apiurl}"
  139. echo -e "* remotebuildfilename: ${remotebuildfilename}"
  140. echo -e "* remotebuildurl: ${remotebuildurl}"
  141. echo -e "* remotebuildversion: ${remotebuildversion}"
  142. fi
  143. fi
  144. }
  145. # The location where the builds are checked and downloaded.
  146. remotelocation="github.com"
  147. if [ ! "$(command -v jq 2> /dev/null)" ]; then
  148. fn_print_fail_nl "jq is not installed"
  149. fn_script_log_fail "jq is not installed"
  150. core_exit.sh
  151. fi
  152. if [ "${firstcommandname}" == "INSTALL" ]; then
  153. fn_update_remotebuild
  154. fn_update_dl
  155. else
  156. fn_print_dots "Checking for update"
  157. fn_print_dots "Checking for update: ${remotelocation}"
  158. fn_script_log_info "Checking for update: ${remotelocation}"
  159. fn_update_localbuild
  160. fn_update_remotebuild
  161. fn_update_compare
  162. fi