install go.d.plugin only if there is new version (#7946)
* netdata-installer.sh: do not install go.d.plugin if there is no a new version
Ilya Mashchenko committed
Feb 4, 2020 at 10:09 UTC
278f2db20e76dc6a3bf496c4fc33c462da5c37eb
1 file changed
+118
-55
netdata-installer.sh
+118
-55
@@ -802,7 +802,71 @@ fi
802
803
# -----------------------------------------------------------------------------
804
805
+# govercomp compares go.d.plugin versions. Exit codes:
806
+# 0 - version1 == version2
807
+# 1 - version1 > version2
808
+# 2 - version2 > version1
809
+# 3 - error
810
+govercomp() {
811
+ # version in file:
812
+ # - v0.14.0
813
+ #
814
+ # 'go.d.plugin -v' output variants:
815
+ # - go.d.plugin, version: unknown
816
+ # - go.d.plugin, version: v0.14.1
817
+ # - go.d.plugin, version: v0.14.1-dirty
818
+ # - go.d.plugin, version: v0.14.1-1-g4c5f98c
819
+ # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
820
+
821
+ # we need to compare only MAJOR.MINOR.PATCH part
822
+ local ver1 ver2
823
+ ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
824
+ ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
825
+
826
+ local IFS=.
827
+ read -ra ver1 <<<"$ver1"
828
+ read -ra ver2 <<<"$ver2"
829
+
830
+ if [ ${#ver1[@]} -eq 0 ] || [ ${#ver2[@]} -eq 0 ]; then
831
+ return 3
832
+ fi
833
+
834
+ local i
835
+ for ((i = 0; i < ${#ver1[@]}; i++)); do
836
+ if [ "${ver1[i]}" -gt "${ver2[i]}" ]; then
837
+ return 1
838
+ elif [ "${ver1[i]}" -gt "${ver2[i]}" ]; then
839
+ return 2
840
+ fi
841
+ done
842
+
843
+ return 0
844
+}
845
+
846
+should_install_go() {
847
+ if [ -n "${NETDATA_DISABLE_GO+x}" ]; then
848
+ return 1
849
+ fi
850
+
851
+ local version_in_file
852
+ local binary_version
853
+
854
+ version_in_file="$(cat packaging/go.d.version 2>/dev/null)"
855
+ binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2>/dev/null)
856
+
857
+ govercomp "$version_in_file" "$binary_version"
858
+ case $? in
859
+ 0) return 1 ;; # =
860
+ 2) return 1 ;; # <
861
+ *) return 0 ;; # >, error
862
+ esac
863
+}
864
+
865
install_go() {
866
+ if ! should_install_go; then
867
+ return 0
868
+ fi
869
+
870
# When updating this value, ensure correct checksums in packaging/go.d.checksums
871
GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
872
ARCH_MAP=(
@@ -816,73 +880,72 @@ install_go() {
880
'armv5tel::arm'
881
)
882
819
- if [ -z "${NETDATA_DISABLE_GO+x}" ]; then
820
- progress "Install go.d.plugin"
821
- ARCH=$(uname -m)
822
- OS=$(uname -s | tr '[:upper:]' '[:lower:]')
823
-
824
- for index in "${ARCH_MAP[@]}"; do
825
- KEY="${index%%::*}"
826
- VALUE="${index##*::}"
827
- if [ "$KEY" = "$ARCH" ]; then
828
- ARCH="${VALUE}"
829
- break
830
- fi
831
- done
832
- tmp=$(mktemp -d /tmp/netdata-go-XXXXXX)
833
- GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
834
-
835
- if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
836
- download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
837
- else
838
- progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
839
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
840
- fi
883
+ progress "Install go.d.plugin"
884
+ ARCH=$(uname -m)
885
+ OS=$(uname -s | tr '[:upper:]' '[:lower:]')
886
842
- if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
843
- download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
844
- else
845
- progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
846
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
887
+ for index in "${ARCH_MAP[@]}"; do
888
+ KEY="${index%%::*}"
889
+ VALUE="${index##*::}"
890
+ if [ "$KEY" = "$ARCH" ]; then
891
+ ARCH="${VALUE}"
892
+ break
893
fi
894
+ done
895
+ tmp=$(mktemp -d /tmp/netdata-go-XXXXXX)
896
+ GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
897
849
- if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
850
- run_failed "go.d plugin download failed, go.d plugin will not be available"
851
- echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
852
- echo >&2
853
- return 0
854
- fi
898
+ if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
899
+ download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
900
+ else
901
+ progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
902
+ run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
903
+ fi
904
+
905
+ if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
906
+ download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
907
+ else
908
+ progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
909
+ run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
910
+ fi
911
856
- grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
857
- grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
912
+ if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
913
+ run_failed "go.d plugin download failed, go.d plugin will not be available"
914
+ echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
915
+ echo >&2
916
+ return 0
917
+ fi
918
859
- # Checksum validation
860
- if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
919
+ grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" >"${tmp}/sha256sums.txt" 2>/dev/null
920
+ grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >>"${tmp}/sha256sums.txt" 2>/dev/null
921
862
- echo >&2 "go.d plugin checksum validation failure."
863
- echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
864
- echo >&2
922
+ # Checksum validation
923
+ if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
924
866
- run_failed "go.d.plugin package files checksum validation failed."
867
- return 0
868
- fi
925
+ echo >&2 "go.d plugin checksum validation failure."
926
+ echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
927
+ echo >&2
928
870
- # Install new files
871
- run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
872
- run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
873
- run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
874
- run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
929
+ run_failed "go.d.plugin package files checksum validation failed."
930
+ return 0
931
+ fi
932
876
- run tar xf "${tmp}/${GO_PACKAGE_BASENAME}"
877
- run mv "${GO_PACKAGE_BASENAME/\.tar\.gz/}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
878
- if [ "${UID}" -eq 0 ]; then
879
- run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
880
- fi
881
- run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
882
- rm -rf "${tmp}"
933
+ # Install new files
934
+ run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
935
+ run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
936
+ run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
937
+ run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
938
+
939
+ run tar xf "${tmp}/${GO_PACKAGE_BASENAME}"
940
+ run mv "${GO_PACKAGE_BASENAME/\.tar\.gz/}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
941
+ if [ "${UID}" -eq 0 ]; then
942
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
943
fi
944
+ run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
945
+ rm -rf "${tmp}"
946
return 0
947
}
948
+
949
install_go
950
951
# -----------------------------------------------------------------------------