diff options
author | James Mills <prologic@shortcircuit.net.au> | 2020-02-05 15:38:49 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-05 15:38:49 +1000 |
commit | 8a0ca04ac9901f21c5a5d1889df6312bff0e34da (patch) | |
tree | 33ed2c7ecd42a7b07465eedc7157a988460b3deb /packaging/installer/netdata-updater.sh | |
parent | 742f4c9840eee5ede44f31dcff0b36c06241c19a (diff) |
Adds support for only performing updates if there is a newer version (#7939)
* Re-formatted ./packaging/installer/netdata-updater.sh with shfmt -w -i 2 -ci -sr
* Fixed errors/warnings founds with shellcheck for ./packaging/installer/netdata-updater.sh
* Fixed logic for removing TMPDIR
* Fixed logic for removing TMPDIR proper
* Fixed another shellcheck warning that ReviewDog found
* Added support for only performing updates if there is a newer version
* Fixed exit 1 on bad cd
* Fixed expansion of pids in kill
* Trigger CI
Diffstat (limited to 'packaging/installer/netdata-updater.sh')
-rwxr-xr-x | packaging/installer/netdata-updater.sh | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 1469fdb728..fc85039dd1 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -73,14 +73,45 @@ download() { fi } -set_tarball_urls() { - local extension="tar.gz" +function parse_version() { + r="${1}" + if echo "${r}" | grep -q '^v.*'; then + # shellcheck disable=SC2001 + # XXX: Need a regex group subsitutation here. + r="$(echo "${r}" | sed -e 's/^v\(.*\)/\1/')" + fi - if [ -n "${NETDATA_LOCAL_TARBAL_OVERRIDE}" ]; then - info "Not fetching remote tarballs, local override was given" - return + read -r -a p <<< "$(echo "${r}" | tr '-' ' ')" + + v="${p[0]}" + b="${p[1]}" + _="${p[2]}" # ignore the SHA + + if [[ ! "${b}" =~ ^[0-9]+$ ]]; then + b="0" fi + read -r -a pp <<< "$(echo "${v}" | tr '.' ' ')" + printf "%03d%03d%03d%03d" "${pp[0]}" "${pp[1]}" "${pp[2]}" "${b}" +} + +get_latest_version() { + shasums="${1}" + + tarball="$(grep -o 'netdata-v.*\.tar\.gz' "${shasums}")" + if [ -n "${tarball}" ]; then + # shellcheck disable=SC2001 + # XXX: Need to use regex group substitution here. + version="$(echo "${tarball}" | sed -e 's/^netdata-\(.*\)\.tar.gz/\1/')" + parse_version "${version}" + else + echo "000000000000" + fi +} + +set_tarball_urls() { + local extension="tar.gz" + if [ "$2" == "yes" ]; then extension="gz.run" fi @@ -105,23 +136,27 @@ update() { tmpdir=$(create_tmp_directory) cd "$tmpdir" || exit 1 - if [ -z "${NETDATA_LOCAL_TARBAL_OVERRIDE}" ]; then - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt" >&3 2>&3 - if [[ -n "${NETDATA_TARBALL_CHECKSUM}" ]] && grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then - info "Newest version is already installed" - else - download "${NETDATA_TARBALL_URL}" "${tmpdir}/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 ${tmpdir}" - 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 netdata-* || exit 1 - RUN_INSTALLER=1 - fi + download "${NETDATA_TARBALL_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt" >&3 2>&3 + + current_version="$(command -v netdata > /dev/null && parse_version "$(netdata -v | cut -f 2 -d ' ')")" + latest_version="$(get_latest_version "${tmpdir}/sha256sum.txt")" + + info "Current Version: ${current_version}" + info "Latest Version: ${latest_version}" + + if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${current_version}" ]; then + info "Newest version ${current_version} <= ${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 - info "!!Local tarball override detected!! - Entering directory ${NETDATA_LOCAL_TARBAL_OVERRIDE} for installation, not downloading anything" + download "${NETDATA_TARBALL_URL}" "${tmpdir}/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 ${tmpdir}" + 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 netdata-* || exit 1 RUN_INSTALLER=1 cd "${NETDATA_LOCAL_TARBAL_OVERRIDE}" || exit 1 fi |