summaryrefslogtreecommitdiffstats
path: root/packaging/installer/netdata-updater.sh
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/installer/netdata-updater.sh')
-rwxr-xr-xpackaging/installer/netdata-updater.sh68
1 files changed, 57 insertions, 11 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh
index 83031f3aa..6609edd5a 100755
--- a/packaging/installer/netdata-updater.sh
+++ b/packaging/installer/netdata-updater.sh
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
#shellcheck disable=SC2164
-
-# this script will uninstall netdata
-
+#
+# Netdata updater utility
+#
# Variables needed by script:
# - PATH
# - CFLAGS
@@ -11,6 +11,12 @@
# - NETDATA_TARBALL_URL
# - NETDATA_TARBALL_CHECKSUM_URL
# - NETDATA_TARBALL_CHECKSUM
+# - NETDATA_PREFIX / NETDATA_LIB_DIR (After 1.16.1 we will only depend on lib dir)
+#
+# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
+#
+# Author: Paweł Krupa <paulfantom@gmail.com>
+# Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
info() {
echo >&3 "$(date) : INFO: " "${@}"
@@ -67,21 +73,26 @@ download() {
}
set_tarball_urls() {
+ local extension="tar.gz"
if [ ! -z "${NETDATA_LOCAL_TARBAL_OVERRIDE}" ]; then
info "Not fetching remote tarballs, local override was given"
return
fi
+ if [ "$2" == "yes" ]; then
+ extension="gz.run"
+ fi
+
if [ "$1" = "stable" ]; then
local latest
# Simple version
# latest="$(curl -sSL https://api.github.com/repos/netdata/netdata/releases/latest | grep tag_name | cut -d'"' -f4)"
latest="$(download "https://api.github.com/repos/netdata/netdata/releases/latest" /dev/stdout | grep tag_name | cut -d'"' -f4)"
- export NETDATA_TARBALL_URL="https://github.com/netdata/netdata/releases/download/$latest/netdata-$latest.tar.gz"
+ export NETDATA_TARBALL_URL="https://github.com/netdata/netdata/releases/download/$latest/netdata-$latest.${extension}"
export NETDATA_TARBALL_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/$latest/sha256sums.txt"
else
- export NETDATA_TARBALL_URL="https://storage.googleapis.com/netdata-nightlies/netdata-latest.tar.gz"
+ export NETDATA_TARBALL_URL="https://storage.googleapis.com/netdata-nightlies/netdata-latest.${extension}"
export NETDATA_TARBALL_CHECKSUM_URL="https://storage.googleapis.com/netdata-nightlies/sha256sums.txt"
fi
}
@@ -131,10 +142,12 @@ update() {
info "Re-installing netdata..."
eval "${REINSTALL_COMMAND} --dont-wait ${do_not_start}" >&3 2>&3 || fatal "FAILED TO COMPILE/INSTALL NETDATA"
+
+ # We no longer store checksum info here. but leave this so that we clean up all environment files upon next update.
sed -i '/NETDATA_TARBALL/d' "${ENVIRONMENT_FILE}"
- cat <<EOF >>"${ENVIRONMENT_FILE}"
-NETDATA_TARBALL_CHECKSUM="$NEW_CHECKSUM"
-EOF
+
+ info "Updating tarball checksum info"
+ echo "${NEW_CHECKSUM}" > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
fi
rm -rf "${tmpdir}" >&3 2>&3
@@ -148,6 +161,12 @@ EOF
# shellcheck source=/dev/null
source "${ENVIRONMENT_FILE}" || exit 1
+# We dont expect to find lib dir variable on older installations, so load this path if none found
+export NETDATA_LIB_DIR="${NETDATA_LIB_DIR:-${NETDATA_PREFIX}/var/lib/netdata}"
+
+# Source the tarbal checksum, if not already available from environment (for existing installations with the old logic)
+[[ -z "${NETDATA_TARBALL_CHECKSUM}" ]] && [[ -f ${NETDATA_LIB_DIR}/netdata.tarball.checksum ]] && NETDATA_TARBALL_CHECKSUM="$(cat "${NETDATA_LIB_DIR}/netdata.tarball.checksum")"
+
if [ "${INSTALL_UID}" != "$(id -u)" ]; then
fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)"
fi
@@ -165,7 +184,34 @@ else
exec 3>"${logfile}"
fi
-set_tarball_urls "${RELEASE_CHANNEL}"
+set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
+
+if [ "${IS_NETDATA_STATIC_BINARY}" == "yes" ]; then
+ TMPDIR="$(create_tmp_directory)"
+ PREVDIR="$(pwd)"
+
+ echo >&2 "Entering ${TMPDIR}"
+ cd "${TMPDIR}"
+
+ download "${NETDATA_TARBALL_CHECKSUM_URL}" "${TMPDIR}/sha256sum.txt"
+ download "${NETDATA_TARBALL_URL}" "${TMPDIR}/netdata-latest.gz.run"
+ if ! grep netdata-latest.gz.run "${TMPDIR}/sha256sum.txt" | safe_sha256sum -c - >/dev/null 2>&1; then
+ fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${TMPDIR}"
+ fi
+
+ # Do not pass any options other than the accept, for now
+ sh "${TMPDIR}/netdata-latest.gz.run" --accept
+
+ #shellcheck disable=SC2181
+ if [ $? -eq 0 ]; then
+ rm -r "${TMPDIR}"
+ else
+ echo >&2 "NOTE: did not remove: ${TMPDIR}"
+ fi
+ echo >&2 "Switching back to ${PREVDIR}"
+ cd "${PREVDIR}"
+else
+ # the installer updates this script - so we run and exit in a single line
+ update && exit 0
+fi
-# the installer updates this script - so we run and exit in a single line
-update && exit 0