diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2021-12-17 09:51:12 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-17 09:51:12 -0500 |
commit | 52f743c5a7cdd3b56c36ac4c054bf182c5e193b1 (patch) | |
tree | f23fc103a531290a51816e2abb1330b9cec0bd31 /packaging | |
parent | 3a4255b8b38b31cfcfc7623047a418b332d5c6ac (diff) |
Fix the code that checks for available updates. (#11870)
* Make update availability check it0s own function.
And use it to check for updates for static builds too.
* Update existing version detection logic to be far more robust.
This brings it into consistency with the existing install detection code
in the new kickstart script, which correctly handles almost all cases of
existing installs.
* Fix typo.
* Assorted fixes.
* Apply suggestions from code review
Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>
Diffstat (limited to 'packaging')
-rwxr-xr-x | packaging/installer/netdata-updater.sh | 116 |
1 files changed, 69 insertions, 47 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 67c0e71289..713af4775e 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -38,6 +38,8 @@ else script_source="${script_dir}/netdata-updater.sh" fi +PATH="${PATH}:/usr/local/bin:/usr/local/sbin" + info() { echo >&3 "$(date) : INFO: " "${@}" } @@ -257,6 +259,40 @@ get_latest_version() { fi } +update_available() { + basepath="$(dirname "$(dirname "$(dirname "${NETDATA_LIB_DIR}")")")" + searchpath="${basepath}/bin:${basepath}/sbin:${basepath}/usr/bin:${basepath}/usr/sbin:${PATH}" + searchpath="${basepath}/netdata/bin:${basepath}/netdata/sbin:${basepath}/netdata/usr/bin:${basepath}/netdata/usr/sbin:${searchpath}" + ndbinary="$(PATH="${searchpath}" command -v netdata 2>/dev/null)" + + if [ -z "${ndbinary}" ]; then + current_version=0 + else + current_version="$(parse_version "$(${ndbinary} -v | cut -f 2 -d ' ')")" + fi + + latest_tag="$(get_latest_version)" + latest_version="$(parse_version "${latest_tag}")" + path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")" + + # If we can't get the current version for some reason assume `0` + current_version="${current_version:-0}" + + # If we can't get the latest version for some reason assume `0` + latest_version="${latest_version:-0}" + + info "Current Version: ${current_version}" + info "Latest Version: ${latest_version}" + + if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then + info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed" + return 1 + else + info "Update available" + return 0 + fi +} + set_tarball_urls() { extension="tar.gz" @@ -281,37 +317,21 @@ update() { ndtmpdir=$(create_tmp_directory) cd "$ndtmpdir" || exit 1 - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" >&3 2>&3 - - current_version="$(command -v netdata > /dev/null && parse_version "$(netdata -v | cut -f 2 -d ' ')")" - latest_tag="$(get_latest_version)" - latest_version="$(parse_version "${latest_tag}")" - path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")" - - # If we can't get the current version for some reason assume `0` - current_version="${current_version:-0}" - - # If we can't get the latest version for some reason assume `0` - latest_version="${latest_version:-0}" - - info "Current Version: ${current_version}" - info "Latest Version: ${latest_version}" - - if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then - info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed" - elif [ -n "${NETDATA_TARBALL_CHECKSUM}" ] && grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then - info "Newest version is already installed" - else + if update_available; then + download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" >&3 2>&3 download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.tar.gz" - if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then - fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour." + if [ -n "${NETDATA_TARBALL_CHECKSUM}" ] && grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then + info "Newest version is already installed" + else + if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then + fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour." + fi + NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)" + tar -xf netdata-latest.tar.gz >&3 2>&3 + rm netdata-latest.tar.gz >&3 2>&3 + cd "$(find . -maxdepth 1 -name "netdata-${path_version}*" | head -n 1)" || exit 1 + RUN_INSTALLER=1 fi - NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)" - tar -xf netdata-latest.tar.gz >&3 2>&3 - rm netdata-latest.tar.gz >&3 2>&3 - cd "$(find . -maxdepth 1 -name "netdata-${path_version}*" | head -n 1)" || exit 1 - RUN_INSTALLER=1 - cd "${NETDATA_LOCAL_TARBALL_OVERRIDE}" || exit 1 fi # We got the sources, run the update now @@ -434,27 +454,29 @@ if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then info "Entering ${ndtmpdir}" cd "${ndtmpdir}" || exit 1 - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" - download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.gz.run" - if ! grep netdata-latest.gz.run "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then - fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour." - fi + if update_available; then + download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" + download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.gz.run" + if ! grep netdata-latest.gz.run "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then + fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour." + fi - if [ -e /opt/netdata/etc/netdata/.install-type ] ; then - install_type="$(cat /opt/netdata/etc/netdata/.install-type)" - else - install_type="INSTALL_TYPE='legacy-static'" - fi + if [ -e /opt/netdata/etc/netdata/.install-type ] ; then + install_type="$(cat /opt/netdata/etc/netdata/.install-type)" + else + install_type="INSTALL_TYPE='legacy-static'" + fi - # Do not pass any options other than the accept, for now - # shellcheck disable=SC2086 - if sh "${ndtmpdir}/netdata-latest.gz.run" --accept -- ${REINSTALL_OPTIONS} >&3 2>&3; then - rm -rf "${ndtmpdir}" >&3 2>&3 - else - info "NOTE: did not remove: ${ndtmpdir}" - fi + # Do not pass any options other than the accept, for now + # shellcheck disable=SC2086 + if sh "${ndtmpdir}/netdata-latest.gz.run" --accept -- ${REINSTALL_OPTIONS} >&3 2>&3; then + rm -rf "${ndtmpdir}" >&3 2>&3 + else + info "NOTE: did not remove: ${ndtmpdir}" + fi - echo "${install_type}" > /opt/netdata/etc/netdata/.install-type + echo "${install_type}" > /opt/netdata/etc/netdata/.install-type + fi if [ -e "${PREVDIR}" ]; then info "Switching back to ${PREVDIR}" |