@cryptotaxi247 / netdata-1 / commits / 2afffd0d6

Report failures to update native packages. (#21144)

* Report failures to update native packages. The current check is relatively naive and only compares the installed version of Netdata against the latest published release. Long term we should probably improve it, but for now this is good enough to clearly report the inability to update. * Only flag cases where installed version is unchanged. This avoids the most likely case of false positives (updating while we’re in the process of publishing a new version). * Address review comments. * Assorted fixes. * Use 4 digits for major version in updater checks.

Austin S. Hemmelgarn committed Nov 11, 2025 at 06:53 UTC 2afffd0d640bf66968f00673d87cebc29a2a9af3
1 file changed +56 -28
packaging/installer/netdata-updater.sh
+56 -28
@@ -22,7 +22,7 @@
22 # - TMPDIR (set to a usable temporary directory)
23 # - NETDATA_NIGHTLIES_BASEURL (set the base url for downloading the dist tarball)
24
25 -# Next unused error code: U001D
25 +# Next unused error code: U001E
26
27 set -e
28
@@ -734,7 +734,7 @@ parse_version() {
734 if [ "${r}" = "latest" ]; then
735 # If we get ‘latest’ as a version, return the largest possible
736 # version value.
737 - printf "99999999999999"
737 + printf "999999999999999"
738 return 0
739 elif echo "${r}" | grep -q '^v.*'; then
740 # shellcheck disable=SC2001
@@ -755,15 +755,19 @@ parse_version() {
755
756 rm -f "${tmpfile}"
757
758 - printf "%03d%03d%03d%05d" "${maj}" "${min}" "${patch}" "${b}"
758 + printf "%04d%03d%03d%05d" "${maj}" "${min}" "${patch}" "${b}"
759 }
760
761 -get_latest_version() {
762 - if [ "${RELEASE_CHANNEL}" = "stable" ]; then
763 - get_netdata_latest_tag "${NETDATA_STABLE_BASE_URL}"
764 - else
765 - get_netdata_latest_tag "${NETDATA_NIGHTLY_BASE_URL}"
761 +get_latest_tag() {
762 + if [ -z "${_latest_tag}" ]; then
763 + if [ "${RELEASE_CHANNEL}" = "stable" ]; then
764 + _latest_tag="$(get_netdata_latest_tag "${NETDATA_STABLE_BASE_URL}")"
765 + else
766 + _latest_tag="$(get_netdata_latest_tag "${NETDATA_NIGHTLY_BASE_URL}")"
767 + fi
768 fi
769 +
770 + echo "${_latest_tag}"
771 }
772
773 validate_environment_file() {
@@ -774,45 +778,49 @@ validate_environment_file() {
778 fi
779 }
780
777 -update_available() {
778 - if [ "$NETDATA_FORCE_UPDATE" = "1" ]; then
779 - info "Force update requested"
780 - return 0
781 - fi
782 -
781 +get_current_version() {
782 basepath="$(dirname "$(dirname "$(dirname "${NETDATA_LIB_DIR}")")")"
783 searchpath="${basepath}/bin:${basepath}/sbin:${basepath}/usr/bin:${basepath}/usr/sbin:${PATH}"
784 searchpath="${basepath}/netdata/bin:${basepath}/netdata/sbin:${basepath}/netdata/usr/bin:${basepath}/netdata/usr/sbin:${searchpath}"
785 ndbinary="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
786
787 if [ -z "${ndbinary}" ]; then
789 - current_version=0
788 + _current_version=0
789 else
791 - current_version="$(parse_version "$(${ndbinary} -v | cut -f 2 -d ' ')")"
790 + _current_version="$(parse_version "$(${ndbinary} -v | cut -f 2 -d ' ')")"
791 fi
792
794 - latest_tag="$(get_latest_version)"
795 - latest_version="$(parse_version "${latest_tag}")"
796 - path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")"
793 + echo "${_current_version:-0}"
794 +}
795
798 - # If we can't get the current version for some reason assume `0`
799 - current_version="${current_version:-0}"
796 +get_latest_version() {
797 + parse_version "$(get_latest_tag)"
798 +}
799
801 - # If we can't get the latest version for some reason assume `0`
802 - latest_version="${latest_version:-0}"
800 +update_available() {
801 + if [ "$NETDATA_FORCE_UPDATE" = "1" ]; then
802 + info "Force update requested"
803 + return 0
804 + fi
805 +
806 + current_version="$(get_current_version)"
807 + latest_version="$(get_latest_version)"
808
809 info "Current Version: ${current_version}"
810 info "Latest Version: ${latest_version}"
811
807 - if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then
812 + if [ -z "${latest_version}" ] || [ -z "${current_version}" ] ; then
813 + info "Unable to compare versions for update check, assuming an update is required."
814 + return 0
815 + elif [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then
816 info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed"
817 return 1
818 else
819 info "Update available"
820
821 if [ "${current_version}" -ne 0 ] && [ "${latest_version}" -ne 0 ]; then
814 - current_major="$(${ndbinary} -v | cut -f 2 -d ' ' | cut -f 1 -d '.' | tr -d 'v')"
815 - latest_major="$(echo "${latest_tag}" | cut -f 1 -d '.' | tr -d 'v')"
822 + current_major="$(echo "${current_version}" | head -c 4)"
823 + latest_major="$(echo "${latest_version}" | head -c 4)"
824
825 if [ "${current_major}" -ne "${latest_major}" ]; then
826 update_safe=0
@@ -887,7 +895,7 @@ update_build() {
895 tar -xf netdata-latest.tar.gz >&3 2>&3
896 rm netdata-latest.tar.gz >&3 2>&3
897 if [ -z "$path_version" ]; then
890 - latest_tag="$(get_latest_version)"
898 + latest_tag="$(get_latest_tag)"
899 path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")"
900 fi
901 cd "$(find . -maxdepth 1 -type d -name "netdata-${path_version}*" | head -n 1)" || fatal "Failed to switch to build directory" U0017
@@ -1003,7 +1011,8 @@ update_static() {
1011 cd "${PREVDIR}"
1012 fi
1013 [ -n "${logfile}" ] && rm "${logfile}" && logfile=
1006 - exit 0
1014 +
1015 + return 0
1016 }
1017
1018 get_new_binpkg_major() {
@@ -1115,6 +1124,8 @@ update_binpkg() {
1124 ;;
1125 esac
1126
1127 + initial_version="$(get_current_version)"
1128 +
1129 if [ -n "${repo_subcmd}" ]; then
1130 # shellcheck disable=SC2086
1131 env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} >&3 2>&3 || fatal "Failed to update repository metadata." U000C
@@ -1165,6 +1176,23 @@ update_binpkg() {
1176 fi
1177 fi
1178
1179 + current_version="$(get_current_version)"
1180 + latest_version="$(get_latest_version)"
1181 +
1182 + if [ "${current_version}" -ne 0 ] && [ "${latest_version}" -ne 0 ]; then
1183 + if [ "${current_version}" -lt "${latest_version}" ] && [ "${initial_version}" -eq "${current_version}" ]; then
1184 + error ""
1185 + error "NETDATA WAS NOT UPDATED!"
1186 + error ""
1187 + error "A newer version of Netdata is available, but the system package manager does not appear to have updated to that version."
1188 + error ""
1189 + error "Most likely, your system is not up to date, and you have it configured in a way that prevents updating one or more of Netdata's dependencies."
1190 + error "Please try updating your system manually and then re-running the Netdata updater before reporting an issue with the update process."
1191 + error ""
1192 + fatal "Package manager did not fully update Netdata despite not reporting a failure." U001D
1193 + fi
1194 + fi
1195 +
1196 [ -n "${logfile}" ] && rm "${logfile}" && logfile=
1197 return 0
1198 }