|
| 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 | + |
| 8 | +moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" |
| 9 | + |
| 10 | +fn_update_dl() { |
| 11 | + # Download and extract files to serverfiles. |
| 12 | + fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}" |
| 13 | + fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}" |
| 14 | + echo "${remotebuild}" > "${serverfiles}/build.txt" |
| 15 | + fn_clear_tmp |
| 16 | +} |
| 17 | + |
| 18 | +fn_update_localbuild() { |
| 19 | + # Gets local build info. |
| 20 | + fn_print_dots "Checking local build: ${remotelocation}" |
| 21 | + # Uses build file to get local build. |
| 22 | + localbuild=$(head -n 1 "${serverfiles}/build.txt" 2> /dev/null) |
| 23 | + if [ -z "${localbuild}" ]; then |
| 24 | + fn_print_error "Checking local build: ${remotelocation}: missing local build info" |
| 25 | + fn_script_log_error "Missing local build info" |
| 26 | + fn_script_log_error "Set localbuild to 0" |
| 27 | + localbuild="0" |
| 28 | + else |
| 29 | + fn_print_ok "Checking local build: ${remotelocation}" |
| 30 | + fn_script_log_pass "Checking local build" |
| 31 | + fi |
| 32 | +} |
| 33 | + |
| 34 | +fn_update_remotebuild() { |
| 35 | + # Gets remote build info. |
| 36 | + apiurl="https://api.github.com/repos/GameServerManagers/etlserver-build/releases/latest" |
| 37 | + remotebuildresponse=$(curl -s "${apiurl}") |
| 38 | + remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[] | select(.browser_download_url | contains("i386-et-260b")) | .name') |
| 39 | + remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[] | select(.browser_download_url | contains("i386-et-260b")) | .browser_download_url') |
| 40 | + remotebuild=$(echo "${remotebuildresponse}" | jq -r '.tag_name') |
| 41 | + remotebuildhash=$(echo "${remotebuildresponse}" | jq -r '.body' | grep 'MD5' | awk '{print $NF}') |
| 42 | + |
| 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_fail "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_fail "Unable to get remote build" |
| 59 | + core_exit.sh |
| 60 | + fi |
| 61 | + fi |
| 62 | +} |
| 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 | + |
| 94 | + if [ "${commandname}" == "UPDATE" ]; then |
| 95 | + date +%s > "${lockdir:?}/last-updated.lock" |
| 96 | + unset updateonstart |
| 97 | + check_status.sh |
| 98 | + # If server stopped. |
| 99 | + if [ "${status}" == "0" ]; then |
| 100 | + fn_update_dl |
| 101 | + if [ "${localbuild}" == "0" ]; then |
| 102 | + exitbypass=1 |
| 103 | + command_start.sh |
| 104 | + fn_firstcommand_reset |
| 105 | + exitbypass=1 |
| 106 | + fn_sleep_time_5 |
| 107 | + command_stop.sh |
| 108 | + fn_firstcommand_reset |
| 109 | + fi |
| 110 | + # If server started. |
| 111 | + else |
| 112 | + fn_print_restart_warning |
| 113 | + exitbypass=1 |
| 114 | + command_stop.sh |
| 115 | + fn_firstcommand_reset |
| 116 | + exitbypass=1 |
| 117 | + fn_update_dl |
| 118 | + exitbypass=1 |
| 119 | + command_start.sh |
| 120 | + fn_firstcommand_reset |
| 121 | + fi |
| 122 | + unset exitbypass |
| 123 | + alert="update" |
| 124 | + elif [ "${commandname}" == "CHECK-UPDATE" ]; then |
| 125 | + alert="check-update" |
| 126 | + fi |
| 127 | + alert.sh |
| 128 | + else |
| 129 | + fn_print_ok_nl "Checking for update: ${remotelocation}" |
| 130 | + fn_print "\n" |
| 131 | + fn_print_nl "${bold}${underline}No update${default} available" |
| 132 | + fn_print_nl "* Local build: ${green}${localbuild}${default}" |
| 133 | + fn_print_nl "* Remote build: ${green}${remotebuild}${default}" |
| 134 | + if [ -n "${branch}" ]; then |
| 135 | + fn_print_nl "* Branch: ${branch}" |
| 136 | + fi |
| 137 | + fn_print "\n" |
| 138 | + fn_script_log_info "No update available" |
| 139 | + fn_script_log_info "Local build: ${localbuild}" |
| 140 | + fn_script_log_info "Remote build: ${remotebuild}" |
| 141 | + if [ -n "${branch}" ]; then |
| 142 | + fn_script_log_info "Branch: ${branch}" |
| 143 | + fi |
| 144 | + if [ -f "${rootdir}/.dev-debug" ]; then |
| 145 | + fn_print_nl "Remote build info" |
| 146 | + fn_print_nl "* apiurl: ${apiurl}" |
| 147 | + fn_print_nl "* remotebuildfilename: ${remotebuildfilename}" |
| 148 | + fn_print_nl "* remotebuildurl: ${remotebuildurl}" |
| 149 | + fn_print_nl "* remotebuild: ${remotebuild}" |
| 150 | + fi |
| 151 | + fi |
| 152 | +} |
| 153 | + |
| 154 | +# The location where the builds are checked and downloaded. |
| 155 | +remotelocation="github.com" |
| 156 | + |
| 157 | +if [ "${firstcommandname}" == "INSTALL" ]; then |
| 158 | + fn_update_remotebuild |
| 159 | + fn_update_dl |
| 160 | +else |
| 161 | + fn_print_dots "Checking for update" |
| 162 | + fn_print_dots "Checking for update: ${remotelocation}" |
| 163 | + fn_script_log_info "Checking for update: ${remotelocation}" |
| 164 | + fn_update_localbuild |
| 165 | + fn_update_remotebuild |
| 166 | + fn_update_compare |
| 167 | +fi |
0 commit comments