4
0

update_ut99.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "${remotebuild}" > "${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. local attempt
  34. for attempt in 1 2 3; do
  35. remotebuildresponse=$(curl --connect-timeout 10 --max-time 30 --fail --silent --show-error --location "${apiurl}") || remotebuildresponse=""
  36. remotebuild=$(echo "${remotebuildresponse}" | jq -er 'select((.tag_name | type) == "string" and (.tag_name | length) > 0) | .tag_name' 2> /dev/null) || remotebuild=""
  37. remotebuildasset=$(echo "${remotebuildresponse}" | jq -cer '[.assets[]? | select((.browser_download_url | type) == "string" and (.browser_download_url | contains("Linux-amd64")))] | select(length == 1) | .[0]' 2> /dev/null) || remotebuildasset=""
  38. remotebuildfilename=$(echo "${remotebuildasset}" | jq -er 'select((.name | type) == "string" and (.name | length) > 0) | .name' 2> /dev/null) || remotebuildfilename=""
  39. remotebuildurl=$(echo "${remotebuildasset}" | jq -er 'select((.browser_download_url | type) == "string" and (.browser_download_url | length) > 0) | .browser_download_url' 2> /dev/null) || remotebuildurl=""
  40. if [ -n "${remotebuild}" ] && [ -n "${remotebuildfilename}" ] && [ -n "${remotebuildurl}" ]; then
  41. break
  42. fi
  43. if [ "${attempt}" -lt 3 ]; then
  44. sleep 2
  45. fi
  46. done
  47. if [ "${firstcommandname}" != "INSTALL" ]; then
  48. fn_print_dots "Checking remote build: ${remotelocation}"
  49. # Checks if remotebuild variable has been set.
  50. if [ -z "${remotebuild}" ] || [ -z "${remotebuildfilename}" ] || [ -z "${remotebuildurl}" ]; then
  51. fn_print_fail "Checking remote build: ${remotelocation}"
  52. fn_script_log_fail "Checking remote build"
  53. core_exit.sh
  54. else
  55. fn_print_ok "Checking remote build: ${remotelocation}"
  56. fn_script_log_pass "Checking remote build"
  57. fi
  58. else
  59. # Checks if remotebuild variable has been set.
  60. if [ -z "${remotebuild}" ] || [ -z "${remotebuildfilename}" ] || [ -z "${remotebuildurl}" ]; then
  61. fn_print_failure "Unable to get remote build"
  62. fn_script_log_fail "Unable to get remote build"
  63. core_exit.sh
  64. fi
  65. fi
  66. }
  67. fn_update_compare() {
  68. fn_print_dots "Checking for update: ${remotelocation}"
  69. # Update has been found or force update.
  70. if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
  71. # Create update lockfile.
  72. date '+%s' > "${lockdir:?}/update.lock"
  73. fn_print_ok_nl "Checking for update: ${remotelocation}"
  74. fn_print "\n"
  75. fn_print_nl "${bold}${underline}Update${default} available"
  76. fn_print_nl "* Local build: ${red}${localbuild}${default}"
  77. fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
  78. if [ -n "${branch}" ]; then
  79. fn_print_nl "* Branch: ${branch}"
  80. fi
  81. if [ -f "${rootdir}/.dev-debug" ]; then
  82. fn_print_nl "Remote build info"
  83. fn_print_nl "* apiurl: ${apiurl}"
  84. fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
  85. fn_print_nl "* remotebuildurl: ${remotebuildurl}"
  86. fn_print_nl "* remotebuild: ${remotebuild}"
  87. fi
  88. fn_print "\n"
  89. fn_script_log_info "Update available"
  90. fn_script_log_info "Local build: ${localbuild}"
  91. fn_script_log_info "Remote build: ${remotebuild}"
  92. if [ -n "${branch}" ]; then
  93. fn_script_log_info "Branch: ${branch}"
  94. fi
  95. fn_script_log_info "${localbuild} > ${remotebuild}"
  96. if [ "${commandname}" == "UPDATE" ]; then
  97. unset updateonstart
  98. fn_update_apply fn_update_dl
  99. if [ "${updatestatus}" == "0" ] && [ "${localbuild}" == "0" ]; then
  100. exitbypass=1
  101. command_start.sh
  102. fn_firstcommand_reset
  103. exitbypass=1
  104. fn_sleep_time_5
  105. command_stop.sh
  106. fn_firstcommand_reset
  107. fi
  108. unset exitbypass
  109. alert="update"
  110. elif [ "${commandname}" == "CHECK-UPDATE" ]; then
  111. alert="check-update"
  112. fi
  113. alert.sh
  114. else
  115. fn_print_ok_nl "Checking for update: ${remotelocation}"
  116. fn_print "\n"
  117. fn_print_nl "${bold}${underline}No update${default} available"
  118. fn_print_nl "* Local build: ${green}${localbuild}${default}"
  119. fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
  120. if [ -n "${branch}" ]; then
  121. fn_print_nl "* Branch: ${branch}"
  122. fi
  123. fn_print "\n"
  124. fn_script_log_info "No update available"
  125. fn_script_log_info "Local build: ${localbuild}"
  126. fn_script_log_info "Remote build: ${remotebuild}"
  127. if [ -n "${branch}" ]; then
  128. fn_script_log_info "Branch: ${branch}"
  129. fi
  130. if [ -f "${rootdir}/.dev-debug" ]; then
  131. fn_print_nl "Remote build info"
  132. fn_print_nl "* apiurl: ${apiurl}"
  133. fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
  134. fn_print_nl "* remotebuildurl: ${remotebuildurl}"
  135. fn_print_nl "* remotebuild: ${remotebuild}"
  136. fi
  137. fi
  138. }
  139. # The location where the builds are checked and downloaded.
  140. remotelocation="github.com"
  141. if [ "${firstcommandname}" == "INSTALL" ]; then
  142. fn_update_remotebuild
  143. fn_update_dl
  144. else
  145. fn_print_dots "Checking for update"
  146. fn_print_dots "Checking for update: ${remotelocation}"
  147. fn_script_log_info "Checking for update: ${remotelocation}"
  148. fn_update_localbuild
  149. fn_update_remotebuild
  150. fn_update_compare
  151. fi