update_etl.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. # LinuxGSM update_etl.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Handles updating of ET: Legacy 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" "${remotebuildhash}"
  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. # Try to get build version from etconsole.log.
  19. if [ -f "${gamelogdir}/etconsole.log" ]; then
  20. localbuild=$(grep "Initializing legacy game" "${gamelogdir}/etconsole.log" | sed -n 's/.*\^2\(v[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/p' | tail -1)
  21. fi
  22. # Fall back to build.txt if log parse failed or log does not exist.
  23. if [ -z "${localbuild}" ]; then
  24. localbuild=$(head -n 1 "${serverfiles}/build.txt" 2> /dev/null)
  25. fi
  26. if [ -z "${localbuild}" ]; then
  27. fn_print_error "Checking local build: ${remotelocation}: missing local build info"
  28. fn_script_log_error "Missing local build info"
  29. fn_script_log_error "Set localbuild to 0"
  30. localbuild="0"
  31. else
  32. fn_print_ok "Checking local build: ${remotelocation}"
  33. fn_script_log_pass "Checking local build"
  34. fi
  35. }
  36. fn_update_remotebuild() {
  37. # Gets remote build info.
  38. apiurl="https://api.github.com/repos/GameServerManagers/etlserver-build/releases/latest"
  39. remotebuildresponse=$(curl -s "${apiurl}")
  40. remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[] | select(.browser_download_url | contains("i386-et-260b")) | .name')
  41. remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[] | select(.browser_download_url | contains("i386-et-260b")) | .browser_download_url')
  42. remotebuild=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
  43. remotebuildhash=$(echo "${remotebuildresponse}" | jq -r '.body' | grep 'MD5' | grep -oE '[a-f0-9]{32}')
  44. if [ "${firstcommandname}" != "INSTALL" ]; then
  45. fn_print_dots "Checking remote build: ${remotelocation}"
  46. # Checks if remotebuild variable has been set.
  47. if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
  48. fn_print_fail "Checking remote build: ${remotelocation}"
  49. fn_script_log_fail "Checking remote build"
  50. core_exit.sh
  51. else
  52. fn_print_ok "Checking remote build: ${remotelocation}"
  53. fn_script_log_pass "Checking remote build"
  54. fi
  55. else
  56. # Checks if remotebuild variable has been set.
  57. if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
  58. fn_print_failure "Unable to get remote build"
  59. fn_script_log_fail "Unable to get remote build"
  60. core_exit.sh
  61. fi
  62. fi
  63. }
  64. fn_update_compare() {
  65. fn_print_dots "Checking for update: ${remotelocation}"
  66. # Update has been found or force update.
  67. if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
  68. # Create update lockfile.
  69. date '+%s' > "${lockdir:?}/update.lock"
  70. fn_print_ok_nl "Checking for update: ${remotelocation}"
  71. fn_print "\n"
  72. fn_print_nl "${bold}${underline}Update${default} available"
  73. fn_print_nl "* Local build: ${red}${localbuild}${default}"
  74. fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
  75. if [ -n "${branch}" ]; then
  76. fn_print_nl "* Branch: ${branch}"
  77. fi
  78. if [ -f "${rootdir}/.dev-debug" ]; then
  79. fn_print_nl "Remote build info"
  80. fn_print_nl "* apiurl: ${apiurl}"
  81. fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
  82. fn_print_nl "* remotebuildurl: ${remotebuildurl}"
  83. fn_print_nl "* remotebuild: ${remotebuild}"
  84. fi
  85. fn_print "\n"
  86. fn_script_log_info "Update available"
  87. fn_script_log_info "Local build: ${localbuild}"
  88. fn_script_log_info "Remote build: ${remotebuild}"
  89. if [ -n "${branch}" ]; then
  90. fn_script_log_info "Branch: ${branch}"
  91. fi
  92. fn_script_log_info "${localbuild} > ${remotebuild}"
  93. if [ "${commandname}" == "UPDATE" ]; then
  94. unset updateonstart
  95. fn_update_apply fn_update_dl
  96. if [ "${updatestatus}" == "0" ] && [ "${localbuild}" == "0" ]; then
  97. exitbypass=1
  98. command_start.sh
  99. fn_firstcommand_reset
  100. exitbypass=1
  101. fn_sleep_time_5
  102. command_stop.sh
  103. fn_firstcommand_reset
  104. fi
  105. unset exitbypass
  106. alert="update"
  107. elif [ "${commandname}" == "CHECK-UPDATE" ]; then
  108. alert="check-update"
  109. fi
  110. alert.sh
  111. else
  112. fn_print_ok_nl "Checking for update: ${remotelocation}"
  113. fn_print "\n"
  114. fn_print_nl "${bold}${underline}No update${default} available"
  115. fn_print_nl "* Local build: ${green}${localbuild}${default}"
  116. fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
  117. if [ -n "${branch}" ]; then
  118. fn_print_nl "* Branch: ${branch}"
  119. fi
  120. fn_print "\n"
  121. fn_script_log_info "No update available"
  122. fn_script_log_info "Local build: ${localbuild}"
  123. fn_script_log_info "Remote build: ${remotebuild}"
  124. if [ -n "${branch}" ]; then
  125. fn_script_log_info "Branch: ${branch}"
  126. fi
  127. if [ -f "${rootdir}/.dev-debug" ]; then
  128. fn_print_nl "Remote build info"
  129. fn_print_nl "* apiurl: ${apiurl}"
  130. fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
  131. fn_print_nl "* remotebuildurl: ${remotebuildurl}"
  132. fn_print_nl "* remotebuild: ${remotebuild}"
  133. fi
  134. fi
  135. }
  136. # The location where the builds are checked and downloaded.
  137. remotelocation="github.com"
  138. if [ "${firstcommandname}" == "INSTALL" ]; then
  139. fn_update_remotebuild
  140. fn_update_dl
  141. else
  142. fn_print_dots "Checking for update"
  143. fn_print_dots "Checking for update: ${remotelocation}"
  144. fn_script_log_info "Checking for update: ${remotelocation}"
  145. fn_update_localbuild
  146. fn_update_remotebuild
  147. fn_update_compare
  148. fi