summaryrefslogtreecommitdiffstats
path: root/netdata-installer.sh
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2020-02-04 10:09:57 +0300
committerGitHub <noreply@github.com>2020-02-04 10:09:57 +0300
commit278f2db20e76dc6a3bf496c4fc33c462da5c37eb (patch)
tree7cc021684f608316735980f8a27ca76fcc2550b5 /netdata-installer.sh
parent98eeb1ae7fc6beaac26bf0d5a5520242e6ebec10 (diff)
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
Diffstat (limited to 'netdata-installer.sh')
-rwxr-xr-xnetdata-installer.sh173
1 files changed, 118 insertions, 55 deletions
diff --git a/netdata-installer.sh b/netdata-installer.sh
index 49b5433598..a2549c20e9 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -802,7 +802,71 @@ fi
# -----------------------------------------------------------------------------
+# govercomp compares go.d.plugin versions. Exit codes:
+# 0 - version1 == version2
+# 1 - version1 > version2
+# 2 - version2 > version1
+# 3 - error
+govercomp() {
+ # version in file:
+ # - v0.14.0
+ #
+ # 'go.d.plugin -v' output variants:
+ # - go.d.plugin, version: unknown
+ # - go.d.plugin, version: v0.14.1
+ # - go.d.plugin, version: v0.14.1-dirty
+ # - go.d.plugin, version: v0.14.1-1-g4c5f98c
+ # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
+
+ # we need to compare only MAJOR.MINOR.PATCH part
+ local ver1 ver2
+ ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
+ ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
+
+ local IFS=.
+ read -ra ver1 <<<"$ver1"
+ read -ra ver2 <<<"$ver2"
+
+ if [ ${#ver1[@]} -eq 0 ] || [ ${#ver2[@]} -eq 0 ]; then
+ return 3
+ fi
+
+ local i
+ for ((i = 0; i < ${#ver1[@]}; i++)); do
+ if [ "${ver1[i]}" -gt "${ver2[i]}" ]; then
+ return 1
+ elif [ "${ver1[i]}" -gt "${ver2[i]}" ]; then
+ return 2
+ fi
+ done
+
+ return 0
+}
+
+should_install_go() {
+ if [ -n "${NETDATA_DISABLE_GO+x}" ]; then
+ return 1
+ fi
+
+ local version_in_file
+ local binary_version
+
+ version_in_file="$(cat packaging/go.d.version 2>/dev/null)"
+ binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2>/dev/null)
+
+ govercomp "$version_in_file" "$binary_version"
+ case $? in
+ 0) return 1 ;; # =
+ 2) return 1 ;; # <
+ *) return 0 ;; # >, error
+ esac
+}
+
install_go() {
+ if ! should_install_go; then
+ return 0
+ fi
+
# When updating this value, ensure correct checksums in packaging/go.d.checksums
GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
ARCH_MAP=(
@@ -816,73 +880,72 @@ install_go() {
'armv5tel::arm'
)
- if [ -z "${NETDATA_DISABLE_GO+x}" ]; then
- progress "Install go.d.plugin"
- ARCH=$(uname -m)
- OS=$(uname -s | tr '[:upper:]' '[:lower:]')
-
- for index in "${ARCH_MAP[@]}"; do
- KEY="${index%%::*}"
- VALUE="${index##*::}"
- if [ "$KEY" = "$ARCH" ]; then
- ARCH="${VALUE}"
- break
- fi
- done
- tmp=$(mktemp -d /tmp/netdata-go-XXXXXX)
- GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
-
- if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
- download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
- else
- progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
- fi
+ progress "Install go.d.plugin"
+ ARCH=$(uname -m)
+ OS=$(uname -s | tr '[:upper:]' '[:lower:]')
- if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
- download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
- else
- progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
+ for index in "${ARCH_MAP[@]}"; do
+ KEY="${index%%::*}"
+ VALUE="${index##*::}"
+ if [ "$KEY" = "$ARCH" ]; then
+ ARCH="${VALUE}"
+ break
fi
+ done
+ tmp=$(mktemp -d /tmp/netdata-go-XXXXXX)
+ GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
- if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
- run_failed "go.d plugin download failed, go.d plugin will not be available"
- echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
- echo >&2
- return 0
- fi
+ if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
+ download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
+ else
+ progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
+ run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
+ fi
+
+ if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
+ download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
+ else
+ progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
+ run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
+ fi
- grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
- grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
+ if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
+ run_failed "go.d plugin download failed, go.d plugin will not be available"
+ echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
+ echo >&2
+ return 0
+ fi
- # Checksum validation
- if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
+ grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" >"${tmp}/sha256sums.txt" 2>/dev/null
+ grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >>"${tmp}/sha256sums.txt" 2>/dev/null
- echo >&2 "go.d plugin checksum validation failure."
- echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
- echo >&2
+ # Checksum validation
+ if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
- run_failed "go.d.plugin package files checksum validation failed."
- return 0
- fi
+ echo >&2 "go.d plugin checksum validation failure."
+ echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
+ echo >&2
- # Install new files
- run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
- run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
- run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
- run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
+ run_failed "go.d.plugin package files checksum validation failed."
+ return 0
+ fi
- run tar xf "${tmp}/${GO_PACKAGE_BASENAME}"
- run mv "${GO_PACKAGE_BASENAME/\.tar\.gz/}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
- if [ "${UID}" -eq 0 ]; then
- run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
- fi
- run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
- rm -rf "${tmp}"
+ # Install new files
+ run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
+ run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
+ run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
+ run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
+
+ run tar xf "${tmp}/${GO_PACKAGE_BASENAME}"
+ run mv "${GO_PACKAGE_BASENAME/\.tar\.gz/}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
+ if [ "${UID}" -eq 0 ]; then
+ run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
fi
+ run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
+ rm -rf "${tmp}"
return 0
}
+
install_go
# -----------------------------------------------------------------------------