summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2022-01-10 10:48:25 -0500
committerGitHub <noreply@github.com>2022-01-10 10:48:25 -0500
commita46e36aef9397ded995090928042ad16229e5e9b (patch)
treed3d96d419c772b94382cd7ccdc51d39733ad644b
parent99c19e3a45c527973c1e1fa56fc55da29f792faf (diff)
Add support to updater for updating native DEB/RPM installs with our official packages. (#11753)
* Restructure update type detection. * Add proper handling for binary package installs. * Add proper support for per-arch static installs. * Address review feedback. * Improved error messages for unsupported install types. * Fixed install type detection for static builds. * Improve handling around custom installs.
-rwxr-xr-xpackaging/installer/netdata-updater.sh265
1 files changed, 219 insertions, 46 deletions
diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh
index a115a9e2c8..5775f9c8ca 100755
--- a/packaging/installer/netdata-updater.sh
+++ b/packaging/installer/netdata-updater.sh
@@ -40,6 +40,12 @@ fi
PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
+if [ ! -t 1 ]; then
+ INTERACTIVE=0
+else
+ INTERACTIVE=1
+fi
+
info() {
echo >&3 "$(date) : INFO: " "${@}"
}
@@ -62,12 +68,16 @@ if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; th
if [ -r "${envpath}" ]; then
ENVIRONMENT_FILE="${envpath}"
else
- error "Cannot find environment file, unable to update."
- exit 1
+ fatal "Cannot find environment file, unable to update."
fi
fi
fi
+str_in_list() {
+ printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
+ return $?
+}
+
safe_sha256sum() {
# Within the context of the installer, we only use -c option that is common between the two commands
# We will have to reconsider if we start non-common options
@@ -310,7 +320,7 @@ set_tarball_urls() {
fi
}
-update() {
+update_build() {
[ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
RUN_INSTALLER=0
@@ -384,6 +394,175 @@ update() {
return 0
}
+update_static() {
+ ndtmpdir="$(create_tmp_directory)"
+ PREVDIR="$(pwd)"
+
+ info "Entering ${ndtmpdir}"
+ cd "${ndtmpdir}" || exit 1
+
+ if update_available; then
+ sysarch="$(uname -m)"
+ download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt"
+ download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-${sysarch}-latest.gz.run"
+ if ! grep netdata-latest.gz.run "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
+ fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour."
+ fi
+
+ if [ -e /opt/netdata/etc/netdata/.install-type ] ; then
+ install_type="$(cat /opt/netdata/etc/netdata/.install-type)"
+ else
+ install_type="INSTALL_TYPE='legacy-static'"
+ fi
+
+ # Do not pass any options other than the accept, for now
+ # shellcheck disable=SC2086
+ if sh "${ndtmpdir}/netdata-${sysarch}-latest.gz.run" --accept -- ${REINSTALL_OPTIONS}; then
+ rm -r "${ndtmpdir}"
+ else
+ info "NOTE: did not remove: ${ndtmpdir}"
+ fi
+
+ echo "${install_type}" > /opt/netdata/etc/netdata/.install-type
+ fi
+
+ if [ -e "${PREVDIR}" ]; then
+ info "Switching back to ${PREVDIR}"
+ cd "${PREVDIR}"
+ fi
+ [ -n "${logfile}" ] && rm "${logfile}" && logfile=
+ exit 0
+}
+
+update_binpkg() {
+ os_release_file=
+ if [ -s "/etc/os-release" ] && [ -r "/etc/os-release" ]; then
+ os_release_file="/etc/os-release"
+ elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
+ os_release_file="/usr/lib/os-release"
+ else
+ fatal "Cannot find an os-release file ..." F0401
+ fi
+
+ # shellcheck disable=SC1090
+ . "${os_release_file}"
+
+ DISTRO="${ID}"
+
+ supported_compat_names="debian ubuntu centos fedora opensuse"
+
+ if str_in_list "${DISTRO}" "${supported_compat_names}"; then
+ DISTRO_COMPAT_NAME="${DISTRO}"
+ else
+ case "${DISTRO}" in
+ opensuse-leap)
+ DISTRO_COMPAT_NAME="opensuse"
+ ;;
+ rhel)
+ DISTRO_COMPAT_NAME="centos"
+ ;;
+ *)
+ DISTRO_COMPAT_NAME="unknown"
+ ;;
+ esac
+ fi
+
+ if [ "${INTERACTIVE}" = "0" ]; then
+ interactive_opts="-y"
+ env="DEBIAN_FRONTEND=noninteractive"
+ else
+ interactive_opts=""
+ env=""
+ fi
+
+ case "${DISTRO_COMPAT_NAME}" in
+ debian)
+ pm_cmd="apt-get"
+ repo_subcmd="update"
+ upgrade_cmd="upgrade"
+ pkg_install_opts="${interactive_opts}"
+ repo_update_opts="${interactive_opts}"
+ pkg_installed_check="dpkg -l"
+ INSTALL_TYPE="binpkg-deb"
+ ;;
+ ubuntu)
+ pm_cmd="apt-get"
+ repo_subcmd="update"
+ upgrade_cmd="upgrade"
+ pkg_install_opts="${interactive_opts}"
+ repo_update_opts="${interactive_opts}"
+ pkg_installed_check="dpkg -l"
+ INSTALL_TYPE="binpkg-deb"
+ ;;
+ centos)
+ if command -v dnf > /dev/null; then
+ pm_cmd="dnf"
+ repo_subcmd="makecache"
+ else
+ pm_cmd="yum"
+ fi
+ upgrade_cmd="upgrade"
+ pkg_install_opts="${interactive_opts}"
+ repo_update_opts="${interactive_opts}"
+ pkg_installed_check="rpm -q"
+ INSTALL_TYPE="binpkg-rpm"
+ ;;
+ fedora)
+ if command -v dnf > /dev/null; then
+ pm_cmd="dnf"
+ repo_subcmd="makecache"
+ else
+ pm_cmd="yum"
+ fi
+ upgrade_cmd="upgrade"
+ pkg_install_opts="${interactive_opts}"
+ repo_update_opts="${interactive_opts}"
+ pkg_installed_check="rpm -q"
+ INSTALL_TYPE="binpkg-rpm"
+ ;;
+ opensuse)
+ pm_cmd="zypper"
+ repo_subcmd="--gpg-auto-import-keys refresh"
+ upgrade_cmd="upgrade"
+ pkg_install_opts="${interactive_opts} --allow-unsigned-rpm"
+ repo_update_opts=""
+ pkg_installed_check="rpm -q"
+ INSTALL_TYPE="binpkg-rpm"
+ ;;
+ *)
+ warning "We do not provide native packages for ${DISTRO}."
+ return 2
+ ;;
+ esac
+
+ if [ -n "${repo_subcmd}" ]; then
+ # shellcheck disable=SC2086
+ env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} || fatal "Failed to update repository metadata."
+ fi
+
+ for repopkg in netdata-repo netdata-repo-edge; do
+ if ${pkg_installed_check} ${repopkg} > /dev/null 2>&1; then
+ # shellcheck disable=SC2086
+ env ${env} ${pm_cmd} ${upgrade_cmd} ${pkg_install_opts} ${repopkg} || fatal "Failed to update Netdata repository config."
+ # shellcheck disable=SC2086
+ env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} || fatal "Failed to update repository metadata."
+ fi
+ done
+
+ # shellcheck disable=SC2086
+ env ${env} ${pm_cmd} ${upgrade_cmd} ${pkg_install_opts} netdata || fatal "Failed to update Netdata package."
+}
+
+# Simple function to encapsulate original updater behavior.
+update_legacy() {
+ set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
+ if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
+ update_static && exit 0
+ else
+ update_build && exit 0
+ fi
+}
+
logfile=
ndtmpdir=
@@ -419,6 +598,11 @@ fi
# shellcheck source=/dev/null
. "${ENVIRONMENT_FILE}" || exit 1
+if [ -f "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
+ # shellcheck source=/dev/null
+ . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || exit 1
+fi
+
# 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}"
@@ -446,46 +630,35 @@ fi
self_update
-set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
-
-if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
- ndtmpdir="$(create_tmp_directory)"
- PREVDIR="$(pwd)"
-
- info "Entering ${ndtmpdir}"
- cd "${ndtmpdir}" || exit 1
-
- if update_available; then
- download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt"
- download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.gz.run"
- if ! grep netdata-latest.gz.run "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
- fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour."
- fi
-
- if [ -e /opt/netdata/etc/netdata/.install-type ] ; then
- install_type="$(cat /opt/netdata/etc/netdata/.install-type)"
- else
- install_type="INSTALL_TYPE='legacy-static'"
- fi
-
- # Do not pass any options other than the accept, for now
- # shellcheck disable=SC2086
- if sh "${ndtmpdir}/netdata-latest.gz.run" --accept -- ${REINSTALL_OPTIONS} >&3 2>&3; then
- rm -rf "${ndtmpdir}" >&3 2>&3
- else
- info "NOTE: did not remove: ${ndtmpdir}"
- fi
-
- echo "${install_type}" > /opt/netdata/etc/netdata/.install-type
- fi
-
- if [ -e "${PREVDIR}" ]; then
- info "Switching back to ${PREVDIR}"
- cd "${PREVDIR}"
- fi
- [ -n "${logfile}" ] && rm "${logfile}" && logfile=
- exit 0
-else
- # the installer updates this script - so we run and exit in a single line
- update && exit 0
-fi
+# shellcheck disable=SC2153
+case "${INSTALL_TYPE}" in
+ *-build)
+ set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
+ update_build && exit 0
+ ;;
+ *-static*)
+ set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
+ update_static && exit 0
+ ;;
+ *binpkg*)
+ update_binpkg && exit 0
+ ;;
+ "") # Fallback case for no `.install-type` file. This just works like the old install type detection.
+ update_legacy
+ ;;
+ custom)
+ # At this point, we _should_ have a valid `.environment` file, but it0s best to just check.
+ # If we do, then behave like the legacy updater.
+ if [ -n "${RELEASE_CHANNEL}" ] && [ -n "${NETDATA_PREFIX}" ] && [ -n "${REINSTALL_OPTIONS}" ]; then
+ update_legacy
+ else
+ fatal "This script does not support updating custom installations."
+ fi
+ ;;
+ oci)
+ fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself."
+ ;;
+ *)
+ fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update."
+ ;;
+esac