From 112b5b91647c3dea45cc1c9bc364df526c8012f1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 26 Jan 2022 19:05:15 +0100 Subject: Merging upstream version 1.33.0. Signed-off-by: Daniel Baumann --- packaging/installer/README.md | 53 +- packaging/installer/REINSTALL.md | 36 +- packaging/installer/UPDATE.md | 69 +- packaging/installer/functions.sh | 6 +- packaging/installer/install-required-packages.sh | 6 +- packaging/installer/kickstart-ng.sh | 1363 +------------------- packaging/installer/kickstart-static64.sh | 440 +------ packaging/installer/kickstart.sh | 1495 ++++++++++++++++------ packaging/installer/methods/alpine.md | 40 - packaging/installer/methods/cloud-providers.md | 6 +- packaging/installer/methods/kickstart-64.md | 116 -- packaging/installer/methods/kickstart.md | 124 +- packaging/installer/methods/macos.md | 16 +- packaging/installer/methods/manual.md | 17 +- packaging/installer/methods/packages.md | 46 - packaging/installer/methods/source.md | 1 + packaging/installer/netdata-updater.sh | 350 +++-- 17 files changed, 1536 insertions(+), 2648 deletions(-) mode change 100644 => 120000 packaging/installer/kickstart-ng.sh mode change 100755 => 120000 packaging/installer/kickstart-static64.sh delete mode 100644 packaging/installer/methods/alpine.md delete mode 100644 packaging/installer/methods/kickstart-64.md delete mode 100644 packaging/installer/methods/packages.md (limited to 'packaging/installer') diff --git a/packaging/installer/README.md b/packaging/installer/README.md index 7bdb6a757..b9d754206 100644 --- a/packaging/installer/README.md +++ b/packaging/installer/README.md @@ -11,9 +11,7 @@ Netdata is a monitoring agent designed to run on all your systems: physical and IoT/edge devices. Netdata runs on Linux, FreeBSD, macOS, Kubernetes, Docker, and all their derivatives. The best way to install Netdata is with our [**automatic one-line installation -script**](#automatic-one-line-installation-script), which works with all Linux distributions and macOS environments, or our [**.deb/rpm -packages**](/packaging/installer/methods/packages.md), which seamlessly install with your distribution's package -manager. +script**](#automatic-one-line-installation-script), which works with all Linux distributions and most macOS environments. If you want to install Netdata with Docker, on a Kubernetes cluster, or a different operating system, see [Have a different operating system, or want to try another @@ -36,24 +34,24 @@ _actively_ contributing to Netdata's future. This method is fully automatic on all Linux distributions, including Ubuntu, Debian, Fedora, CentOS, and others, as well as on mac OS environments. -To install Netdata from source, including all dependencies required to connect to Netdata Cloud, and get _automatic -nightly updates_, run the following as your normal user: - -**Linux** +To install Netdata, including all dependencies required to connect to Netdata Cloud, and get _automatic nightly +updates_, run the following as your normal user: ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) +wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh ``` -**macOS** +Or, if you have cURL but not wget (such as on macOS): ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) --install /usr/local/ +curl https://my-netdata.io/kickstart.sh > /tmp/netdata-kickstart.sh && sh /tmp/netdata-kickstart.sh ``` +This script will preferentially use native DEB/RPM packages if we provide them for your platform. + To see more information about this installation script, including how to disable automatic updates, get nightly vs. stable releases, or disable anonymous statistics, see the [`kickstart.sh` method -page](/packaging/installer/methods/kickstart.md). +page](/packaging/installer/methods/kickstart.md). Scroll down for details about [automatic updates](#automatic-updates) or [nightly vs. stable releases](#nightly-vs-stable-releases). @@ -71,9 +69,8 @@ external databases, and more. ## Have a different operating system, or want to try another method? -Netdata works on many different operating systems, each with a few possible installation methods. To see the full list -of approved methods for each operating system/version we support, see our [distribution -matrix](/packaging/DISTRIBUTIONS.md). +Netdata works on many different platforms. To see all supported platforms, check out our [platform support +policy](/packaging/PLATFORM_SUPPORT.md). Below, you can find a few additional installation methods, followed by separate instructions for a variety of unique operating systems. @@ -87,27 +84,19 @@ operating systems. svg="linux" /> - - ) diff --git a/packaging/installer/UPDATE.md b/packaging/installer/UPDATE.md index ba57c8cc5..8230d00cd 100644 --- a/packaging/installer/UPDATE.md +++ b/packaging/installer/UPDATE.md @@ -23,76 +23,43 @@ icon in the local Agent dashboard's top navigation. This modal informs you wheth If you are not sure where your Netdata config directory is, see the [configuration doc](/docs/configure/nodes.md). In most installations, this is `/etc/netdata`. -Use `cd` to navigate to the Netdata config directory, then use `ls -a` to look for a file called `.environment`. - -- If the `.environment` file _does not_ exist, reinstall with your [package manager](#deb-or-rpm-packages). -- If the `.environment` file _does_ exist, check its contents with `less .environment`. - - If `IS_NETDATA_STATIC_BINARY` is `"yes"`, update using the [pre-built static - binary](#pre-built-static-binary-for-64-bit-systems-kickstart-static64sh). - - In all other cases, update using the [one-line installer script](#one-line-installer-script-kickstartsh). +Use `cd` to navigate to the Netdata config directory, then use `ls -a` to look for a file called `.install-type`. + +- If the `.install-type` file doex not exist, look for a file in the same directory called `.environment`. + - If the `.environment` file does not exist, you probably installed Netdata using your system package manager + and should update it the same way you would run updates on the system itself. + - If the `.environment` file does exist, then our [regular update method](#updates-for-most-systems) should + work correctly. +- If the `.install-type` file does exist, check it’s contents with `cat .install-type`. + - If the `INSTALL_TYPE` key has a value of `custom`, you probably installed Netdata using your system + package manager and should update it the same way you would run updates on the system itself. + - If the `INSTALL_TYPE` key has a value of `oci`, the install is from a Docker image. + - Otherwise, the install should work with our [regular update method](#updates-for-most-systems). Next, use the appropriate method to update the Netdata Agent: -- [One-line installer script (`kickstart.sh`)](#one-line-installer-script-kickstartsh) -- [`.deb` or `.rpm` packages](#deb-or-rpm-packages) -- [Pre-built static binary for 64-bit systems (`kickstart-static64.sh`)](#pre-built-static-binary-for-64-bit-systems-kickstart-static64sh) +- [Updates for most systems](#updates-for-most-systems) - [Docker](#docker) - [macOS](#macos) - [Manual installation from Git](#manual-installation-from-git) -## One-line installer script (`kickstart.sh`) - -If you installed Netdata using our one-line automatic installation script, run it again to update Netdata. Any custom -settings present in your Netdata configuration directory (typically at `/etc/netdata`) persists during this process. +## Updates for most systems -This script will automatically run the update script that was installed as part of the initial install (even if -you disabled automatic updates) and preserve the existing install options you specified. +In most cases, you can update netdata using our one-line installation script. This script will automatically +run the update script that was installed as part of the initial install (even if you disabled automatic updates) +and preserve the existing install options you specified. If you installed Netdata using an installation prefix, you will need to add an `--install` option specifying that prefix to this command to make sure it finds Netdata. ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) +wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh ``` > ❗ If the above command fails, you can [reinstall > Netdata](/packaging/installer/REINSTALL.md#one-line-installer-script-kickstartsh) to get the latest version. This also > preserves your [configuration](/docs/configure/nodes.md) in `netdata.conf` or other files. -## `.deb` or `.rpm` packages - -If you installed Netdata with [`.deb` or `.rpm` packages](/packaging/installer/methods/packages.md), use your -distribution's package manager to update Netdata. Any custom settings present in your Netdata configuration directory -(typically at `/etc/netdata`) persists during this process. - -Your package manager grabs a new package from our hosted repository, updates the Netdata Agent, and restarts it. - -```bash -apt-get install netdata # Ubuntu/Debian -dnf install netdata # Fedora/RHEL -yum install netdata # CentOS -zypper in netdata # openSUSE -``` - -> You may need to escalate privileges using `sudo`. - -## Pre-built static binary for 64-bit systems (`kickstart-static64.sh`) - -If you installed Netdata using the pre-built static binary, run the `kickstart-static64.sh` script again to update -Netdata. Any custom settings present in your Netdata configuration directory (typically at `/etc/netdata`) persists -during this process. - -This script will automatically run the update script that was installed as part of the initial install (even if -you disabled automatic updates) and preserve the existing install options you specified. - -```bash -bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh) -``` - -> ❗ If the above command fails, you can [reinstall -> Netdata](/packaging/installer/REINSTALL.md#pre-built-static-binary-for-64-bit-systems-kickstart-static64sh) to get the -> latest version. This also preserves your [configuration](/docs/configure/nodes.md) in `netdata.conf` or other files. - ## Docker Docker-based installations do not update automatically. To update an Netdata Agent running in a Docker container, you diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index 6264c1131..bd9ca39b5 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -184,9 +184,9 @@ netdata_banner() { # ----------------------------------------------------------------------------- # portable service command -service_cmd="$(command -v service 2> /dev/null)" -rcservice_cmd="$(command -v rc-service 2> /dev/null)" -systemctl_cmd="$(command -v systemctl 2> /dev/null)" +service_cmd="$(command -v service 2> /dev/null || true)" +rcservice_cmd="$(command -v rc-service 2> /dev/null || true)" +systemctl_cmd="$(command -v systemctl 2> /dev/null || true)" service() { local cmd="${1}" action="${2}" diff --git a/packaging/installer/install-required-packages.sh b/packaging/installer/install-required-packages.sh index 6eeda53c0..28605a142 100755 --- a/packaging/installer/install-required-packages.sh +++ b/packaging/installer/install-required-packages.sh @@ -124,9 +124,9 @@ Supported packages (you can append many of them): - sensors install lm_sensors for monitoring h/w sensors - - firehol-all packages required for FireHOL, FireQoS, update-ipsets + - firehol-all packages required for FireHOL, FireQOS, update-ipsets - firehol packages required for FireHOL - - fireqos packages required for FireQoS + - fireqos packages required for FireQOS - update-ipsets packages required for update-ipsets - demo packages required for running a netdata demo site @@ -1613,7 +1613,7 @@ validate_tree_centos() { if [[ "${version}" =~ ^8(\..*)?$ ]]; then echo >&2 " > Checking for config-manager ..." - if ! run yum ${sudo} config-manager; then + if ! run ${sudo} yum config-manager --help; then if prompt "config-manager not found, shall I install it?"; then run ${sudo} yum ${opts} install 'dnf-command(config-manager)' fi diff --git a/packaging/installer/kickstart-ng.sh b/packaging/installer/kickstart-ng.sh deleted file mode 100644 index 8fcc6d5d3..000000000 --- a/packaging/installer/kickstart-ng.sh +++ /dev/null @@ -1,1362 +0,0 @@ -#!/bin/sh -# -# SPDX-License-Identifier: GPL-3.0-or-later - -# ====================================================================== -# Constants - -KICKSTART_OPTIONS="${*}" -PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh" -PATH="${PATH}:/usr/local/bin:/usr/local/sbin" -REPOCONFIG_URL_PREFIX="https://packagecloud.io/netdata/netdata-repoconfig/packages" -REPOCONFIG_VERSION="1-1" -TELEMETRY_URL="https://posthog.netdata.cloud/capture/" -START_TIME="$(date +%s)" - -# ====================================================================== -# Defaults for environment variables - -SELECTED_INSTALL_METHOD="none" -INSTALL_TYPE="unknown" -INSTALL_PREFIX="" -NETDATA_AUTO_UPDATES="1" -NETDATA_CLAIM_ONLY=0 -NETDATA_CLAIM_URL="https://app.netdata.cloud" -NETDATA_DISABLE_CLOUD=0 -NETDATA_ONLY_BUILD=0 -NETDATA_ONLY_NATIVE=0 -NETDATA_ONLY_STATIC=0 -NETDATA_REQUIRE_CLOUD=1 -RELEASE_CHANNEL="nightly" - -NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK:-0}" -NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://storage.googleapis.com/netdata-nightlies}" -NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:-""}" -TELEMETRY_API_KEY="${NETDATA_POSTHOG_API_KEY:-mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y}" - -if [ ! -t 1 ]; then - INTERACTIVE=0 -else - INTERACTIVE=1 -fi - -# ====================================================================== -# Usage info - -usage() { - cat << HEREDOC -USAGE: kickstart.sh [options] - where options include: - - --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal) - --interactive Prompt for user input even if there is no controlling terminal. - --dont-start-it Do not start the agent by default (only for static installs or local builds) - --stable-channel Install a stable version instead of a nightly build (default: install a nightly build) - --nightly-channel Install a nightly build instead of a stable version - --no-updates Do not enable automatic updates (default: enable automatic updates) - --auto-update Enable automatic updates. - --disable-telemetry Opt-out of anonymous statistics. - --native-only Only install if native binary packages are available. - --static-only Only install if a static build is available. - --build-only Only install using a local build. - --reinstall Explicitly reinstall instead of updating any existing install. - --reinstall-even-if-unsafe Even try to reinstall if we don't think we can do so safely (implies --reinstall). - --disable-cloud Disable support for Netdata Cloud (default: detect) - --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud. - --install Specify an installation prefix for local builds (default: autodetect based on system type). - --claim-token Use a specified token for claiming to Netdata Cloud. - --claim-rooms When claiming, add the node to the specified rooms. - --claim-only If there is an existing install, only try to claim it, not update it. - --claim-* Specify other options for the claiming script. - --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer. - -Additionally, this script may use the following environment variables: - - TMPDIR: Used to specify where to put temporary files. On most systems, the default we select - automatically should be fine. The user running the script needs to both be able to - write files to the temporary directory, and run files from that location. - ROOTCMD: Used to specify a command to use to run another command with root privileges if needed. By - default we try to use sudo, doas, or pkexec (in that order of preference), but if - you need special options for one of those to work, or have a different tool to do - the same thing on your system, you can specify it here. - DO_NOT_TRACK If set to a value other than 0, behave as if \`--disable-telemetry\` was specified. - NETDATA_INSTALLER_OPTIONS: Specifies extra options to pass to the static installer or local build script. - -HEREDOC -} - -# ====================================================================== -# Telemetry functions - -telemetry_event() { - if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then - return 0 - fi - - now="$(date +%s)" - total_duration="$((now - START_TIME))" - - if [ -e "/etc/os-release" ]; then - eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/HOST_/')" - fi - - if [ -z "${HOST_NAME}" ] || [ -z "${HOST_VERSION}" ] || [ -z "${HOST_ID}" ]; then - if [ -f "/etc/lsb-release" ]; then - DISTRIB_ID="unknown" - DISTRIB_RELEASE="unknown" - DISTRIB_CODENAME="unknown" - eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" < /etc/lsb-release)" - if [ -z "${HOST_NAME}" ]; then HOST_NAME="${DISTRIB_ID}"; fi - if [ -z "${HOST_VERSION}" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi - if [ -z "${HOST_ID}" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi - fi - fi - - KERNEL_NAME="$(uname -s)" - - if [ "${KERNEL_NAME}" = FreeBSD ]; then - TOTAL_RAM="$(sysctl -n hw.physmem)" - elif [ "${KERNEL_NAME}" = Darwin ]; then - TOTAL_RAM="$(sysctl -n hw.memsize)" - elif [ -r /proc/meminfo ]; then - TOTAL_RAM="$(grep -F MemTotal /proc/meminfo | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -f 1 -d ' ')" - TOTAL_RAM="$((TOTAL_RAM * 1024))" - fi - - if [ -f /etc/machine-id ]; then - DISTINCT_ID="$(cat /etc/machine-id)" - elif command -v uuidgen > /dev/null 2>&1; then - DISTINCT_ID="$(uuidgen)" - else - DISTINCT_ID="null" - fi - - REQ_BODY="$(cat << EOF -{ - "api_key": "${TELEMETRY_API_KEY}", - "event": "${1}", - "properties": { - "distinct_id": "${DISTINCT_ID}", - "event_source": "agent installer", - "\$current_url": "agent installer", - "\$pathname": "netdata-installer", - "\$host": "installer.netdata.io", - "\$ip": "127.0.0.1", - "script_variant": "kickstart-ng", - "error_code": "${3}", - "error_message": "${2}", - "install_options": "${KICKSTART_OPTIONS}", - "total_runtime": "${total_duration}", - "selected_install_method": "${SELECTED_INSTALL_METHOD}", - "netdata_release_channel": "${RELEASE_CHANNEL:-null}", - "netdata_install_type": "${INSTALL_TYPE}", - "host_os_name": "${HOST_NAME:-unknown}", - "host_os_id": "${HOST_ID:-unknown}", - "host_os_id_like": "${HOST_ID_LIKE:-unknown}", - "host_os_version": "${HOST_VERSION:-unknown}", - "host_os_version_id": "${HOST_VERSION_ID:-unknown}", - "system_kernel_name": "${KERNEL_NAME}", - "system_kernel_version": "$(uname -r)", - "system_architecture": "$(uname -m)", - "system_total_ram": "${TOTAL_RAM:-unknown}" - } -} -EOF -)" - - if [ -n "$(command -v curl 2> /dev/null)" ]; then - curl --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null - else - wget -q -O - --no-check-certificate \ - --method POST \ - --timeout=1 \ - --header 'Content-Type: application/json' \ - --body-data "${REQ_BODY}" \ - "${TELEMETRY_URL}" > /dev/null - fi -} - -trap_handler() { - code="${1}" - lineno="${2}" - - printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})" - - telemetry_event INSTALL_CRASH "Installer exited unexpectedly (${code}-${lineno})" "E${code}-${lineno}" - - trap - EXIT - - cleanup - - exit 1 -} - -trap 'trap_handler 0 ${LINENO}' EXIT -trap 'trap_handler 1 0' HUP -trap 'trap_handler 2 0' INT -trap 'trap_handler 3 0' QUIT -trap 'trap_handler 13 0' PIPE -trap 'trap_handler 15 0' TERM - -# ====================================================================== -# Utility functions - -setup_terminal() { - TPUT_RESET="" - TPUT_WHITE="" - TPUT_BGRED="" - TPUT_BGGREEN="" - TPUT_BOLD="" - TPUT_DIM="" - - # Is stderr on the terminal? If not, then fail - test -t 2 || return 1 - - if command -v tput > /dev/null 2>&1; then - if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then - # Enable colors - TPUT_RESET="$(tput sgr 0)" - TPUT_WHITE="$(tput setaf 7)" - TPUT_BGRED="$(tput setab 1)" - TPUT_BGGREEN="$(tput setab 2)" - TPUT_BOLD="$(tput bold)" - TPUT_DIM="$(tput dim)" - fi - fi - - echo "${TPUT_RESET}" - - return 0 -} - -cleanup() { - if [ -z "${NO_CLEANUP}" ]; then - ${ROOTCMD} rm -rf "${tmpdir}" - fi -} - -fatal() { - printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*}" - telemetry_event "INSTALL_FAILED" "${1}" "${2}" - cleanup - trap - EXIT - exit 1 -} - -run_ok() { - printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}" -} - -run_failed() { - printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}" -} - -ESCAPED_PRINT_METHOD= -# shellcheck disable=SC3050 -if printf "%q " test > /dev/null 2>&1; then - ESCAPED_PRINT_METHOD="printfq" -fi - -escaped_print() { - if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then - # shellcheck disable=SC3050 - printf "%q " "${@}" - else - printf "%s" "${*}" - fi - return 0 -} - -progress() { - echo >&2 " --- ${TPUT_BOLD}${*}${TPUT_RESET} --- " -} - -run_logfile="/dev/null" -run() { - user="${USER--}" - dir="${PWD}" - - if [ "$(id -u)" = "0" ]; then - info="[root ${dir}]# " - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# " - else - info="[${user} ${dir}]$ " - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ " - fi - - { - printf "%s" "${info}" - escaped_print "${@}" - printf " ... " - } >> "${run_logfile}" - - printf >&2 "%s" "${info_console}${TPUT_BOLD}" - escaped_print >&2 "${@}" - printf >&2 "%s\n" "${TPUT_RESET}" - - "${@}" - - ret=$? - if [ ${ret} -ne 0 ]; then - run_failed - printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}" - else - run_ok - printf "OK\n" >> "${run_logfile}" - fi - - return ${ret} -} - -warning() { - printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}" -} - -_cannot_use_tmpdir() { - testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)" - ret=0 - - if [ -z "${testfile}" ]; then - return "${ret}" - fi - - if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then - if chmod +x "${testfile}"; then - if [ "$("${testfile}")" = "SUCCESS" ]; then - ret=1 - fi - fi - fi - - rm -f "${testfile}" - return "${ret}" -} - -create_tmp_directory() { - if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then - if _cannot_use_tmpdir /tmp; then - if _cannot_use_tmpdir "${PWD}"; then - fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." F0400 - else - TMPDIR="${PWD}" - fi - else - TMPDIR="/tmp" - fi - fi - - mktemp -d -t netdata-kickstart-XXXXXXXXXX -} - -download() { - url="${1}" - dest="${2}" - if command -v curl > /dev/null 2>&1; then - run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1 - elif command -v wget > /dev/null 2>&1; then - run wget -T 15 -O "${dest}" "${url}" || return 1 - else - fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003 - fi -} - -get_redirect() { - url="${1}" - - if command -v curl > /dev/null 2>&1; then - run sh -c "curl ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$'" || return 1 - elif command -v wget > /dev/null 2>&1; then - run sh -c "wget --max-redirect=0 ${url} 2>&1 | grep Location | cut -d ' ' -f2 | grep -o '[^/]*$'" || return 1 - else - fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003 - fi -} - -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 using non-common options - if command -v sha256sum > /dev/null 2>&1; then - sha256sum "$@" - elif command -v shasum > /dev/null 2>&1; then - shasum -a 256 "$@" - else - fatal "I could not find a suitable checksum binary to use" F0004 - fi -} - -get_system_info() { - case "$(uname -s)" in - Linux) - SYSTYPE="Linux" - - 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}" - SYSVERSION="${VERSION_ID}" - SYSCODENAME="${VERSION_CODENAME}" - SYSARCH="$(uname -m)" - - 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 - ;; - Darwin) - SYSTYPE="Darwin" - SYSVERSION="$(sw_vers -buildVersion)" - SYSARCH="$(uname -m)" - ;; - FreeBSD) - SYSTYPE="FreeBSD" - SYSVERSION="$(uname -K)" - SYSARCH="$(uname -m)" - ;; - *) - fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200 - ;; - esac -} - -str_in_list() { - printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$" - return $? -} - -confirm_root_support() { - if [ "$(id -u)" -ne "0" ]; then - if [ -z "${ROOTCMD}" ] && command -v sudo > /dev/null; then - ROOTCMD="sudo" - fi - - if [ -z "${ROOTCMD}" ] && command -v doas > /dev/null; then - ROOTCMD="doas" - fi - - if [ -z "${ROOTCMD}" ] && command -v pkexec > /dev/null; then - ROOTCMD="pkexec" - fi - - if [ -z "${ROOTCMD}" ]; then - fatal "We need root privileges to continue, but cannot find a way to gain them. Either re-run this script as root, or set \$ROOTCMD to a command that can be used to gain root privileges" F0201 - fi - fi -} - -confirm() { - prompt="${1} [y/n]" - - while true; do - echo "${prompt}" - read -r yn - - case "$yn" in - [Yy]*) return 0;; - [Nn]*) return 1;; - *) echo "Please answer yes or no.";; - esac - done -} - -# ====================================================================== -# Existing install handling code - -update() { - updater="${ndprefix}/usr/libexec/netdata/netdata-updater.sh" - - if [ -x "${updater}" ]; then - if run ${ROOTCMD} "${updater}" --not-running-from-cron; then - progress "Updated existing install at ${ndprefix}" - return 0 - else - fatal "Failed to update existing Netdata install at ${ndprefix}" F0100 - fi - else - return 1 - fi -} - -handle_existing_install() { - if pkg_installed netdata; then - ndprefix="/" - else - if [ -n "${INSTALL_PREFIX}" ]; then - searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}" - searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}" - else - searchpath="${PATH}" - fi - - ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)" - - if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ]; then - ndpath="/opt/netdata/bin/netdata" - fi - - if [ -n "${ndpath}" ]; then - ndprefix="$(dirname "$(dirname "${ndpath}")")" - fi - - if echo "${ndprefix}" | grep -Eq '/usr$'; then - ndprefix="$(dirname "${ndprefix}")" - fi - fi - - if [ -n "${ndprefix}" ]; then - typefile="${ndprefix}/etc/netdata/.install-type" - if [ -r "${typefile}" ]; then - ${ROOTCMD} sh -c "cat \"${typefile}\" > \"${tmpdir}/install-type\"" - # shellcheck disable=SC1091 - . "${tmpdir}/install-type" - else - INSTALL_TYPE="unknown" - fi - fi - - if [ -z "${ndprefix}" ]; then - progress "No existing installations of netdata found, assuming this is a fresh install." - return 0 - fi - - case "${INSTALL_TYPE}" in - kickstart-*|legacy-*|binpkg-*|manual-static|unknown) - if [ "${INSTALL_TYPE}" = "unknown" ]; then - warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type." - else - progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'." - fi - - if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then - progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing." - - case "${INSTALL_TYPE}" in - binpkg-*) NETDATA_ONLY_NATIVE=1 ;; - *-build) NETDATA_ONLY_BUILD=1 ;; - *-static) NETDATA_ONLY_STATIC=1 ;; - *) - if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then - warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed." - elif [ "${INTERACTIVE}" -eq 0 ]; then - fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104 - else - if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then - progress "OK, continuing." - else - fatal "Cancelling reinstallation at user request." F0105 - fi - fi - ;; - esac - - return 0 - fi - - ret=0 - - if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then - if ! update; then - warning "Unable to find usable updater script, not updating existing install at ${ndprefix}." - fi - else - warning "Not updating existing install at ${ndprefix}." - fi - - if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then - progress "Attempting to claim existing install at ${ndprefix}." - INSTALL_PREFIX="${ndprefix}" - claim - ret=$? - elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then - fatal "User asked to claim, but did not proide a claiming token." F0202 - else - progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)." - fi - - cleanup - trap - EXIT - exit $ret - ;; - oci) - fatal "This is an OCI container, use the regular image lifecycle management commands in your container instead of this script for managing it." F0203 - ;; - *) - if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then - if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then - warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed." - elif [ "${INTERACTIVE}" -eq 0 ]; then - fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104 - else - if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then - progress "OK, continuing." - else - fatal "Cancelling reinstallation at user request." F0105 - fi - fi - else - fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103 - fi - ;; - esac -} - -soft_disable_cloud() { - cloud_prefix="${INSTALL_PREFIX}/var/lib/netdata/cloud.d" - - run ${ROOTCMD} mkdir -p "${cloud_prefix}" - - cat > "${tmpdir}/cloud.conf" << EOF -[global] - enabled = no -EOF - - run ${ROOTCMD} cp "${tmpdir}/cloud.conf" "${cloud_prefix}/cloud.conf" - - if [ -z "${NETDATA_NO_START}" ]; then - case "${SYSTYPE}" in - Darwin) run ${ROOTCMD} launchctl kickstart -k com.github.netdata ;; - FreeBSD) run ${ROOTCMD} service netdata restart ;; - Linux) - initpath="$(${ROOTCMD} readlink /proc/1/exe)" - - if command -v service > /dev/null 2>&1; then - run ${ROOTCMD} service netdata restart - elif command -v rc-service > /dev/null 2>&1; then - run ${ROOTCMD} rc-service netdata restart - elif [ "$(basename "${initpath}" 2> /dev/null)" = "systemd" ]; then - run ${ROOTCMD} systemctl restart netdata - elif [ -f /etc/init.d/netdata ]; then - run ${ROOTCMD} /etc/init.d/netdata restart - fi - ;; - esac - fi -} - -confirm_install_prefix() { - if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then - fatal "The \`--install\` option is only supported together with the \`--only-build\` option." F0204 - fi - - if [ -n "${INSTALL_PREFIX}" ]; then - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install ${INSTALL_PREFIX}" - else - case "${SYSTYPE}" in - Darwin) - INSTALL_PREFIX="/usr/local/netdata" - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}" - ;; - FreeBSD) - INSTALL_PREFIX="/usr/local" - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}" - ;; - esac - fi -} - -# ====================================================================== -# Claiming support code - -check_claim_opts() { -# shellcheck disable=SC2235,SC2030 - if [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then - fatal "Invalid claiming options, claim rooms may only be specified when a token and URL are specified." F0204 - elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_EXTRA}" ]; then - fatal "Invalid claiming options, a claiming token must be specified." F0204 - elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ] && [ -n "${NETDATA_CLAIM_TOKEN}" ]; then - fatal "Cloud explicitly disabled, but automatic claiming requested. Either enable Netdata Cloud, or remove the --claim-* options." F0204 - fi -} - -claim() { - progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}" - if [ -z "${INSTALL_PREFIX}" ]; then - NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh - elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then - NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh" - else - NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh" - fi - - if ! pgrep netdata > /dev/null; then - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running" - fi - - # shellcheck disable=SC2086 - if ${ROOTCMD} "${NETDATA_CLAIM_PATH}" -token="${NETDATA_CLAIM_TOKEN}" -rooms="${NETDATA_CLAIM_ROOMS}" -url="${NETDATA_CLAIM_URL}" ${NETDATA_CLAIM_EXTRA}; then - progress "Successfully claimed node" - else - warning "Unable to claim node, you must do so manually." - if [ -z "${NETDATA_NEW_INSTALL}" ]; then - cleanup - trap - EXIT - exit 1 - fi - fi -} - -# ====================================================================== -# Native package install code. - -# Check for an already installed package with a given name. -pkg_installed() { - case "${DISTRO_COMPAT_NAME}" in - debian|ubuntu) - dpkg -l "${1}" > /dev/null 2>&1 - return $? - ;; - centos|fedora|opensuse) - rpm -q "${1}" > /dev/null 2>&1 - return $? - ;; - *) - return 1 - ;; - esac -} - -# Check for the existence of a usable netdata package in the repo. -netdata_avail_check() { - case "${DISTRO_COMPAT_NAME}" in - debian|ubuntu) - env DEBIAN_FRONTEND=noninteractive apt-cache policy netdata | grep -q packagecloud.io/netdata/netdata; - return $? - ;; - centos|fedora) - # shellcheck disable=SC2086 - ${pm_cmd} search -v netdata | grep -qE 'Repo *: netdata(-edge)?$' - return $? - ;; - opensuse) - zypper packages -r "$(zypper repos | grep -E 'netdata |netdata-edge ' | cut -f 1 -d '|' | tr -d ' ')" | grep -E 'netdata ' - return $? - ;; - *) - return 1 - ;; - esac -} - -# Check for any distro-specific dependencies we know we need. -check_special_native_deps() { - if [ "${DISTRO_COMPAT_NAME}" = "centos" ] && [ "${SYSVERSION}" = "7" ]; then - progress "Checking for libuv availability." - # shellcheck disable=SC2086 - if ${pm_cmd} search ${interactive_opts} -v libuv | grep -q "No matches found"; then - progress "libv not found, checking for EPEL availability." - # shellcheck disable=SC2086 - if ${pm_cmd} search ${interactive_opts} -v epel-release | grep -q "No matches found"; then - warning "Unable to find a suitable source for libuv, cannot install on this system." - return 1 - else - progress "EPEL is available, attempting to install so that required dependencies are available." - - # shellcheck disable=SC2086 - if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} epel-release; then - warning "Failed to install EPEL." - return 1 - fi - fi - else - return 0 - fi - fi -} - -try_package_install() { - if [ -z "${DISTRO}" ]; then - warning "Unable to determine Linux distribution for native packages." - return 1 - fi - - progress "Attempting to install using native packages..." - - if [ "${RELEASE_CHANNEL}" = "nightly" ]; then - release="-edge" - else - release="" - fi - - if [ "${INTERACTIVE}" = "0" ]; then - interactive_opts="-y" - env="DEBIAN_FRONTEND=noninteractive" - else - interactive_opts="" - env="" - fi - - case "${DISTRO_COMPAT_NAME}" in - debian) - needs_early_refresh=1 - pm_cmd="apt-get" - repo_subcmd="update" - repo_prefix="debian/${SYSCODENAME}" - pkg_type="deb" - pkg_suffix="_all" - pkg_vsep="_" - pkg_install_opts="${interactive_opts}" - repo_update_opts="${interactive_opts}" - uninstall_subcmd="uninstall" - INSTALL_TYPE="binpkg-deb" - ;; - ubuntu) - needs_early_refresh=1 - pm_cmd="apt-get" - repo_subcmd="update" - repo_prefix="ubuntu/${SYSCODENAME}" - pkg_type="deb" - pkg_suffix="_all" - pkg_vsep="_" - pkg_install_opts="${interactive_opts}" - repo_update_opts="${interactive_opts}" - uninstall_subcmd="uninstall" - INSTALL_TYPE="binpkg-deb" - ;; - centos) - if command -v dnf > /dev/null; then - pm_cmd="dnf" - repo_subcmd="makecache" - else - pm_cmd="yum" - fi - repo_prefix="el/${SYSVERSION}" - pkg_type="rpm" - pkg_suffix=".noarch" - pkg_vsep="-" - pkg_install_opts="${interactive_opts}" - repo_update_opts="${interactive_opts}" - uninstall_subcmd="remove" - INSTALL_TYPE="binpkg-rpm" - ;; - fedora) - if command -v dnf > /dev/null; then - pm_cmd="dnf" - repo_subcmd="makecache" - else - pm_cmd="yum" - fi - repo_prefix="fedora/${SYSVERSION}" - pkg_type="rpm" - pkg_suffix=".noarch" - pkg_vsep="-" - pkg_install_opts="${interactive_opts}" - repo_update_opts="${interactive_opts}" - uninstall_subcmd="remove" - INSTALL_TYPE="binpkg-rpm" - ;; - opensuse) - pm_cmd="zypper" - repo_subcmd="--gpg-auto-import-keys refresh" - repo_prefix="opensuse/${SYSVERSION}" - pkg_type="rpm" - pkg_suffix=".noarch" - pkg_vsep="-" - pkg_install_opts="${interactive_opts} --allow-unsigned-rpm" - repo_update_opts="" - uninstall_subcmd="remove" - INSTALL_TYPE="binpkg-rpm" - ;; - *) - warning "We do not provide native packages for ${DISTRO}." - return 2 - ;; - esac - - repoconfig_name="netdata-repo${release}" - repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_VERSION}${pkg_suffix}.${pkg_type}" - repoconfig_url="${REPOCONFIG_URL_PREFIX}/${repo_prefix}/${repoconfig_file}/download.${pkg_type}" - - if ! pkg_installed "${repoconfig_name}"; then - progress "Downloading repository configuration package." - if ! download "${repoconfig_url}" "${tmpdir}/${repoconfig_file}"; then - warning "Failed to download repository configuration package." - return 2 - fi - - if [ -n "${needs_early_refresh}" ]; then - progress "Updating repository metadata." - # shellcheck disable=SC2086 - if ! run ${ROOTCMD} env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then - warning "Failed to refresh repository metadata." - return 2 - fi - fi - - progress "Installing repository configuration package." - # shellcheck disable=SC2086 - if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} "${tmpdir}/${repoconfig_file}"; then - warning "Failed to install repository configuration package." - return 2 - fi - - if [ -n "${repo_subcmd}" ]; then - progress "Updating repository metadata." - # shellcheck disable=SC2086 - if ! run ${ROOTCMD} env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then - fatal "Failed to update repository metadata." F0205 - fi - fi - else - progress "Repository configuration is already present, attempting to install netdata." - fi - - if ! check_special_native_deps; then - warning "Could not find secondary dependencies ${DISTRO} on ${SYSARCH}." - if [ -z "${NO_CLEANUP}" ]; then - progress "Attempting to uninstall repository configuration package." - # shellcheck disable=SC2086 - run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}" - fi - return 2 - fi - - progress "Checking for usable Netdata package." - if ! netdata_avail_check "${DISTRO_COMPAT_NAME}"; then - warning "Could not find a usable native package for ${DISTRO} on ${SYSARCH}." - if [ -z "${NO_CLEANUP}" ]; then - progress "Attempting to uninstall repository configuration package." - # shellcheck disable=SC2086 - run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}" - fi - return 2 - fi - - if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then - run ${ROOTCMD} mkdir -p "/etc/netdata" - run ${ROOTCMD} touch "/etc/netdata/.opt-out-from-anonymous-statistics" - fi - - progress "Installing Netdata package." - # shellcheck disable=SC2086 - if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} netdata; then - warning "Failed to install Netdata package." - if [ -z "${NO_CLEANUP}" ]; then - progress "Attempting to uninstall repository configuration package." - # shellcheck disable=SC2086 - run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}" - fi - return 2 - fi -} - -# ====================================================================== -# Static build install code - -set_static_archive_urls() { - if [ "${RELEASE_CHANNEL}" = "stable" ]; then - latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")" - export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${SYSARCH}-${latest}.gz.run" - export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt" - else - export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-latest.gz.run" - export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt" - fi -} - -try_static_install() { - set_static_archive_urls "${RELEASE_CHANNEL}" - progress "Downloading static netdata binary: ${NETDATA_STATIC_ARCHIVE_URL}" - - if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "${tmpdir}/netdata-${SYSARCH}-latest.gz.run"; then - warning "Unable to download static build archive for ${SYSARCH}." - return 2 - fi - - if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"; then - fatal "Unable to fetch checksums to verify static build archive." F0206 - fi - - if ! grep "netdata-${SYSARCH}-latest.gz.run" "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then - fatal "Static binary checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0207 - fi - - if [ "${INTERACTIVE}" -eq 0 ]; then - opts="${opts} --accept" - fi - - progress "Installing netdata" - # shellcheck disable=SC2086 - if ! run ${ROOTCMD} sh "${tmpdir}/netdata-${SYSARCH}-latest.gz.run" ${opts} -- ${NETDATA_AUTO_UPDATES:+--auto-update} ${NETDATA_INSTALLER_OPTIONS}; then - warning "Failed to install static build of Netdata on ${SYSARCH}." - run rm -rf /opt/netdata - return 2 - fi - - install_type_file="/opt/netdata/etc/netdata/.install-type" - if [ -f "${install_type_file}" ]; then - ${ROOTCMD} sh -c "cat \"${install_type_file}\" > \"${tmpdir}/install-type\"" - ${ROOTCMD} chown "$(id -u)":"$(id -g)" "${tmpdir}/install-type" - # shellcheck disable=SC1091 - . "${tmpdir}/install-type" - cat > "${tmpdir}/install-type" <<- EOF - INSTALL_TYPE='kickstart-static' - PREBUILT_ARCH='${PREBUILT_ARCH}' - EOF - ${ROOTCMD} chown netdata:netdata "${tmpdir}/install-type" - ${ROOTCMD} cp "${tmpdir}/install-type" "${install_type_file}" - fi -} - -# ====================================================================== -# Local build install code - -set_source_archive_urls() { - if [ "$1" = "stable" ]; then - latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")" - export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${latest}.tar.gz" - export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt" - else - export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-latest.tar.gz" - export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt" - fi -} - -install_local_build_dependencies() { - bash="$(command -v bash 2> /dev/null)" - - if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then - warning "Unable to find a usable version of \`bash\` (required for local build)." - return 1 - fi - - progress "Fetching script to detect required packages..." - download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh" - - if [ ! -s "${tmpdir}/install-required-packages.sh" ]; then - warning "Downloaded dependency installation script is empty." - else - progress "Running downloaded script to detect required packages..." - - if [ "${INTERACTIVE}" -eq 0 ]; then - opts="--dont-wait --non-interactive" - fi - - if [ "${SYSTYPE}" = "Darwin" ]; then - sudo="" - else - sudo="${ROOTCMD}" - fi - - # shellcheck disable=SC2086 - if ! run ${sudo} "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then - warning "It failed to install all the required packages, but installation might still be possible." - fi - fi -} - -build_and_install() { - progress "Building netdata" - - echo "INSTALL_TYPE='kickstart-build'" > system/.install-type - - opts="${NETDATA_INSTALLER_OPTIONS}" - - if [ "${INTERACTIVE}" -eq 0 ]; then - opts="${opts} --dont-wait" - fi - - if [ "${NETDATA_AUTO_UPDATES}" -eq 1 ]; then - opts="${opts} --auto-update" - fi - - if [ "${RELEASE_CHANNEL}" = "stable" ]; then - opts="${opts} --stable-channel" - fi - - if [ "${NETDATA_REQUIRE_CLOUD}" -eq 1 ]; then - opts="${opts} --require-cloud" - elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then - opts="${opts} --disable-cloud" - fi - - # shellcheck disable=SC2086 - run ${ROOTCMD} ./netdata-installer.sh ${opts} - - case $? in - 1) - fatal "netdata-installer.sh exited with error" F0007 - ;; - 2) - fatal "Insufficient RAM to install netdata" F0008 - ;; - esac -} - -try_build_install() { - if ! install_local_build_dependencies; then - return 1 - fi - - set_source_archive_urls "${RELEASE_CHANNEL}" - - download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt" - download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-latest.tar.gz" - - if ! grep netdata-latest.tar.gz "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then - fatal "Tarball checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0005 - fi - - run tar -xf "${tmpdir}/netdata-latest.tar.gz" -C "${tmpdir}" - rm -rf "${tmpdir}/netdata-latest.tar.gz" > /dev/null 2>&1 - cd "$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name netdata-)" || fatal "Cannot cd to netdata source tree" F0006 - - if [ -x netdata-installer.sh ]; then - build_and_install || return 1 - else - # This case is needed because some platforms produce an extra directory on the source tarball extraction. - if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then - cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && build_and_install || return 1 - else - fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${tmpdir}" F0009 - fi - fi -} - -# ====================================================================== -# Per system-type install logic - -install_on_linux() { - if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then - SELECTED_INSTALL_METHOD="native" - try_package_install - - case "$?" in - 0) - NETDATA_INSTALL_SUCCESSFUL=1 - ;; - 1) - fatal "Unable to install on this system." F0300 - ;; - 2) - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then - fatal "Could not install native binary packages." F0301 - else - warning "Could not install native binary packages, falling back to alternative installation method." - fi - ;; - esac - fi - - if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then - SELECTED_INSTALL_METHOD="static" - INSTALL_TYPE="kickstart-static" - try_static_install - - case "$?" in - 0) - NETDATA_INSTALL_SUCCESSFUL=1 - INSTALL_PREFIX="/opt/netdata" - ;; - 1) - fatal "Unable to install on this system." F0302 - ;; - 2) - if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then - fatal "Could not install static build." F0303 - else - warning "Could not install static build, falling back to alternative installation method." - fi - ;; - esac - fi - - if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then - SELECTED_INSTALL_METHOD="build" - INSTALL_TYPE="kickstart-build" - try_build_install - - case "$?" in - 0) - NETDATA_INSTALL_SUCCESSFUL=1 - ;; - *) - fatal "Unable to install on this system." F0304 - ;; - esac - fi -} - -install_on_macos() { - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then - fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option." F0305 - elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then - fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option." F0306 - else - SELECTED_INSTALL_METHOD="build" - INSTALL_TYPE="kickstart-build" - try_build_install - - case "$?" in - 0) - NETDATA_INSTALL_SUCCESSFUL=1 - ;; - *) - fatal "Unable to install on this system." F0307 - ;; - esac - fi -} - -install_on_freebsd() { - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then - fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option." F0308 - elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then - fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option." F0309 - else - SELECTED_INSTALL_METHOD="build" - INSTALL_TYPE="kickstart-build" - try_build_install - - case "$?" in - 0) - NETDATA_INSTALL_SUCCESSFUL=1 - ;; - *) - fatal "Unable to install on this system." F030A - ;; - esac - fi -} - -# ====================================================================== -# Main program - -setup_terminal || echo > /dev/null - -while [ -n "${1}" ]; do - case "${1}" in - "--help") - usage - cleanup - trap - EXIT - exit 0 - ;; - "--no-cleanup") NO_CLEANUP=1 ;; - "--dont-wait"|"--non-interactive") INTERACTIVE=0 ;; - "--interactive") INTERACTIVE=1 ;; - "--stable-channel") RELEASE_CHANNEL="stable" ;; - "--no-updates") NETDATA_AUTO_UPDATES=0 ;; - "--auto-update") NETDATA_AUTO_UPDATES="1" ;; - "--reinstall") NETDATA_REINSTALL=1 ;; - "--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;; - "--claim-only") NETDATA_CLAIM_ONLY=1 ;; - "--disable-cloud") - NETDATA_DISABLE_CLOUD=1 - NETDATA_REQUIRE_CLOUD=0 - ;; - "--require-cloud") - NETDATA_DISABLE_CLOUD=0 - NETDATA_REQUIRE_CLOUD=1 - ;; - "--dont-start-it") - NETDATA_NO_START=1 - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it" - ;; - "--disable-telemetry") - NETDATA_DISABLE_TELEMETRY="1" - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry" - ;; - "--install") - INSTALL_PREFIX="${2}" - shift 1 - ;; - "--native-only") - NETDATA_ONLY_NATIVE=1 - NETDATA_ONLY_STATIC=0 - NETDATA_ONLY_BUILD=0 - SELECTED_INSTALL_METHOD="native" - ;; - "--static-only") - NETDATA_ONLY_STATIC=1 - NETDATA_ONLY_NATIVE=0 - NETDATA_ONLY_BUILD=0 - SELECTED_INSTALL_METHOD="static" - ;; - "--build-only") - NETDATA_ONLY_BUILD=1 - NETDATA_ONLY_NATIVE=0 - NETDATA_ONLY_STATIC=0 - SELECTED_INSTALL_METHOD="build" - ;; - "--claim-token") - NETDATA_CLAIM_TOKEN="${2}" - shift 1 - ;; - "--claim-rooms") - NETDATA_CLAIM_ROOMS="${2}" - shift 1 - ;; - "--claim-url") - NETDATA_CLAIM_URL="${2}" - shift 1 - ;; - "--claim-*") - optname="$(echo "${1}" | cut -d '-' -f 4-)" - case "${optname}" in - id|proxy|user|hostname) - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname} ${2}" - shift 1 - ;; - verbose|insecure|noproxy|noreload|daemon-not-running) - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}" - ;; - *) - warning "Ignoring unrecognized claiming option ${optname}" - ;; - esac - ;; - *) - warning "Passing unrecognized option '${1}' to installer script. If this is intended, please add it to \$NETDATA_INSTALLER_OPTIONS instead." - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}" - ;; - esac - shift 1 -done - -check_claim_opts -confirm_root_support -get_system_info -confirm_install_prefix - -tmpdir="$(create_tmp_directory)" -progress "Using ${tmpdir} as a temporary directory." -cd "${tmpdir}" || exit 1 - -handle_existing_install - -case "${SYSTYPE}" in - Linux) install_on_linux ;; - Darwin) install_on_macos ;; - FreeBSD) install_on_freebsd ;; -esac - -if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then - claim -elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then - soft_disable_cloud -fi - -telemetry_event INSTALL_SUCCESS "" "" -cleanup -trap - EXIT diff --git a/packaging/installer/kickstart-ng.sh b/packaging/installer/kickstart-ng.sh new file mode 120000 index 000000000..71d605e7c --- /dev/null +++ b/packaging/installer/kickstart-ng.sh @@ -0,0 +1 @@ +kickstart.sh \ No newline at end of file diff --git a/packaging/installer/kickstart-static64.sh b/packaging/installer/kickstart-static64.sh deleted file mode 100755 index ec1800a61..000000000 --- a/packaging/installer/kickstart-static64.sh +++ /dev/null @@ -1,439 +0,0 @@ -#!/usr/bin/env sh - -# SPDX-License-Identifier: GPL-3.0-or-later -# shellcheck disable=SC1117,SC2039,SC2059,SC2086 -# -# Options to run -# --dont-wait do not wait for input -# --non-interactive do not wait for input -# --dont-start-it do not start netdata after install -# --stable-channel Use the stable release channel, rather than the nightly to fetch sources -# --disable-telemetry Opt-out of anonymous telemetry program (DO_NOT_TRACK=1) -# --local-files Use a manually provided tarball for the installation -# --allow-duplicate-install do not bail if we detect a duplicate install -# --reinstall if an existing install would be updated, reinstall instead -# --claim-token specify a token to use for claiming the newly installed instance -# --claim-url specify a URL to use for claiming the newly installed isntance -# --claim-rooms specify a list of rooms to claim the newly installed instance to -# --claim-proxy specify a proxy to use while claiming the newly installed instance -# -# Environment options: -# -# NETDATA_TARBALL_BASEURL set the base url for downloading the dist tarball -# -# ---------------------------------------------------------------------------- -# library functions copied from packaging/installer/functions.sh - -setup_terminal() { - TPUT_RESET="" - TPUT_YELLOW="" - TPUT_WHITE="" - TPUT_BGRED="" - TPUT_BGGREEN="" - TPUT_BOLD="" - TPUT_DIM="" - - # Is stderr on the terminal? If not, then fail - test -t 2 || return 1 - - if command -v tput > /dev/null 2>&1; then - if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then - # Enable colors - TPUT_RESET="$(tput sgr 0)" - TPUT_YELLOW="$(tput setaf 3)" - TPUT_WHITE="$(tput setaf 7)" - TPUT_BGRED="$(tput setab 1)" - TPUT_BGGREEN="$(tput setab 2)" - TPUT_BOLD="$(tput bold)" - TPUT_DIM="$(tput dim)" - fi - fi - - return 0 -} -setup_terminal || echo > /dev/null - -# ---------------------------------------------------------------------------- -fatal() { - printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n" - exit 1 -} - -run_ok() { - printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} \n\n" -} - -run_failed() { - printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} \n\n" -} - -ESCAPED_PRINT_METHOD= -if printf "%q " test > /dev/null 2>&1; then - ESCAPED_PRINT_METHOD="printfq" -fi -escaped_print() { - if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then - printf "%q " "${@}" - else - printf "%s" "${*}" - fi - return 0 -} - -progress() { - echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- " -} - -run_logfile="/dev/null" -run() { - local user="${USER--}" dir="${PWD}" info info_console - - if [ "${UID}" = "0" ]; then - info="[root ${dir}]# " - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# " - else - info="[${user} ${dir}]$ " - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ " - fi - - { - printf "${info}" - escaped_print "${@}" - printf " ... " - } >> "${run_logfile}" - - printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" - escaped_print >&2 "${@}" - printf >&2 "${TPUT_RESET}\n" - - "${@}" - - local ret=$? - if [ ${ret} -ne 0 ]; then - run_failed - printf >> "${run_logfile}" "FAILED with exit code ${ret}\n" - else - run_ok - printf >> "${run_logfile}" "OK\n" - fi - - return ${ret} -} - -fatal() { - printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n" - exit 1 -} - -_cannot_use_tmpdir() { - local testfile ret - testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)" - ret=0 - - if [ -z "${testfile}" ] ; then - return "${ret}" - fi - - if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}" ; then - if chmod +x "${testfile}" ; then - if [ "$("${testfile}")" = "SUCCESS" ] ; then - ret=1 - fi - fi - fi - - rm -f "${testfile}" - return "${ret}" -} - -create_tmp_directory() { - if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then - if _cannot_use_tmpdir /tmp ; then - if _cannot_use_tmpdir "${PWD}" ; then - echo >&2 - echo >&2 "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." - exit 1 - else - TMPDIR="${PWD}" - fi - else - TMPDIR="/tmp" - fi - fi - - mktemp -d -t netdata-kickstart-XXXXXXXXXX -} - -download() { - url="${1}" - dest="${2}" - if command -v curl > /dev/null 2>&1; then - run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" - elif command -v wget > /dev/null 2>&1; then - run wget -T 15 -O "${dest}" "${url}" || fatal "Cannot download ${url}" - else - fatal "I need curl or wget to proceed, but neither is available on this system." - fi -} - -set_tarball_urls() { - if [ -n "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ]; then - progress "Not fetching remote tarballs, local override was given" - return - fi - - if [ "$1" = "stable" ]; then - local latest - # Simple version - 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.gz.run" - export NETDATA_TARBALL_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/$latest/sha256sums.txt" - else - export NETDATA_TARBALL_URL="$NETDATA_TARBALL_BASEURL/netdata-latest.gz.run" - export NETDATA_TARBALL_CHECKSUM_URL="$NETDATA_TARBALL_BASEURL/sha256sums.txt" - fi -} - -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 using non-common options - if command -v sha256sum > /dev/null 2>&1; then - sha256sum "$@" - elif command -v shasum > /dev/null 2>&1; then - shasum -a 256 "$@" - else - fatal "I could not find a suitable checksum binary to use" - fi -} - -mark_install_type() { - install_type_file="/opt/netdata/etc/netdata/.install-type" - if [ -f "${install_type_file}" ]; then - # shellcheck disable=SC1090 - . "${install_type_file}" - cat > "${TMPDIR}/install-type" <<- EOF - INSTALL_TYPE='kickstart-static' - PREBUILT_ARCH='${PREBUILT_ARCH}' - EOF - ${sudo} chown netdata:netdata "${TMPDIR}/install-type" - ${sudo} cp "${TMPDIR}/install-type" "${install_type_file}" - fi -} - -claim() { - progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}" - NETDATA_CLAIM_PATH=/opt/netdata/bin/netdata-claim.sh - - if ${sudo} "${NETDATA_CLAIM_PATH}" -token=${NETDATA_CLAIM_TOKEN} -rooms=${NETDATA_CLAIM_ROOMS} -url=${NETDATA_CLAIM_URL} ${NETDATA_CLAIM_EXTRA}; then - progress "Successfully claimed node" - return 0 - else - run_failed "Unable to claim node, you must do so manually." - return 1 - fi -} - -# ---------------------------------------------------------------------------- -umask 022 - -sudo="" -[ -z "${UID}" ] && UID="$(id -u)" -[ "${UID}" -ne "0" ] && sudo="sudo" - -# ---------------------------------------------------------------------------- -if [ "$(uname -m)" != "x86_64" ]; then - fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)." -fi - -if [ "$(uname -s)" != "Linux" ]; then - fatal "Static binary versions of netdata are available only for Linux, but this system is $(uname -s)" -fi - -# ---------------------------------------------------------------------------- -opts= -NETDATA_INSTALLER_OPTIONS="" -NETDATA_UPDATES="--auto-update" -RELEASE_CHANNEL="nightly" -while [ -n "${1}" ]; do - case "${1}" in - "--dont-wait") opts="${opts} --accept" ;; - "--non-interactive") opts="${opts} --accept" ;; - "--accept") opts="${opts} --accept" ;; - "--dont-start-it") - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}" - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running" - ;; - "--no-updates") NETDATA_UPDATES="" ;; - "--stable-channel") - RELEASE_CHANNEL="stable" - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}" - ;; - "--disable-telemetry") NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }${1}";; - "--local-files") - NETDATA_UPDATES="" # Disable autoupdates if using pre-downloaded files. - if [ -z "${2}" ]; then - fatal "Option --local-files requires extra information. The desired tarball full filename is needed" - fi - - NETDATA_LOCAL_TARBALL_OVERRIDE="${2}" - - if [ -z "${3}" ]; then - fatal "Option --local-files requires a pair of the tarball source and the checksum file" - fi - - NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${3}" - shift 2 - ;; - "--allow-duplicate-install") NETDATA_ALLOW_DUPLICATE_INSTALL=1 ;; - "--reinstall") NETDATA_REINSTALL=1 ;; - "--claim-token") - NETDATA_CLAIM_TOKEN="${2}" - shift 1 - ;; - "--claim-rooms") - NETDATA_CLAIM_ROOMS="${2}" - shift 1 - ;; - "--claim-url") - NETDATA_CLAIM_URL="${2}" - shift 1 - ;; - "--claim-proxy") - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -proxy ${2}" - shift 1 - ;; - *) - echo >&2 "Unknown option '${1}' or invalid number of arguments. Please check the README for the available arguments of ${0} and try again" - exit 1 - esac - shift 1 -done - -if [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] || [ -n "$DO_NOT_TRACK" ]; then - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:+${NETDATA_INSTALLER_OPTIONS} }--disable-telemetry" -fi - -if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then - if [ -n "${NETDATA_CLAIM_TOKEN}" ] || [ -n "${NETDATA_CLAIM_ROOMS}" ] || [ -n "${NETDATA_CLAIM_URL}" ]; then - run_failed "Cloud explicitly disabled but automatic claiming requested." - run_failed "Either enable Netdata Cloud, or remove the --claim-* options." - exit 1 - fi -fi - -# shellcheck disable=SC2235,SC2030 -if ( [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_URL}" ] ) || ( [ -n "${NETDATA_CLAIM_TOKEN}" ] && [ -z "${NETDATA_CLAIM_URL}" ] ); then - run_failed "Invalid claiming options, both a claiming token and URL must be specified." - exit 1 -elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then - run_failed "Invalid claiming options, claim rooms may only be specified when a token and URL are specified." - exit 1 -fi - -# Netdata Tarball Base URL (defaults to our Google Storage Bucket) -[ -z "$NETDATA_TARBALL_BASEURL" ] && NETDATA_TARBALL_BASEURL=https://storage.googleapis.com/netdata-nightlies - -# --------------------------------------------------------------------------------------------------------------------- -# look for an existing install and try to update that instead if it exists - -ndpath="$(command -v netdata 2>/dev/null)" -if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then - ndpath="/opt/netdata/bin/netdata" -fi - -if [ -n "$ndpath" ] ; then - ndprefix="$(dirname "$(dirname "${ndpath}")")" - - if [ "${ndprefix}" = /usr ] ; then - ndprefix="/" - fi - - progress "Found existing install of Netdata under: ${ndprefix}" - - if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then - ndstatic="$(grep IS_NETDATA_STATIC_BINARY "${ndprefix}/etc/netdata/.environment" | cut -d "=" -f 2 | tr -d \")" - if [ -z "${NETDATA_REINSTALL}" ] && [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ] ; then - if [ -n "${NETDATA_CLAIM_TOKEN}" ] ; then - claim - exit $? - elif [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then - progress "Attempting to update existing install instead of creating a new one" - if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then - progress "Updated existing install at ${ndpath}" - exit 0 - else - fatal "Failed to update existing Netdata install" - exit 1 - fi - else - if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] || [ "${ndstatic}" = "no" ] ; then - fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue." - exit 1 - else - progress "User explicitly requested duplicate install, proceeding." - fi - fi - else - if [ "${ndstatic}" = "yes" ] ; then - progress "User requested reinstall instead of update, proceeding." - else - fatal "Existing install is not a static install, please use kickstart.sh instead." - exit 1 - fi - fi - else - progress "Existing install appears to be handled manually or through the system package manager." - if [ -n "${NETDATA_CLAIM_TOKEN}" ] ; then - claim - exit $? - elif [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then - fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue." - exit 1 - else - progress "User explicitly requested duplicate install, proceeding." - fi - fi -fi - -# ---------------------------------------------------------------------------- -TMPDIR=$(create_tmp_directory) -cd "${TMPDIR}" || exit 1 - -if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ]; then - set_tarball_urls "${RELEASE_CHANNEL}" - progress "Downloading static netdata binary: ${NETDATA_TARBALL_URL}" - - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${TMPDIR}/sha256sum.txt" - download "${NETDATA_TARBALL_URL}" "${TMPDIR}/netdata-latest.gz.run" -else - progress "Installation sources were given as input, running installation using \"${NETDATA_LOCAL_TARBALL_OVERRIDE}\"" - run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE}" "${TMPDIR}/netdata-latest.gz.run" - run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM}" "${TMPDIR}/sha256sum.txt" -fi - -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 Agent installation and leaving binary in ${TMPDIR}\nUsually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." -fi - -# ---------------------------------------------------------------------------- -progress "Installing netdata" -run ${sudo} sh "${TMPDIR}/netdata-latest.gz.run" ${opts} -- ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS} - -mark_install_type - -#shellcheck disable=SC2181 -if [ $? -eq 0 ]; then - run ${sudo} rm "${TMPDIR}/netdata-latest.gz.run" - if [ ! "${TMPDIR}" = "/" ] && [ -d "${TMPDIR}" ]; then - run ${sudo} rm -rf "${TMPDIR}" - fi -else - echo >&2 "NOTE: did not remove: ${TMPDIR}/netdata-latest.gz.run" - exit 1 -fi - -# -------------------------------------------------------------------------------------------------------------------- - -if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then - claim -fi diff --git a/packaging/installer/kickstart-static64.sh b/packaging/installer/kickstart-static64.sh new file mode 120000 index 000000000..71d605e7c --- /dev/null +++ b/packaging/installer/kickstart-static64.sh @@ -0,0 +1 @@ +kickstart.sh \ No newline at end of file diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh index 2fa762968..2fe627022 100755 --- a/packaging/installer/kickstart.sh +++ b/packaging/installer/kickstart.sh @@ -1,91 +1,105 @@ -#!/usr/bin/env bash -# SPDX-License-Identifier: GPL-3.0-or-later -# -# Run me with: -# -# bash <(curl -Ss https://my-netdata.io/kickstart.sh) -# -# or (to install all netdata dependencies): -# -# bash <(curl -Ss https://my-netdata.io/kickstart.sh) all -# -# Other options: -# --dont-wait do not prompt for user input -# --non-interactive do not prompt for user input -# --no-updates do not install script for daily updates -# --local-files set the full path of the desired tarball to run install with -# --allow-duplicate-install do not bail if we detect a duplicate install -# --reinstall if an existing install would be updated, reinstall instead -# --disable-telemetry opt out of anonymous statistics -# --claim-token specify a token to use for claiming the newly installed instance -# --claim-url specify a URL to use for claiming the newly installed isntance -# --claim-rooms specify a list of rooms to claim the newly installed instance to -# --claim-proxy specify a proxy to use while claiming the newly installed instance -# -# Environment options: +#!/bin/sh # -# TMPDIR specify where to save temporary files -# NETDATA_TARBALL_BASEURL set the base url for downloading the dist tarball -# -# This script will: -# -# 1. install all netdata compilation dependencies -# using the package manager of the system -# -# 2. download netdata nightly package to temporary directory -# -# 3. install netdata +# SPDX-License-Identifier: GPL-3.0-or-later -# shellcheck disable=SC2039,SC2059,SC2086 +# ====================================================================== +# Constants -# External files +KICKSTART_OPTIONS="${*}" PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh" - -# Netdata Tarball Base URL (defaults to our Google Storage Bucket) -[ -z "$NETDATA_TARBALL_BASEURL" ] && NETDATA_TARBALL_BASEURL=https://storage.googleapis.com/netdata-nightlies - +PATH="${PATH}:/usr/local/bin:/usr/local/sbin" +REPOCONFIG_URL_PREFIX="https://packagecloud.io/netdata/netdata-repoconfig/packages" +REPOCONFIG_VERSION="1-1" TELEMETRY_URL="https://posthog.netdata.cloud/capture/" -TELEMETRY_API_KEY="${NETDATA_POSTHOG_API_KEY:-mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y}" -KICKSTART_OPTIONS="${*}" - -# --------------------------------------------------------------------------------------------------------------------- -# library functions copied from packaging/installer/functions.sh +START_TIME="$(date +%s)" + +# ====================================================================== +# Defaults for environment variables + +SELECTED_INSTALL_METHOD="none" +INSTALL_TYPE="unknown" +INSTALL_PREFIX="" +NETDATA_AUTO_UPDATES="1" +NETDATA_CLAIM_ONLY=0 +NETDATA_CLAIM_URL="https://app.netdata.cloud" +NETDATA_DISABLE_CLOUD=0 +NETDATA_ONLY_BUILD=0 +NETDATA_ONLY_NATIVE=0 +NETDATA_ONLY_STATIC=0 +NETDATA_REQUIRE_CLOUD=1 +RELEASE_CHANNEL="nightly" -setup_terminal() { - TPUT_RESET="" - TPUT_YELLOW="" - TPUT_WHITE="" - TPUT_BGRED="" - TPUT_BGGREEN="" - TPUT_BOLD="" - TPUT_DIM="" +NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK:-0}" +NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://storage.googleapis.com/netdata-nightlies}" +NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:-""}" +TELEMETRY_API_KEY="${NETDATA_POSTHOG_API_KEY:-mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y}" - # Is stderr on the terminal? If not, then fail - test -t 2 || return 1 +if echo "${0}" | grep -q 'kickstart-static64'; then + NETDATA_ONLY_STATIC=1 +fi - if command -v tput > /dev/null 2>&1; then - if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then - # Enable colors - TPUT_RESET="$(tput sgr 0)" - TPUT_YELLOW="$(tput setaf 3)" - TPUT_WHITE="$(tput setaf 7)" - TPUT_BGRED="$(tput setab 1)" - TPUT_BGGREEN="$(tput setab 2)" - TPUT_BOLD="$(tput bold)" - TPUT_DIM="$(tput dim)" - fi - fi +if [ ! -t 1 ]; then + INTERACTIVE=0 +else + INTERACTIVE=1 +fi - return 0 +# ====================================================================== +# Usage info + +usage() { + cat << HEREDOC +USAGE: kickstart.sh [options] + where options include: + + --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal) + --interactive Prompt for user input even if there is no controlling terminal. + --dont-start-it Do not start the agent by default (only for static installs or local builds) + --stable-channel Install a stable version instead of a nightly build (default: install a nightly build) + --nightly-channel Install a nightly build instead of a stable version + --no-updates Do not enable automatic updates (default: enable automatic updates) + --auto-update Enable automatic updates. + --disable-telemetry Opt-out of anonymous statistics. + --native-only Only install if native binary packages are available. + --static-only Only install if a static build is available. + --build-only Only install using a local build. + --reinstall Explicitly reinstall instead of updating any existing install. + --reinstall-even-if-unsafe Even try to reinstall if we don't think we can do so safely (implies --reinstall). + --disable-cloud Disable support for Netdata Cloud (default: detect) + --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud. + --install Specify an installation prefix for local builds (default: autodetect based on system type). + --claim-token Use a specified token for claiming to Netdata Cloud. + --claim-rooms When claiming, add the node to the specified rooms. + --claim-only If there is an existing install, only try to claim it, not update it. + --claim-* Specify other options for the claiming script. + --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer. + +Additionally, this script may use the following environment variables: + + TMPDIR: Used to specify where to put temporary files. On most systems, the default we select + automatically should be fine. The user running the script needs to both be able to + write files to the temporary directory, and run files from that location. + ROOTCMD: Used to specify a command to use to run another command with root privileges if needed. By + default we try to use sudo, doas, or pkexec (in that order of preference), but if + you need special options for one of those to work, or have a different tool to do + the same thing on your system, you can specify it here. + DO_NOT_TRACK If set to a value other than 0, behave as if \`--disable-telemetry\` was specified. + NETDATA_INSTALLER_OPTIONS: Specifies extra options to pass to the static installer or local build script. + +HEREDOC } -setup_terminal || echo > /dev/null -# ----------------------------------------------------------------------------- +# ====================================================================== +# Telemetry functions + telemetry_event() { - if [ -n "${NETDATA_DISABLE_TELEMETRY}" ]; then + if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then return 0 fi + now="$(date +%s)" + total_duration="$((now - START_TIME))" + if [ -e "/etc/os-release" ]; then eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/HOST_/')" fi @@ -115,7 +129,7 @@ telemetry_event() { if [ -f /etc/machine-id ]; then DISTINCT_ID="$(cat /etc/machine-id)" - elif command -v uuidgen 2> /dev/null; then + elif command -v uuidgen > /dev/null 2>&1; then DISTINCT_ID="$(uuidgen)" else DISTINCT_ID="null" @@ -132,12 +146,14 @@ telemetry_event() { "\$pathname": "netdata-installer", "\$host": "installer.netdata.io", "\$ip": "127.0.0.1", - "script_variant": "legacy-kickstart", - "error_code": "${2}", - "error_message": "${3}", + "script_variant": "kickstart-ng", + "error_code": "${3}", + "error_message": "${2}", "install_options": "${KICKSTART_OPTIONS}", + "total_runtime": "${total_duration}", + "selected_install_method": "${SELECTED_INSTALL_METHOD}", "netdata_release_channel": "${RELEASE_CHANNEL:-null}", - "netdata_install_type": "kickstart-build", + "netdata_install_type": "${INSTALL_TYPE}", "host_os_name": "${HOST_NAME:-unknown}", "host_os_id": "${HOST_ID:-unknown}", "host_os_id_like": "${HOST_ID_LIKE:-unknown}", @@ -152,39 +168,102 @@ telemetry_event() { EOF )" -if [ -n "$(command -v curl 2> /dev/null)" ]; then - curl --silent -o /dev/null --write-out '%{http_code}' -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" -else - wget -q -O - --no-check-certificate \ - --server-response \ - --method POST \ - --timeout=1 \ - --header 'Content-Type: application/json' \ - --body-data "${REQ_BODY}" \ - "${TELEMETRY_URL}" 2>&1 | awk '/^ HTTP/{print $2}' -fi + if command -v curl > /dev/null 2>&1; then + curl --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null + elif command -v wget > /dev/null 2>&1; then + wget -q -O - --no-check-certificate \ + --method POST \ + --timeout=1 \ + --header 'Content-Type: application/json' \ + --body-data "${REQ_BODY}" \ + "${TELEMETRY_URL}" > /dev/null + fi +} + +trap_handler() { + code="${1}" + lineno="${2}" + + printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})" + + telemetry_event INSTALL_CRASH "Installer exited unexpectedly (${code}-${lineno})" "E${code}-${lineno}" + + trap - EXIT + + cleanup + + exit 1 +} + +trap 'trap_handler 0 ${LINENO}' EXIT +trap 'trap_handler 1 0' HUP +trap 'trap_handler 2 0' INT +trap 'trap_handler 3 0' QUIT +trap 'trap_handler 13 0' PIPE +trap 'trap_handler 15 0' TERM + +# ====================================================================== +# Utility functions + +setup_terminal() { + TPUT_RESET="" + TPUT_WHITE="" + TPUT_BGRED="" + TPUT_BGGREEN="" + TPUT_BOLD="" + TPUT_DIM="" + + # Is stderr on the terminal? If not, then fail + test -t 2 || return 1 + + if command -v tput > /dev/null 2>&1; then + if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then + # Enable colors + TPUT_RESET="$(tput sgr 0)" + TPUT_WHITE="$(tput setaf 7)" + TPUT_BGRED="$(tput setab 1)" + TPUT_BGGREEN="$(tput setab 2)" + TPUT_BOLD="$(tput bold)" + TPUT_DIM="$(tput dim)" + fi + fi + + echo "${TPUT_RESET}" + + return 0 +} + +cleanup() { + if [ -z "${NO_CLEANUP}" ]; then + ${ROOTCMD} rm -rf "${tmpdir}" + fi } fatal() { - printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1} \n\n" + printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}" telemetry_event "INSTALL_FAILED" "${1}" "${2}" + cleanup + trap - EXIT exit 1 } run_ok() { - printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} \n\n" + printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}" } run_failed() { - printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} \n\n" + printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}" } ESCAPED_PRINT_METHOD= +# shellcheck disable=SC3050 if printf "%q " test > /dev/null 2>&1; then ESCAPED_PRINT_METHOD="printfq" fi + escaped_print() { if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then + # shellcheck disable=SC3050 printf "%q " "${@}" else printf "%s" "${*}" @@ -193,14 +272,15 @@ escaped_print() { } progress() { - echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- " + echo >&2 " --- ${TPUT_BOLD}${*}${TPUT_RESET} --- " } run_logfile="/dev/null" run() { - local user="${USER--}" dir="${PWD}" info info_console + user="${USER--}" + dir="${PWD}" - if [ "${UID}" = "0" ]; then + if [ "$(id -u)" = "0" ]; then info="[root ${dir}]# " info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# " else @@ -209,51 +289,44 @@ run() { fi { - printf "${info}" + printf "%s" "${info}" escaped_print "${@}" printf " ... " } >> "${run_logfile}" - printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}" + printf >&2 "%s" "${info_console}${TPUT_BOLD}" escaped_print >&2 "${@}" - printf >&2 "${TPUT_RESET}" + printf >&2 "%s\n" "${TPUT_RESET}" "${@}" - local ret=$? + ret=$? if [ ${ret} -ne 0 ]; then run_failed - printf >> "${run_logfile}" "FAILED with exit code ${ret}\n" + printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}" else run_ok - printf >> "${run_logfile}" "OK\n" + printf "OK\n" >> "${run_logfile}" fi return ${ret} } warning() { - printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*} \n\n" - if [ "${INTERACTIVE}" = "0" ]; then - fatal "Stopping due to non-interactive mode. Fix the issue or retry installation in an interactive mode." F0001 - else - read -r -p "Press ENTER to attempt netdata installation > " - progress "OK, let's give it a try..." - fi + printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}" } _cannot_use_tmpdir() { - local testfile ret testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)" ret=0 - if [ -z "${testfile}" ] ; then + if [ -z "${testfile}" ]; then return "${ret}" fi - if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}" ; then - if chmod +x "${testfile}" ; then - if [ "$("${testfile}")" = "SUCCESS" ] ; then + if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then + if chmod +x "${testfile}"; then + if [ "$("${testfile}")" = "SUCCESS" ]; then ret=1 fi fi @@ -264,12 +337,10 @@ _cannot_use_tmpdir() { } create_tmp_directory() { - if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then - if _cannot_use_tmpdir /tmp ; then - if _cannot_use_tmpdir "${PWD}" ; then - echo >&2 - echo >&2 "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." - exit 1 + if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then + if _cannot_use_tmpdir /tmp; then + if _cannot_use_tmpdir "${PWD}"; then + fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." F0400 else TMPDIR="${PWD}" fi @@ -285,346 +356,771 @@ download() { url="${1}" dest="${2}" if command -v curl > /dev/null 2>&1; then - run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || fatal "Cannot download ${url}" F0002 + run curl --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1 elif command -v wget > /dev/null 2>&1; then - run wget -T 15 -O "${dest}" "${url}" || fatal "Cannot download ${url}" F0002 + run wget -T 15 -O "${dest}" "${url}" || return 1 else - fatal "I need curl or wget to proceed, but neither is available on this system." F0003 + fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003 fi } -set_tarball_urls() { - if [ -n "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ]; then - progress "Not fetching remote tarballs, local override was given" - return - fi +get_redirect() { + url="${1}" - if [ "$1" = "stable" ]; then - local latest - # Simple version - 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_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/$latest/sha256sums.txt" + if command -v curl > /dev/null 2>&1; then + run sh -c "curl ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$'" || return 1 + elif command -v wget > /dev/null 2>&1; then + run sh -c "wget --max-redirect=0 ${url} 2>&1 | grep Location | cut -d ' ' -f2 | grep -o '[^/]*$'" || return 1 else - export NETDATA_TARBALL_URL="$NETDATA_TARBALL_BASEURL/netdata-latest.tar.gz" - export NETDATA_TARBALL_CHECKSUM_URL="$NETDATA_TARBALL_BASEURL/sha256sums.txt" + fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003 fi } -detect_bash4() { - bash="${1}" - if [ -z "${BASH_VERSION}" ]; then - # we don't run under bash - if [ -n "${bash}" ] && [ -x "${bash}" ]; then - # shellcheck disable=SC2016 - BASH_MAJOR_VERSION=$(${bash} -c 'echo "${BASH_VERSINFO[0]}"') - fi +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 using non-common options + if command -v sha256sum > /dev/null 2>&1; then + sha256sum "$@" + elif command -v shasum > /dev/null 2>&1; then + shasum -a 256 "$@" else - # we run under bash - BASH_MAJOR_VERSION="${BASH_VERSINFO[0]}" + fatal "I could not find a suitable checksum binary to use" F0004 fi +} - if [ -z "${BASH_MAJOR_VERSION}" ]; then - echo >&2 "No BASH is available on this system" - return 1 - elif [ $((BASH_MAJOR_VERSION)) -lt 4 ]; then - echo >&2 "No BASH v4+ is available on this system (installed bash is v${BASH_MAJOR_VERSION})" - return 1 +get_system_info() { + case "$(uname -s)" in + Linux) + SYSTYPE="Linux" + + 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}" + SYSVERSION="${VERSION_ID}" + SYSCODENAME="${VERSION_CODENAME}" + SYSARCH="$(uname -m)" + + 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 + ;; + Darwin) + SYSTYPE="Darwin" + SYSVERSION="$(sw_vers -buildVersion)" + SYSARCH="$(uname -m)" + ;; + FreeBSD) + SYSTYPE="FreeBSD" + SYSVERSION="$(uname -K)" + SYSARCH="$(uname -m)" + ;; + *) + fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200 + ;; + esac +} + +str_in_list() { + printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$" + return $? +} + +confirm_root_support() { + if [ "$(id -u)" -ne "0" ]; then + if [ -z "${ROOTCMD}" ] && command -v sudo > /dev/null; then + ROOTCMD="sudo" + fi + + if [ -z "${ROOTCMD}" ] && command -v doas > /dev/null; then + ROOTCMD="doas" + fi + + if [ -z "${ROOTCMD}" ] && command -v pkexec > /dev/null; then + ROOTCMD="pkexec" + fi + + if [ -z "${ROOTCMD}" ]; then + fatal "We need root privileges to continue, but cannot find a way to gain them. Either re-run this script as root, or set \$ROOTCMD to a command that can be used to gain root privileges" F0201 + fi fi - return 0 } -dependencies() { - SYSTEM="$(uname -s 2> /dev/null || uname -v)" - OS="$(uname -o 2> /dev/null || uname -rs)" - MACHINE="$(uname -m 2> /dev/null)" +confirm() { + prompt="${1} [y/n]" - echo "System : ${SYSTEM}" - echo "Operating System : ${OS}" - echo "Machine : ${MACHINE}" - echo "BASH major version: ${BASH_MAJOR_VERSION}" + while true; do + echo "${prompt}" + read -r yn - bash="$(command -v bash 2> /dev/null)" - if ! detect_bash4 "${bash}"; then - warning "Cannot detect packages to be installed in this system, without BASH v4+." + case "$yn" in + [Yy]*) return 0;; + [Nn]*) return 1;; + *) echo "Please answer yes or no.";; + esac + done +} + +# ====================================================================== +# Existing install handling code + +update() { + updater="${ndprefix}/usr/libexec/netdata/netdata-updater.sh" + + if [ -x "${updater}" ]; then + if run ${ROOTCMD} "${updater}" --not-running-from-cron; then + progress "Updated existing install at ${ndprefix}" + return 0 + else + fatal "Failed to update existing Netdata install at ${ndprefix}" F0100 + fi else - progress "Fetching script to detect required packages..." - if [ -n "${NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT}" ]; then - if [ -f "${NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT}" ]; then - run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT}" "${ndtmpdir}/install-required-packages.sh" - else - fatal "Invalid given dependency file, please check your --local-files parameter options and try again" F1001 - fi + return 1 + fi +} + +handle_existing_install() { + if pkg_installed netdata; then + ndprefix="/" + else + if [ -n "${INSTALL_PREFIX}" ]; then + searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}" + searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}" else - download "${PACKAGES_SCRIPT}" "${ndtmpdir}/install-required-packages.sh" + searchpath="${PATH}" + fi + + ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)" + + if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ]; then + ndpath="/opt/netdata/bin/netdata" + fi + + if [ -n "${ndpath}" ]; then + ndprefix="$(dirname "$(dirname "${ndpath}")")" + fi + + if echo "${ndprefix}" | grep -Eq '/usr$'; then + ndprefix="$(dirname "${ndprefix}")" fi + fi - if [ ! -s "${ndtmpdir}/install-required-packages.sh" ]; then - warning "Downloaded dependency installation script is empty." + if [ -n "${ndprefix}" ]; then + typefile="${ndprefix}/etc/netdata/.install-type" + if [ -r "${typefile}" ]; then + ${ROOTCMD} sh -c "cat \"${typefile}\" > \"${tmpdir}/install-type\"" + # shellcheck disable=SC1091 + . "${tmpdir}/install-type" else - progress "Running downloaded script to detect required packages..." - run ${sudo} "${bash}" "${ndtmpdir}/install-required-packages.sh" ${PACKAGES_INSTALLER_OPTIONS} - # shellcheck disable=SC2181 - if [ $? -ne 0 ]; then - warning "It failed to install all the required packages, but installation might still be possible." - fi + INSTALL_TYPE="unknown" fi + fi + if [ -z "${ndprefix}" ]; then + progress "No existing installations of netdata found, assuming this is a fresh install." + return 0 fi + + case "${INSTALL_TYPE}" in + kickstart-*|legacy-*|binpkg-*|manual-static|unknown) + if [ "${INSTALL_TYPE}" = "unknown" ]; then + warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type." + else + progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'." + fi + + if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then + progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing." + + case "${INSTALL_TYPE}" in + binpkg-*) NETDATA_ONLY_NATIVE=1 ;; + *-build) NETDATA_ONLY_BUILD=1 ;; + *-static) NETDATA_ONLY_STATIC=1 ;; + *) + if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then + warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed." + elif [ "${INTERACTIVE}" -eq 0 ]; then + fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104 + else + if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then + progress "OK, continuing." + else + fatal "Cancelling reinstallation at user request." F0105 + fi + fi + ;; + esac + + return 0 + fi + + ret=0 + + if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then + if ! update; then + warning "Unable to find usable updater script, not updating existing install at ${ndprefix}." + fi + else + warning "Not updating existing install at ${ndprefix}." + fi + + if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then + progress "Attempting to claim existing install at ${ndprefix}." + INSTALL_PREFIX="${ndprefix}" + claim + ret=$? + elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then + fatal "User asked to claim, but did not proide a claiming token." F0202 + else + progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)." + fi + + cleanup + trap - EXIT + exit $ret + ;; + oci) + fatal "This is an OCI container, use the regular image lifecycle management commands in your container instead of this script for managing it." F0203 + ;; + *) + if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then + if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then + warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed." + elif [ "${INTERACTIVE}" -eq 0 ]; then + fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104 + else + if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then + progress "OK, continuing." + else + fatal "Cancelling reinstallation at user request." F0105 + fi + fi + else + fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103 + fi + ;; + esac } -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 - if command -v sha256sum > /dev/null 2>&1; then - sha256sum "$@" - elif command -v shasum > /dev/null 2>&1; then - shasum -a 256 "$@" +soft_disable_cloud() { + cloud_prefix="${INSTALL_PREFIX}/var/lib/netdata/cloud.d" + + run ${ROOTCMD} mkdir -p "${cloud_prefix}" + + cat > "${tmpdir}/cloud.conf" << EOF +[global] + enabled = no +EOF + + run ${ROOTCMD} cp "${tmpdir}/cloud.conf" "${cloud_prefix}/cloud.conf" + + if [ -z "${NETDATA_NO_START}" ]; then + case "${SYSTYPE}" in + Darwin) run ${ROOTCMD} launchctl kickstart -k com.github.netdata ;; + FreeBSD) run ${ROOTCMD} service netdata restart ;; + Linux) + initpath="$(${ROOTCMD} readlink /proc/1/exe)" + + if command -v service > /dev/null 2>&1; then + run ${ROOTCMD} service netdata restart + elif command -v rc-service > /dev/null 2>&1; then + run ${ROOTCMD} rc-service netdata restart + elif [ "$(basename "${initpath}" 2> /dev/null)" = "systemd" ]; then + run ${ROOTCMD} systemctl restart netdata + elif [ -f /etc/init.d/netdata ]; then + run ${ROOTCMD} /etc/init.d/netdata restart + fi + ;; + esac + fi +} + +confirm_install_prefix() { + if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then + fatal "The \`--install\` option is only supported together with the \`--only-build\` option." F0204 + fi + + if [ -n "${INSTALL_PREFIX}" ]; then + NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install ${INSTALL_PREFIX}" else - fatal "I could not find a suitable checksum binary to use" F0004 + case "${SYSTYPE}" in + Darwin) + INSTALL_PREFIX="/usr/local/netdata" + NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}" + ;; + FreeBSD) + INSTALL_PREFIX="/usr/local" + NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}" + ;; + esac + fi +} + +# ====================================================================== +# Claiming support code + +check_claim_opts() { +# shellcheck disable=SC2235,SC2030 + if [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then + fatal "Invalid claiming options, claim rooms may only be specified when a token and URL are specified." F0204 + elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_EXTRA}" ]; then + fatal "Invalid claiming options, a claiming token must be specified." F0204 + elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ] && [ -n "${NETDATA_CLAIM_TOKEN}" ]; then + fatal "Cloud explicitly disabled, but automatic claiming requested. Either enable Netdata Cloud, or remove the --claim-* options." F0204 + fi +} + +is_netdata_running() { + if command -v pgrep > /dev/null 2>&1; then + if pgrep netdata; then + return 0 + else + return 1 + fi + else + if [ -z "${INSTALL_PREFIX}" ]; then + NETDATACLI_PATH=/usr/sbin/netdatacli + elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then + NETDATACLI_PATH="/opt/netdata/bin/netdatacli" + else + NETDATACLI_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdatacli" + fi + + if "${NETDATACLI_PATH}" ping > /dev/null 2>&1; then + return 0 + else + return 1 + fi fi } claim() { progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}" - if [ -z "${NETDATA_PREFIX}" ] ; then + if [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh + elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then + NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh" else - NETDATA_CLAIM_PATH="${NETDATA_PREFIX}/netdata/usr/sbin/netdata-claim.sh" + NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh" + fi + + if ! is_netdata_running; then + NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running" fi - if ${sudo} "${NETDATA_CLAIM_PATH}" -token=${NETDATA_CLAIM_TOKEN} -rooms=${NETDATA_CLAIM_ROOMS} -url=${NETDATA_CLAIM_URL} ${NETDATA_CLAIM_EXTRA}; then + # shellcheck disable=SC2086 + if ${ROOTCMD} "${NETDATA_CLAIM_PATH}" -token="${NETDATA_CLAIM_TOKEN}" -rooms="${NETDATA_CLAIM_ROOMS}" -url="${NETDATA_CLAIM_URL}" ${NETDATA_CLAIM_EXTRA}; then progress "Successfully claimed node" - return 0 else - run_failed "Unable to claim node, you must do so manually." - return 1 + warning "Unable to claim node, you must do so manually." + if [ -z "${NETDATA_NEW_INSTALL}" ]; then + cleanup + trap - EXIT + exit 1 + fi fi } -# --------------------------------------------------------------------------------------------------------------------- -umask 022 - -sudo="" -[ -z "${UID}" ] && UID="$(id -u)" -[ "${UID}" -ne "0" ] && sudo="sudo" -export PATH="${PATH}:/usr/local/bin:/usr/local/sbin" +# ====================================================================== +# Native package install code. - -# --------------------------------------------------------------------------------------------------------------------- - -INTERACTIVE=1 -PACKAGES_INSTALLER_OPTIONS="netdata" -NETDATA_INSTALLER_OPTIONS="" -NETDATA_UPDATES="--auto-update" -RELEASE_CHANNEL="nightly" -while [ -n "${1}" ]; do - case "${1}" in - "all") PACKAGES_INSTALLER_OPTIONS="netdata-all" ;; - "--dont-wait") INTERACTIVE=0 ;; - "--non-interactive") INTERACTIVE=0 ;; - "--no-updates") NETDATA_UPDATES= ;; - "--stable-channel") - RELEASE_CHANNEL="stable" - NETDATA_INSTALLER_OPTIONS="$NETDATA_INSTALLER_OPTIONS --stable-channel" - ;; - "--allow-duplicate-install") NETDATA_ALLOW_DUPLICATE_INSTALL=1 ;; - "--reinstall") NETDATA_REINSTALL=1 ;; - "--claim-token") - NETDATA_CLAIM_TOKEN="${2}" - shift 1 - ;; - "--claim-rooms") - NETDATA_CLAIM_ROOMS="${2}" - shift 1 +# Check for an already installed package with a given name. +pkg_installed() { + case "${DISTRO_COMPAT_NAME}" in + debian|ubuntu) + dpkg -l "${1}" > /dev/null 2>&1 + return $? ;; - "--claim-url") - NETDATA_CLAIM_URL="${2}" - shift 1 + centos|fedora|opensuse) + rpm -q "${1}" > /dev/null 2>&1 + return $? ;; - "--claim-proxy") - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -proxy ${2}" - shift 1 + *) + return 1 ;; - "--dont-start-it") - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running" - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it" + esac +} + +# Check for the existence of a usable netdata package in the repo. +netdata_avail_check() { + case "${DISTRO_COMPAT_NAME}" in + debian|ubuntu) + env DEBIAN_FRONTEND=noninteractive apt-cache policy netdata | grep -q packagecloud.io/netdata/netdata; + return $? ;; - "--install") - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install ${2}" - NETDATA_PREFIX="${2}" - shift 1 + centos|fedora) + # shellcheck disable=SC2086 + ${pm_cmd} search -v netdata | grep -qE 'Repo *: netdata(-edge)?$' + return $? ;; - "--disable-cloud") - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-cloud" - NETDATA_DISABLE_CLOUD=1 + opensuse) + zypper packages -r "$(zypper repos | grep -E 'netdata |netdata-edge ' | cut -f 1 -d '|' | tr -d ' ')" | grep -E 'netdata ' + return $? ;; - "--disable-telemetry") - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry" - NETDATA_DISABLE_TELEMETRY=1 + *) + return 1 ;; - "--local-files") - if [ -z "${2}" ]; then - fatal "Missing netdata: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1002 - fi + esac +} - export NETDATA_LOCAL_TARBALL_OVERRIDE="${2}" +# Check for any distro-specific dependencies we know we need. +check_special_native_deps() { + if [ "${DISTRO_COMPAT_NAME}" = "centos" ] && [ "${SYSVERSION}" = "7" ]; then + progress "Checking for libuv availability." + # shellcheck disable=SC2086 + if ${pm_cmd} search ${interactive_opts} -v libuv | grep -q "No matches found"; then + progress "libv not found, checking for EPEL availability." + # shellcheck disable=SC2086 + if ${pm_cmd} search ${interactive_opts} -v epel-release | grep -q "No matches found"; then + warning "Unable to find a suitable source for libuv, cannot install on this system." + return 1 + else + progress "EPEL is available, attempting to install so that required dependencies are available." - if [ -z "${3}" ]; then - fatal "Missing checksum file: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1003 + # shellcheck disable=SC2086 + if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} epel-release; then + warning "Failed to install EPEL." + return 1 + fi fi + else + return 0 + fi + fi +} - export NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${3}" - - if [ -z "${4}" ]; then - fatal "Missing go.d tarball: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1004 - fi +try_package_install() { + if [ -z "${DISTRO}" ]; then + warning "Unable to determine Linux distribution for native packages." + return 1 + fi - export NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN="${4}" + progress "Attempting to install using native packages..." - if [ -z "${5}" ]; then - fatal "Missing go.d config tarball: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1005 - fi + if [ "${RELEASE_CHANNEL}" = "nightly" ]; then + release="-edge" + else + release="" + fi - export NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG="${5}" + if [ "${INTERACTIVE}" = "0" ]; then + interactive_opts="-y" + env="DEBIAN_FRONTEND=noninteractive" + else + interactive_opts="" + env="" + fi - if [ -z "${6}" ]; then - fatal "Missing dependencies management scriptlet: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1006 + case "${DISTRO_COMPAT_NAME}" in + debian) + needs_early_refresh=1 + pm_cmd="apt-get" + repo_subcmd="update" + repo_prefix="debian/${SYSCODENAME}" + pkg_type="deb" + pkg_suffix="_all" + pkg_vsep="_" + pkg_install_opts="${interactive_opts}" + repo_update_opts="${interactive_opts}" + uninstall_subcmd="purge" + INSTALL_TYPE="binpkg-deb" + ;; + ubuntu) + needs_early_refresh=1 + pm_cmd="apt-get" + repo_subcmd="update" + repo_prefix="ubuntu/${SYSCODENAME}" + pkg_type="deb" + pkg_suffix="_all" + pkg_vsep="_" + pkg_install_opts="${interactive_opts}" + repo_update_opts="${interactive_opts}" + uninstall_subcmd="purge" + INSTALL_TYPE="binpkg-deb" + ;; + centos) + if command -v dnf > /dev/null; then + pm_cmd="dnf" + repo_subcmd="makecache" + else + pm_cmd="yum" fi - - export NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT="${6}" - shift 5 + repo_prefix="el/${SYSVERSION}" + pkg_type="rpm" + pkg_suffix=".noarch" + pkg_vsep="-" + pkg_install_opts="${interactive_opts}" + repo_update_opts="${interactive_opts}" + uninstall_subcmd="remove" + INSTALL_TYPE="binpkg-rpm" + ;; + fedora) + if command -v dnf > /dev/null; then + pm_cmd="dnf" + repo_subcmd="makecache" + else + pm_cmd="yum" + fi + repo_prefix="fedora/${SYSVERSION}" + pkg_type="rpm" + pkg_suffix=".noarch" + pkg_vsep="-" + pkg_install_opts="${interactive_opts}" + repo_update_opts="${interactive_opts}" + uninstall_subcmd="remove" + INSTALL_TYPE="binpkg-rpm" + ;; + opensuse) + pm_cmd="zypper" + repo_subcmd="--gpg-auto-import-keys refresh" + repo_prefix="opensuse/${SYSVERSION}" + pkg_type="rpm" + pkg_suffix=".noarch" + pkg_vsep="-" + pkg_install_opts="${interactive_opts} --allow-unsigned-rpm" + repo_update_opts="" + uninstall_subcmd="remove" + INSTALL_TYPE="binpkg-rpm" ;; *) - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}" + warning "We do not provide native packages for ${DISTRO}." + return 2 ;; esac - shift 1 -done -if [ "${INTERACTIVE}" = "0" ]; then - PACKAGES_INSTALLER_OPTIONS="--dont-wait --non-interactive ${PACKAGES_INSTALLER_OPTIONS}" - NETDATA_INSTALLER_OPTIONS="$NETDATA_INSTALLER_OPTIONS --dont-wait" -fi + repoconfig_name="netdata-repo${release}" + repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_VERSION}${pkg_suffix}.${pkg_type}" + repoconfig_url="${REPOCONFIG_URL_PREFIX}/${repo_prefix}/${repoconfig_file}/download.${pkg_type}" + + if ! pkg_installed "${repoconfig_name}"; then + progress "Downloading repository configuration package." + if ! download "${repoconfig_url}" "${tmpdir}/${repoconfig_file}"; then + warning "Failed to download repository configuration package." + return 2 + fi + + if [ -n "${needs_early_refresh}" ]; then + progress "Updating repository metadata." + # shellcheck disable=SC2086 + if ! run ${ROOTCMD} env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then + warning "Failed to refresh repository metadata." + return 2 + fi + fi -if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then - if [ -n "${NETDATA_CLAIM_TOKEN}" ] || [ -n "${NETDATA_CLAIM_ROOMS}" ] || [ -n "${NETDATA_CLAIM_URL}" ]; then - run_failed "Cloud explicitly disabled but automatic claiming requested." - run_failed "Either enable Netdata Cloud, or remove the --claim-* options." - exit 1 + progress "Installing repository configuration package." + # shellcheck disable=SC2086 + if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} "${tmpdir}/${repoconfig_file}"; then + warning "Failed to install repository configuration package." + return 2 + fi + + if [ -n "${repo_subcmd}" ]; then + progress "Updating repository metadata." + # shellcheck disable=SC2086 + if ! run ${ROOTCMD} env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then + fatal "Failed to update repository metadata." F0205 + fi + fi + else + progress "Repository configuration is already present, attempting to install netdata." fi -fi -# shellcheck disable=SC2235,SC2030,SC2031 -if ( [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_URL}" ] ) || ( [ -n "${NETDATA_CLAIM_TOKEN}" ] && [ -z "${NETDATA_CLAIM_URL}" ] ); then - run_failed "Invalid claiming options, both a claiming token and URL must be specified." - exit 1 -elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then - run_failed "Invalid claiming options, claim rooms may only be specified when a token and URL are specified." - exit 1 -fi + if ! check_special_native_deps; then + warning "Could not find secondary dependencies ${DISTRO} on ${SYSARCH}." + if [ -z "${NO_CLEANUP}" ]; then + progress "Attempting to uninstall repository configuration package." + # shellcheck disable=SC2086 + run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}" + fi + return 2 + fi -# --------------------------------------------------------------------------------------------------------------------- -# look for an existing install and try to update that instead if it exists + progress "Checking for usable Netdata package." + if ! netdata_avail_check "${DISTRO_COMPAT_NAME}"; then + warning "Could not find a usable native package for ${DISTRO} on ${SYSARCH}." + if [ -z "${NO_CLEANUP}" ]; then + progress "Attempting to uninstall repository configuration package." + # shellcheck disable=SC2086 + run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}" + fi + return 2 + fi -ndpath="$(command -v netdata 2>/dev/null)" -if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then - ndpath="/opt/netdata/bin/netdata" -fi + if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then + run ${ROOTCMD} mkdir -p "/etc/netdata" + run ${ROOTCMD} touch "/etc/netdata/.opt-out-from-anonymous-statistics" + fi -if [ -n "$ndpath" ] ; then - ndprefix="$(dirname "$(dirname "${ndpath}")")" + progress "Installing Netdata package." + # shellcheck disable=SC2086 + if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} netdata; then + warning "Failed to install Netdata package." + if [ -z "${NO_CLEANUP}" ]; then + progress "Attempting to uninstall repository configuration package." + # shellcheck disable=SC2086 + run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}" + fi + return 2 + fi +} - if [ "${ndprefix}" = /usr ] ; then - ndprefix="/" +# ====================================================================== +# Static build install code + +set_static_archive_urls() { + if [ "${RELEASE_CHANNEL}" = "stable" ]; then + latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")" + export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${SYSARCH}-latest.gz.run" + export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt" + else + export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-${SYSARCH}-latest.gz.run" + export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt" fi +} - progress "Found existing install of Netdata under: ${ndprefix}" +try_static_install() { + set_static_archive_urls "${RELEASE_CHANNEL}" + progress "Downloading static netdata binary: ${NETDATA_STATIC_ARCHIVE_URL}" - if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then - ndstatic="$(grep IS_NETDATA_STATIC_BINARY "${ndprefix}/etc/netdata/.environment" | cut -d "=" -f 2 | tr -d \")" - if [ -z "${NETDATA_REINSTALL}" ] && [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ] ; then - if [ -n "${NETDATA_CLAIM_TOKEN}" ] ; then - if [ "${ndprefix}" != '/' ] ; then - NETDATA_PREFIX="${ndprefix}" - fi + if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "${tmpdir}/netdata-${SYSARCH}-latest.gz.run"; then + warning "Unable to download static build archive for ${SYSARCH}." + return 2 + fi - claim - exit $? - elif [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then - progress "Attempting to update existing install instead of creating a new one" - if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then - progress "Updated existing install at ${ndpath}" - exit 0 - else - fatal "Failed to update existing Netdata install" F0100 - fi - else - if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] || [ "${ndstatic}" = "yes" ] ; then - fatal "Existing installation detected which cannot be safely updated by this script. Refusing to continue." F0101 - else - progress "User explicitly requested duplicate install, proceeding." - fi - fi - else - if [ "${ndstatic}" = "no" ] ; then - progress "User requested reinstall instead of update, proceeding." - else - fatal "Existing install is a static install. Please use kickstart-static64.sh instead." F0102 - fi - fi + if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"; then + fatal "Unable to fetch checksums to verify static build archive." F0206 + fi + + if ! grep "netdata-${SYSARCH}-latest.gz.run" "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then + fatal "Static binary checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0207 + fi + + if [ "${INTERACTIVE}" -eq 0 ]; then + opts="${opts} --accept" + fi + + progress "Installing netdata" + # shellcheck disable=SC2086 + if ! run ${ROOTCMD} sh "${tmpdir}/netdata-${SYSARCH}-latest.gz.run" ${opts} -- ${NETDATA_AUTO_UPDATES:+--auto-update} ${NETDATA_INSTALLER_OPTIONS}; then + warning "Failed to install static build of Netdata on ${SYSARCH}." + run rm -rf /opt/netdata + return 2 + fi + + install_type_file="/opt/netdata/etc/netdata/.install-type" + if [ -f "${install_type_file}" ]; then + ${ROOTCMD} sh -c "cat \"${install_type_file}\" > \"${tmpdir}/install-type\"" + ${ROOTCMD} chown "$(id -u)":"$(id -g)" "${tmpdir}/install-type" + # shellcheck disable=SC1091 + . "${tmpdir}/install-type" + cat > "${tmpdir}/install-type" <<- EOF + INSTALL_TYPE='kickstart-static' + PREBUILT_ARCH='${PREBUILT_ARCH}' + EOF + ${ROOTCMD} chown netdata:netdata "${tmpdir}/install-type" + ${ROOTCMD} cp "${tmpdir}/install-type" "${install_type_file}" + fi +} + +# ====================================================================== +# Local build install code + +set_source_archive_urls() { + if [ "$1" = "stable" ]; then + latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")" + export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${latest}.tar.gz" + export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt" else - progress "Existing install appears to be handled manually or through the system package manager." - if [ -n "${NETDATA_CLAIM_TOKEN}" ] ; then - if [ "${ndprefix}" != '/' ] ; then - NETDATA_PREFIX="${ndprefix}" - fi + export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-latest.tar.gz" + export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt" + fi +} + +install_local_build_dependencies() { + bash="$(command -v bash 2> /dev/null)" + + if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then + warning "Unable to find a usable version of \`bash\` (required for local build)." + return 1 + fi + + progress "Fetching script to detect required packages..." + download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh" + + if [ ! -s "${tmpdir}/install-required-packages.sh" ]; then + warning "Downloaded dependency installation script is empty." + else + progress "Running downloaded script to detect required packages..." - claim - exit $? - elif [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then - fatal "Existing installation detected which cannot be safely updated by this script. Refusing to continue." F0103 + if [ "${INTERACTIVE}" -eq 0 ]; then + opts="--dont-wait --non-interactive" + fi + + if [ "${SYSTYPE}" = "Darwin" ]; then + sudo="" else - progress "User explicitly requested duplicate install, proceeding." + sudo="${ROOTCMD}" + fi + + # shellcheck disable=SC2086 + if ! run ${sudo} "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then + warning "It failed to install all the required packages, but installation might still be possible." fi fi -fi +} -# --------------------------------------------------------------------------------------------------------------------- -# install required system packages +build_and_install() { + progress "Building netdata" -ndtmpdir=$(create_tmp_directory) -cd "${ndtmpdir}" || exit 1 + echo "INSTALL_TYPE='kickstart-build'" > system/.install-type -dependencies + opts="${NETDATA_INSTALLER_OPTIONS}" -# --------------------------------------------------------------------------------------------------------------------- -# download netdata package + if [ "${INTERACTIVE}" -eq 0 ]; then + opts="${opts} --dont-wait" + fi -if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ]; then - set_tarball_urls "${RELEASE_CHANNEL}" + if [ "${NETDATA_AUTO_UPDATES}" -eq 1 ]; then + opts="${opts} --auto-update" + fi - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" - download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.tar.gz" -else - progress "Installation sources were given as input, running installation using \"${NETDATA_LOCAL_TARBALL_OVERRIDE}\"" - run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM}" "${ndtmpdir}/sha256sum.txt" - run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE}" "${ndtmpdir}/netdata-latest.tar.gz" -fi + if [ "${RELEASE_CHANNEL}" = "stable" ]; then + opts="${opts} --stable-channel" + fi -if ! grep netdata-latest.tar.gz "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then - fatal "Tarball checksum validation failed. Stopping Netdata Agent installation and leaving tarball in ${ndtmpdir}.\nUsually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0005 -fi -run tar -xf netdata-latest.tar.gz -rm -rf netdata-latest.tar.gz > /dev/null 2>&1 -cd netdata-* || fatal "Cannot cd to netdata source tree" F0006 + if [ "${NETDATA_REQUIRE_CLOUD}" -eq 1 ]; then + opts="${opts} --require-cloud" + elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then + opts="${opts} --disable-cloud" + fi -# --------------------------------------------------------------------------------------------------------------------- -# install netdata from source + # shellcheck disable=SC2086 + run ${ROOTCMD} ./netdata-installer.sh ${opts} -install() { - progress "Installing netdata..." - run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS} case $? in 1) fatal "netdata-installer.sh exited with error" F0007 @@ -633,25 +1129,262 @@ install() { fatal "Insufficient RAM to install netdata" F0008 ;; esac - if [ -d "${ndtmpdir}" ] && [ ! "${ndtmpdir}" = "/" ]; then - run ${sudo} rm -rf "${ndtmpdir}" > /dev/null 2>&1 +} + +try_build_install() { + if ! install_local_build_dependencies; then + return 1 + fi + + set_source_archive_urls "${RELEASE_CHANNEL}" + + download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt" + download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-latest.tar.gz" + + if ! grep netdata-latest.tar.gz "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then + fatal "Tarball checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0005 + fi + + run tar -xf "${tmpdir}/netdata-latest.tar.gz" -C "${tmpdir}" + rm -rf "${tmpdir}/netdata-latest.tar.gz" > /dev/null 2>&1 + cd "$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name netdata-)" || fatal "Cannot cd to netdata source tree" F0006 + + if [ -x netdata-installer.sh ]; then + build_and_install || return 1 + else + # This case is needed because some platforms produce an extra directory on the source tarball extraction. + if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then + cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && build_and_install || return 1 + else + fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${tmpdir}" F0009 + fi fi } -if [ -x netdata-installer.sh ]; then - echo "INSTALL_TYPE='kickstart-build'" > system/.install-type - install "$@" -else - if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then - cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && install "$@" +# ====================================================================== +# Per system-type install logic + +install_on_linux() { + if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then + SELECTED_INSTALL_METHOD="native" + try_package_install + + case "$?" in + 0) + NETDATA_INSTALL_SUCCESSFUL=1 + ;; + 1) + fatal "Unable to install on this system." F0300 + ;; + 2) + if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then + fatal "Could not install native binary packages." F0301 + else + warning "Could not install native binary packages, falling back to alternative installation method." + fi + ;; + esac + fi + + if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then + SELECTED_INSTALL_METHOD="static" + INSTALL_TYPE="kickstart-static" + try_static_install + + case "$?" in + 0) + NETDATA_INSTALL_SUCCESSFUL=1 + INSTALL_PREFIX="/opt/netdata" + ;; + 1) + fatal "Unable to install on this system." F0302 + ;; + 2) + if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then + fatal "Could not install static build." F0303 + else + warning "Could not install static build, falling back to alternative installation method." + fi + ;; + esac + fi + + if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then + SELECTED_INSTALL_METHOD="build" + INSTALL_TYPE="kickstart-build" + try_build_install + + case "$?" in + 0) + NETDATA_INSTALL_SUCCESSFUL=1 + ;; + *) + fatal "Unable to install on this system." F0304 + ;; + esac + fi +} + +install_on_macos() { + if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then + fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option." F0305 + elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then + fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option." F0306 else - fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${ndtmpdir}" F0009 - exit 1 + SELECTED_INSTALL_METHOD="build" + INSTALL_TYPE="kickstart-build" + try_build_install + + case "$?" in + 0) + NETDATA_INSTALL_SUCCESSFUL=1 + ;; + *) + fatal "Unable to install on this system." F0307 + ;; + esac fi -fi +} + +install_on_freebsd() { + if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then + fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option." F0308 + elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then + fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option." F0309 + else + SELECTED_INSTALL_METHOD="build" + INSTALL_TYPE="kickstart-build" + try_build_install + + case "$?" in + 0) + NETDATA_INSTALL_SUCCESSFUL=1 + ;; + *) + fatal "Unable to install on this system." F030A + ;; + esac + fi +} + +# ====================================================================== +# Main program -# -------------------------------------------------------------------------------------------------------------------- +setup_terminal || echo > /dev/null + +while [ -n "${1}" ]; do + case "${1}" in + "--help") + usage + cleanup + trap - EXIT + exit 0 + ;; + "--no-cleanup") NO_CLEANUP=1 ;; + "--dont-wait"|"--non-interactive") INTERACTIVE=0 ;; + "--interactive") INTERACTIVE=1 ;; + "--stable-channel") RELEASE_CHANNEL="stable" ;; + "--no-updates") NETDATA_AUTO_UPDATES=0 ;; + "--auto-update") NETDATA_AUTO_UPDATES="1" ;; + "--reinstall") NETDATA_REINSTALL=1 ;; + "--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;; + "--claim-only") NETDATA_CLAIM_ONLY=1 ;; + "--disable-cloud") + NETDATA_DISABLE_CLOUD=1 + NETDATA_REQUIRE_CLOUD=0 + ;; + "--require-cloud") + NETDATA_DISABLE_CLOUD=0 + NETDATA_REQUIRE_CLOUD=1 + ;; + "--dont-start-it") + NETDATA_NO_START=1 + NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it" + ;; + "--disable-telemetry") + NETDATA_DISABLE_TELEMETRY="1" + NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry" + ;; + "--install") + INSTALL_PREFIX="${2}" + shift 1 + ;; + "--native-only") + NETDATA_ONLY_NATIVE=1 + NETDATA_ONLY_STATIC=0 + NETDATA_ONLY_BUILD=0 + SELECTED_INSTALL_METHOD="native" + ;; + "--static-only") + NETDATA_ONLY_STATIC=1 + NETDATA_ONLY_NATIVE=0 + NETDATA_ONLY_BUILD=0 + SELECTED_INSTALL_METHOD="static" + ;; + "--build-only") + NETDATA_ONLY_BUILD=1 + NETDATA_ONLY_NATIVE=0 + NETDATA_ONLY_STATIC=0 + SELECTED_INSTALL_METHOD="build" + ;; + "--claim-token") + NETDATA_CLAIM_TOKEN="${2}" + shift 1 + ;; + "--claim-rooms") + NETDATA_CLAIM_ROOMS="${2}" + shift 1 + ;; + "--claim-url") + NETDATA_CLAIM_URL="${2}" + shift 1 + ;; + "--claim-*") + optname="$(echo "${1}" | cut -d '-' -f 4-)" + case "${optname}" in + id|proxy|user|hostname) + NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname} ${2}" + shift 1 + ;; + verbose|insecure|noproxy|noreload|daemon-not-running) + NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}" + ;; + *) + warning "Ignoring unrecognized claiming option ${optname}" + ;; + esac + ;; + *) + warning "Passing unrecognized option '${1}' to installer script. If this is intended, please add it to \$NETDATA_INSTALLER_OPTIONS instead." + NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}" + ;; + esac + shift 1 +done + +check_claim_opts +confirm_root_support +get_system_info +confirm_install_prefix + +tmpdir="$(create_tmp_directory)" +progress "Using ${tmpdir} as a temporary directory." +cd "${tmpdir}" || exit 1 + +handle_existing_install + +case "${SYSTYPE}" in + Linux) install_on_linux ;; + Darwin) install_on_macos ;; + FreeBSD) install_on_freebsd ;; +esac if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then claim +elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then + soft_disable_cloud fi + +telemetry_event INSTALL_SUCCESS "" "" +cleanup +trap - EXIT diff --git a/packaging/installer/methods/alpine.md b/packaging/installer/methods/alpine.md deleted file mode 100644 index 51c4b0ccd..000000000 --- a/packaging/installer/methods/alpine.md +++ /dev/null @@ -1,40 +0,0 @@ - - -# Install Netdata on Alpine 3.x - -Execute these commands to install Netdata in Alpine Linux 3.x: - -```sh -# install required packages -apk add alpine-sdk bash curl libuv-dev zlib-dev util-linux-dev libmnl-dev gcc make git autoconf automake pkgconfig python3 logrotate - -# if you plan to run node.js Netdata plugins -apk add nodejs - -# download Netdata - the directory 'netdata' will be created -git clone https://github.com/netdata/netdata.git --depth=100 --recursive -cd netdata - -# build it, install it, start it -./netdata-installer.sh - -# make Netdata start at boot and stop at shutdown -cat > /etc/init.d/netdata << EOF -#!/sbin/openrc-run - -name="netdata" -command="/usr/sbin/$SVCNAME" - -depend() { - need net localmount - after firewall -} -EOF -``` - -If you have installed Netdata in another directory, you have to change the content of the `command` variable in that script. - -[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fpackaging%2Finstaller%2Fmethods%2Falpine&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) diff --git a/packaging/installer/methods/cloud-providers.md b/packaging/installer/methods/cloud-providers.md index 7b232f322..08c0ed9da 100644 --- a/packaging/installer/methods/cloud-providers.md +++ b/packaging/installer/methods/cloud-providers.md @@ -25,11 +25,7 @@ aims to document some of those steps for popular cloud providers. ## Recommended installation methods for cloud providers The best installation method depends on the instance's operating system, distribution, and version. For Linux instances, -we recommend either the [`kickstart.sh` automatic installation script](kickstart.md) or [.deb/.rpm -packages](packages.md). - -To see the full list of approved methods for each operating system/version we support, see our [distribution -matrix](../../DISTRIBUTIONS.md). That table will guide you to the various supported methods for your cloud instance. +we recommend the [`kickstart.sh` automatic installation script](kickstart.md). If you have issues with Netdata after installation, look to the sections below to find the issue you're experiencing, followed by the solution for your provider. diff --git a/packaging/installer/methods/kickstart-64.md b/packaging/installer/methods/kickstart-64.md deleted file mode 100644 index 176d63ad4..000000000 --- a/packaging/installer/methods/kickstart-64.md +++ /dev/null @@ -1,116 +0,0 @@ - - -# Install Netdata with kickstart-static64.sh - -![](https://registry.my-netdata.io/api/v1/badge.svg?chart=web_log_nginx.requests_per_url&options=unaligned&dimensions=kickstart64&group=sum&after=-3600&label=last+hour&units=installations&value_color=orange&precision=0) ![](https://registry.my-netdata.io/api/v1/badge.svg?chart=web_log_nginx.requests_per_url&options=unaligned&dimensions=kickstart64&group=sum&after=-86400&label=today&units=installations&precision=0) - -This page covers detailed instructions on using and configuring the installation script named `kickstart-static64.sh`. - -This method uses a pre-compiled static binary to install Netdata on any Intel/AMD 64bit Linux system and on any Linux -distribution, even those with a broken or unsupported package manager. - -To install Netdata from a static binary package, including all dependencies required to connect to Netdata Cloud, and -get _automatic nightly updates_, run the following as your normal user: - -```bash -bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh) -``` - -> This script installs Netdata at `/opt/netdata`. - -> See our [installation guide](/packaging/installer/README.md) for details about [automatic -> updates](/packaging/installer/README.md#automatic-updates) or [nightly vs. stable -> releases](/packaging/installer/README.md#nightly-vs-stable-releases). - -## What does `kickstart-static64.sh` do? - -The `kickstart.sh` script does the following after being downloaded and run: - -- Checks to see if there is an existing installation, and if there is updates that in preference to reinstalling. -- Downloads the latest Netdata binary from the [binary-packages](https://github.com/netdata/binary-packages) - repository. You can also run any of these `.run` files with [makeself](https://github.com/megastep/makeself). -- Installs Netdata by running `./netdata-installer.sh` from the source tree, including any options you might have - added. -- Installs `netdata-updater.sh` to `cron.daily` to enable automatic updates, unless you added the `--no-updates` - option. -- Prints a message about whether the installation succeeded for failed for QA purposes. - -If your shell fails to handle the above one-liner, you can download and run the `kickstart-static64.sh` script manually. - -```sh -# download the script with curl -curl https://my-netdata.io/kickstart-static64.sh >/tmp/kickstart-static64.sh - -# or, download the script with wget -wget -O /tmp/kickstart-static64.sh https://my-netdata.io/kickstart-static64.sh - -# run the downloaded script (any sh is fine, no need for bash) -sh /tmp/kickstart-static64.sh -``` - -## Optional parameters to alter your installation - -The `kickstart-static64.sh` script passes all its parameters to `netdata-installer.sh`, which you can use to customize -your installation. Here are a few important parameters: - -- `--dont-wait`: Enable automated installs by not prompting for permission to install any required packages. -- `--dont-start-it`: Prevent the installer from starting Netdata automatically. -- `--stable-channel`: Automatically update only on the release of new major versions. -- `--nightly-channel`: Automatically update on every new nightly build. -- `--disable-telemetry`: Opt-out of [anonymous statistics](/docs/anonymous-statistics.md) we use to make - Netdata better. -- `--no-updates`: Prevent automatic updates of any kind. -- `--reinstall`: If an existing installation is detected, reinstall instead of attempting to update it. Note - that this cannot be used to switch between installation types. -- `--local-files`: Used for [offline installations](/packaging/installer/methods/offline.md). Pass four file paths: - the Netdata tarball, the checksum file, the go.d plugin tarball, and the go.d plugin config tarball, to force - kickstart run the process using those files. This option conflicts with the `--stable-channel` option. If you set - this _and_ `--stable-channel`, Netdata will use the local files. - -### Connect node to Netdata Cloud during installation - -The `kickstart.sh` script accepts additional parameters to automatically [connect](/claim/README.md) your node to Netdata -Cloud immediately after installation. Find the `token` and `rooms` strings by [signing in to Netdata -Cloud](https://app.netdata.cloud/sign-in?cloudRoute=/spaces), then clicking on **Connect Nodes** in the [Spaces management -area](https://learn.netdata.cloud/docs/cloud/spaces#manage-spaces). - -- `--claim-token`: The unique token associated with your Space in Netdata Cloud. -- `--claim-rooms`: A comma-separated list of tokens for each War Room this node should appear in. -- `--claim-proxy`: Should take the form of `socks5[h]://[user:pass@]host:ip` for a SOCKS5 proxy, or - `http://[user:pass@]host:ip` for an HTTP(S) proxy.See [connecting through a - proxy](/claim/README.md#connect-through-a-proxy) for details. -- `--claim-url`: Defaults to `https://app.netdata.cloud`. - -For example: - -```bash -bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh) --claim-token=TOKEN --claim-rooms=ROOM1,ROOM2 -``` - -## Verify script integrity - -To use `md5sum` to verify the integrity of the `kickstart-static64.sh` script you will download using the one-line -command above, run the following: - -```bash -[ "78461a3055aee03011a577a716e2dee5" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID" -``` - -If the script is valid, this command will return `OK, VALID`. - -## What's next? - -When you're finished with installation, check out our [single-node](/docs/quickstart/single-node.md) or -[infrastructure](/docs/quickstart/infrastructure.md) monitoring quickstart guides based on your use case. - -Or, skip straight to [configuring the Netdata Agent](/docs/configure/nodes.md). - -Read through Netdata's [documentation](https://learn.netdata.cloud/docs), which is structured based on actions and -solutions, to enable features like health monitoring, alarm notifications, long-term metrics storage, exporting to -external databases, and more. - -[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fpackaging%2Finstaller%2Fmethods%2Fkickstart-64&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) diff --git a/packaging/installer/methods/kickstart.md b/packaging/installer/methods/kickstart.md index 7792989ee..bc7c4de95 100644 --- a/packaging/installer/methods/kickstart.md +++ b/packaging/installer/methods/kickstart.md @@ -11,62 +11,74 @@ custom_edit_url: https://github.com/netdata/netdata/edit/master/packaging/instal This page covers detailed instructions on using and configuring the automatic one-line installation script named `kickstart.sh`. -This method is fully automatic on all Linux distributions and macOS environments. To install Netdata from source, including all dependencies -required to connect to Netdata Cloud, and get _automatic nightly updates_, run the following as your normal user: +The kickstart script works on all Linux distributions and macOS environments. By default, automatic nightly updates are enabled. If you are installing on macOS, make sure to check the [install documentation for macOS](packaging/installer/methods/macos) before continuing. -**Linux** +> If you are unsure whether you want nightly or stable releases, read the [installation guide](/packaging/installer/README.md#nightly-vs-stable-releases). +> If you want to turn off [automatic updates](/packaging/installer/README.md#automatic-updates), use the `--no-updates` option. You can find more installation options below. + +To install Netdata, run the following as your normal user: ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) +wget -O ./kickstart.sh https://my-netdata.io/kickstart.sh && sh ./kickstart.sh ``` -**macOS** +Or, if you have cURL but not wget (such as on macOS): ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) --install /usr/local/ +curl https://my-netdata.io/kickstart.sh > /tmp/netdata-kickstart.sh && sh /tmp/netdata-kickstart.sh ``` -> See our [installation guide](/packaging/installer/README.md) for details about [automatic updates](/packaging/installer/README.md#automatic-updates) or -> [nightly vs. stable releases](/packaging/installer/README.md#nightly-vs-stable-releases). ## What does `kickstart.sh` do? -The `kickstart.sh` script does the following after being downloaded and run using `bash`: +The `kickstart.sh` script does the following after being downloaded and run using `sh`: -- Detects the Linux distribution and **installs the required system packages** for building Netdata. Unless you added - the `--dont-wait` option, it will ask for your permission first. -- Checks for an existing installation, and if found updates that instead of creating a new install. -- Downloads the latest Netdata source tree to `/usr/src/netdata.git`. -- Installs Netdata by running `./netdata-installer.sh` from the source tree, using any [optional - parameters](#optional-parameters-to-alter-your-installation) you have specified. -- Installs `netdata-updater.sh` to `cron.daily`, so your Netdata installation will be updated with new nightly - versions, unless you override that with an [optional parameter](#optional-parameters-to-alter-your-installation). -- Prints a message whether installation succeeded or failed for QA purposes. +- Determines what platform you are running on. +- Checks for an existing installation, and if found updates that instead of creating a new install. +- Attempts to install Netdata using our [official native binary packages](#native-packages). +- If there are no official native binary packages for your system (or installing that way failed), tries to install + using a [static build of Netdata](#static-builds) if one is available. +- If no static build is available, installs required dependencies and then attempts to install by + [building Netdata locally](#local-builds) (by downloading the sources and building them directly). +- Installs `netdata-updater.sh` to `cron.daily`, so your Netdata installation will be updated with new nightly + versions, unless you override that with an [optional parameter](#optional-parameters-to-alter-your-installation). +- Prints a message whether installation succeeded or failed for QA purposes. ## Optional parameters to alter your installation -The `kickstart.sh` script passes all its parameters to `netdata-installer.sh`, which you can use to customize your -installation. Here are a few important parameters: +The `kickstart.sh` script accepts a number of optional parameters to control how the installation process works: +- `--non-interactive`: Don’t prompt for anything and assume yes whenever possible, overriding any automatic detection of an interactive run. +- `--interactive`: Act as if running interactively, even if automatic detection indicates a run is non-interactive. - `--dont-wait`: Synonym for `--non-interactive` -- `--non-interactive`: Don’t prompt for anything and assume yes whenever possible. +- `--dont-start-it`: Don’t auto-start the daemon after installing. This parameter is not gauranteed to work. +- `--nightly-channel`: Use a nightly build instead of a stable release (this is the default). +- `--stable-channel`: Use a stable release instead of a nightly build. +- `--auto-update`: Enable automatic updates (this is the default). - `--no-updates`: Disable automatic updates. -- `--stable-channel`: Use a stable build instead of a nightly build. +- `--disable-telemetry`: Disable anonymous statistics. +- `--native-only`: Only install if native binary packages are available. +- `--static-only`: Only install if a static build is available. +- `--build-only`: Only install using a local build. - `--reinstall`: If an existing install is found, reinstall instead of trying to update it in place. -- `--dont-start-it`: Don’t auto-start the daemon after installing. This parameter is not guaranteed to work. -- `--install`: Specify an alternative install prefix. -- `--disable-cloud`: For local builds, don’t build any of the cloud code at all. For native packages and static builds, +- `--reinstall-even-if-unsafe`: Even try to reinstall if we don't think we can do so safely (implies `--reinstall`). +- `--disable-cloud`: For local builds, don’t build any of the cloud code at all. For native packages and static builds, use runtime configuration to disable cloud support. -- `--auto-update-type`: Specify how auto-updates are to be scheduled, overriding auto-detection. -- `--disable-telemetry`: Disable anonymous statistics. -- `--local-files`: Used for [offline installations](offline.md). Pass four file paths: the Netdata - tarball, the checksum file, the go.d plugin tarball, and the go.d plugin config tarball, to force kickstart run the - process using those files. This option conflicts with the `--stable-channel` option. If you set this _and_ - `--stable-channel`, Netdata will use the local files. -- `all`: Ask for all dependencies in the dependency handling script. - - > Note: The `all` and `--local-files` parameters are scheduled to be removed in a forthcoming update. - +- `--require-cloud`: Only install if Netdata Cloud can be enabled. Overrides `--disable-cloud`. +- `--install`: Specify an installation prefix for local builds (by default, we use a sane prefix based on the type of system). + +Additionally, the following environment variables may be used to further customize how the script runs (most users +should not need to use special values for any of these): + +- `TMPDIR`: Used to specify where to put temporary files. On most systems, the default we select automatically + should be fine. The user running the script needs to both be able to write files to the temporary directory, + and run files from that location. +- `ROOTCMD`: Used to specify a command to use to run another command with root privileges if needed. By default + we try to use sudo, doas, or pkexec (in that order of preference), but if you need special options for one of + those to work, or have a different tool to do the same thing on your system, you can specify it here. +- `DO_NOT_TRACK`: If set to a value other than 0, behave as if `--disable-telemetry` was specified. +- `NETDATA_INSTALLER_OPTIONS`: Specifies extra options to pass to the static installer or local build script. + ### Connect node to Netdata Cloud during installation The `kickstart.sh` script accepts additional parameters to automatically [connect](/claim/README.md) your node to Netdata @@ -74,10 +86,10 @@ Cloud immediately after installation. Find the `token` and `rooms` strings by [s Cloud](https://app.netdata.cloud/sign-in?cloudRoute=/spaces), then clicking on **Connect Nodes** in the [Spaces management area](https://learn.netdata.cloud/docs/cloud/spaces#manage-spaces). -- `--claim-token`: Specify a unique claiming token associated with your Space in Netdata Cloud to be used to connect to the node +- `--claim-token`: Specify a unique claiming token associated with your Space in Netdata Cloud to be used to connect to the node after the install. - `--claim-rooms`: Specify a comma-separated list of tokens for each War Room this node should appear in. -- `--claim-proxy`: Specify a proxy to use when connecting to the cloud in the form of +- `--claim-proxy`: Specify a proxy to use when connecting to the cloud in the form of `socks5[h]://[user:pass@]host:ip` for a SOCKS5 proxy, or `http://[user:pass@]host:ip` for an HTTP(S) proxy. See [connecting through a proxy](/claim/README.md#connect-through-a-proxy) for details. - `--claim-url`: Specify a URL to use when connecting to the cloud. Defaults to `https://app.netdata.cloud`. @@ -85,10 +97,42 @@ area](https://learn.netdata.cloud/docs/cloud/spaces#manage-spaces). For example: ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) --claim-token=TOKEN --claim-rooms=ROOM1,ROOM2 +wget -O ./kickstart.sh https://my-netdata.io/kickstart.sh && sh ./kickstart.sh --claim-token=TOKEN --claim-rooms=ROOM1,ROOM2 ``` -Please note that to run it you will either need to have root privileges or run it with the user that is running the agent, more details on the [Connect an agent without root privileges](#connect-an-agent-without-root-privileges) section. +Please note that to run it you will either need to have root privileges or run it with the user that is running the agent, more details on the [Connect an agent without root privileges](/claim/README.md#connect-an-agent-without-root-privileges) section. + +### Native packages + +We publish official DEB/RPM packages for a number of common Linux distributions as part of our releases and nightly +builds. These packages are available for 64-bit x86 systems. Depending on the distribution and release they may +also be available for 32-bit x86, ARMv7, and AArch64 systems. If a native package is available, it will be used as the +default installation method. This allows you to handle Netdata updates as part of your usual system update procedure. + +If you want to enforce the usage of native packages and have the installer return a failure if they are not available, +you can do so by adding `--native-only` to the options you pass to the installer. + +### Static builds + +We publish pre-built static builds of Netdata for Linux systems. Currently, these are published for 64-bit x86, ARMv7, +AArch64, and POWER8+ hardware. These static builds are able to operate in a mostly self-contained manner and only +require a POSIX compliant shell and a supported init system. These static builds install under `/opt/netdata`. If +you are on a platform which we provide static builds for but do not provide native packages for, a static build +will be used by default for installation. + +If you want to enforce the usage of a static build and have the installer return a failure if one is not available, +you can do so by adding `--static-only` to the options you pass to the installer. + +### Local builds + +For systems which do not have available native packages or static builds, we support building Netdata locally on +the system it will be installed on. When using this approach, the installer will attempt to install any required +dependencies for building Netdata, though this may not always work correctly. + +If you want to enforce the usage of a local build (perhaps because you require a custom installation prefix, +which is not supported with native packages or static builds), you can do so by adding `--build-only` to the +options you pass to the installer. + ## Verify script integrity @@ -96,7 +140,7 @@ To use `md5sum` to verify the integrity of the `kickstart.sh` script you will do run the following: ```bash -[ "7e8b449ca44e49b7074b5b9d6022cbcc" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID" +[ "dc50e88ee6e19f50dd395e1e5117a1fa" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID" ``` If the script is valid, this command will return `OK, VALID`. diff --git a/packaging/installer/methods/macos.md b/packaging/installer/methods/macos.md index 48d53fd08..0ae1d9f23 100644 --- a/packaging/installer/methods/macos.md +++ b/packaging/installer/methods/macos.md @@ -6,31 +6,35 @@ custom_edit_url: https://github.com/netdata/netdata/edit/master/packaging/instal # Install Netdata on macOS Netdata works on macOS, albeit with some limitations. The number of charts displaying system metrics is limited, but you -can use any of Netdata's [external plugins](../../../collectors/plugins.d/README.md) to monitor any services you might +can use any of Netdata's [external plugins](/collectors/plugins.d/README.md) to monitor any services you might have installed on your macOS system. You could also use a macOS system as the parent node in a [streaming configuration](/streaming/README.md). -We recommend you to **[install Netdata with the our automatic one-line installation script](#install-netdata-with-the-automatic-one-line-installation-script)**, +We recommend you to **[install Netdata with the our automatic one-line installation script](#install-netdata-with-our-automatic-one-line-installation-script)**, As an alternative you also have community-created and -maintained [**Homebrew package**](#install-netdata-with-the-homebrew-package). -- [Install Netdata via the Homebrew package](#install-netdata-with-the-homebrew-package) -- [Install Netdata from source](#install-netdata-from-source) +- [Install Netdata via the Homebrew package](#install-netdata-with-the-homebrew-package) +- [Install Netdata from source](#install-netdata-from-source) Being community-created and -maintained we don't guarantee that the features made available on our installation script will also be available or give support to it. ## Install Netdata with our automatic one-line installation script -To install Netdata using our automatic [kickstart](/packaging/installer/#automatic-one-line-installation-script) script you will just need to run: +To install Netdata using our automatic [kickstart](/packaging/installer/README.md#automatic-one-line-installation-script) script you will just need to run: ```bash -bash <(curl -Ss https://my-netdata.io/kickstart.sh) --install /usr/local/ +wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh ``` With this script, you are also able to connect your nodes directly to Netdata Cloud if you wish, see more details on [Connect an agent running in macOS](/claim/README.md#connect-an-agent-running-in-macos) +This currently only supports building Netdata locally, and requires dependencies to be handled either via Homebrew +or MacPorts (we preferentially use Homebrew if both are found). By default, this will install Netdata under +`/usr/local/netdata`. + ## Install Netdata with the Homebrew package If you don't have [Homebrew](https://brew.sh/) installed already, begin with their installation script: diff --git a/packaging/installer/methods/manual.md b/packaging/installer/methods/manual.md index ae96dd954..73cedd24d 100644 --- a/packaging/installer/methods/manual.md +++ b/packaging/installer/methods/manual.md @@ -67,16 +67,16 @@ This is how to do it by hand: ```sh # Debian / Ubuntu -apt-get install zlib1g-dev uuid-dev libuv1-dev liblz4-dev libjudy-dev libssl-dev libelf-dev libmnl-dev gcc make git autoconf autoconf-archive autogen automake pkg-config curl python cmake +apt-get install zlib1g-dev uuid-dev libuv1-dev liblz4-dev libjudy-dev libssl-dev libelf-dev libmnl-dev libprotobuf-dev protobuf-compiler gcc g++ make git autoconf autoconf-archive autogen automake pkg-config curl python cmake # Fedora -dnf install zlib-devel libuuid-devel libuv-devel lz4-devel Judy-devel openssl-devel elfutils-libelf-devel libmnl-devel gcc make git autoconf autoconf-archive autogen automake pkgconfig curl findutils python cmake +dnf install zlib-devel libuuid-devel libuv-devel lz4-devel Judy-devel openssl-devel elfutils-libelf-devel libmnl-devel protobuf-devel protobuf-compiler gcc gcc-c++ make git autoconf autoconf-archive autogen automake pkgconfig curl findutils python cmake # CentOS / Red Hat Enterprise Linux -yum install autoconf automake curl gcc git libmnl-devel libuuid-devel openssl-devel libuv-devel lz4-devel Judy-devel elfutils-libelf-devel make nc pkgconfig python zlib-devel cmake +yum install autoconf automake curl gcc gcc-c++ git libmnl-devel libuuid-devel openssl-devel libuv-devel lz4-devel Judy-devel elfutils-libelf-devel protobuf protobuf-devel protobuf-compiler make nc pkgconfig python zlib-devel cmake # openSUSE -zypper install zlib-devel libuuid-devel libuv-devel liblz4-devel judy-devel libopenssl-devel libelf-devel libmnl-devel gcc make git autoconf autoconf-archive autogen automake pkgconfig curl findutils python cmake +zypper install zlib-devel libuuid-devel libuv-devel liblz4-devel judy-devel libopenssl-devel libelf-devel libmnl-devel protobuf-devel gcc gcc-c++ make git autoconf autoconf-archive autogen automake pkgconfig curl findutils python cmake ``` Once Netdata is compiled, to run it the following packages are required (already installed using the above commands): @@ -124,10 +124,11 @@ Netdata DB engine can be enabled when these are installed (they are optional): Netdata Cloud support may require the following packages to be installed: -| package | description -|:--------:| ----------------------- -| `cmake` | Needed at build time if you aren't using your distribution's version of libwebsockets or are building on a platform other than Linux -| `openssl` | Needed to secure communications with the Netdata Cloud +| package | description | +|:---------:|--------------------------------------------------------------------------------------------------------------------------------------| +| `cmake` | Needed at build time if you aren't using your distribution's version of libwebsockets or are building on a platform other than Linux | +| `openssl` | Needed to secure communications with the Netdata Cloud | +| `protobuf`| Used for the new Cloud<->Agent binary protocol *Netdata will greatly benefit if you have the above packages installed, but it will still work without them.* diff --git a/packaging/installer/methods/packages.md b/packaging/installer/methods/packages.md deleted file mode 100644 index 20dbaf060..000000000 --- a/packaging/installer/methods/packages.md +++ /dev/null @@ -1,46 +0,0 @@ - - -# Install Netdata with .deb/.rpm packages - -Netdata provides our own flavour of binary packages for the most common operating systems that use with `.deb` and -`.rpm` packaging formats. - -We provide two separate repositories, one for our stable releases and one for our nightly releases. Visit the repository -pages and follow the quick set-up instructions to get started. - -1. Stable releases: Our stable production releases are hosted in the - [netdata/netdata](https://packagecloud.io/netdata/netdata) repository on packagecloud -2. Nightly releases: Our latest releases are hosted in the - [netdata/netdata-edge](https://packagecloud.io/netdata/netdata-edge) repository on packagecloud - -## Using caching proxies with packagecloud repositories - -packagecloud only provides HTTPS access to repositories they host, which means in turn that Netdata's package -repositories are only accessible via HTTPS. This is known to cause issues with some setups that use a caching proxy for -package downloads. - -If you are using such a setup, there are a couple of ways to work around this: - -- Configure your proxy to automatically pass through HTTPS connections without caching them. This is the simplest - solution, but means that downloads of Netdata packages will not be cached. -- Mirror the repository locally on your proxy system, and use that mirror when installing on other systems. This - requires more setup and more disk space on the caching host, but it lets you cache the packages locally. -- Some specific caching proxies may have alternative configuration options to deal with these issues. Find - such options in their documentation. - -## What's next? - -When you're finished with installation, check out our [single-node](/docs/quickstart/single-node.md) or -[infrastructure](/docs/quickstart/infrastructure.md) monitoring quickstart guides based on your use case. - -Or, skip straight to [configuring the Netdata Agent](/docs/configure/nodes.md). - -Read through Netdata's [documentation](https://learn.netdata.cloud/docs), which is structured based on actions and -solutions, to enable features like health monitoring, alarm notifications, long-term metrics storage, exporting to -external databases, and more. - -[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fpackages%2Finstaller%2Fmethods%2Fpackages&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]() diff --git a/packaging/installer/methods/source.md b/packaging/installer/methods/source.md index ba29a188d..5345a1a4c 100644 --- a/packaging/installer/methods/source.md +++ b/packaging/installer/methods/source.md @@ -38,6 +38,7 @@ Additionally, the following build time features require additional dependencies: - A recent version of CMake - OpenSSL 1.0.2 or newer _or_ LibreSSL 3.0.0 or newer. - JSON-C (may be provided by the user as shown below, or by the system) + - protobuf (Google Protocol Buffers) and protoc compiler ## Preparing the source tree diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index be98079c8..964710058 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -38,6 +38,14 @@ else script_source="${script_dir}/netdata-updater.sh" fi +PATH="${PATH}:/usr/local/bin:/usr/local/sbin" + +if [ ! -t 1 ]; then + INTERACTIVE=0 +else + INTERACTIVE=1 +fi + info() { echo >&3 "$(date) : INFO: " "${@}" } @@ -60,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 @@ -181,10 +193,6 @@ get_netdata_latest_tag() { fatal "I need curl or wget to proceed, but neither of them are available on this system." fi - if echo "${tag}" | grep -vEq "^v[0-9]+\..+"; then - fatal "Cannot download latest stable tag from ${url}" - fi - echo "${tag}" >"${dest}" } @@ -261,6 +269,40 @@ get_latest_version() { fi } +update_available() { + basepath="$(dirname "$(dirname "$(dirname "${NETDATA_LIB_DIR}")")")" + searchpath="${basepath}/bin:${basepath}/sbin:${basepath}/usr/bin:${basepath}/usr/sbin:${PATH}" + searchpath="${basepath}/netdata/bin:${basepath}/netdata/sbin:${basepath}/netdata/usr/bin:${basepath}/netdata/usr/sbin:${searchpath}" + ndbinary="$(PATH="${searchpath}" command -v netdata 2>/dev/null)" + + if [ -z "${ndbinary}" ]; then + current_version=0 + else + current_version="$(parse_version "$(${ndbinary} -v | cut -f 2 -d ' ')")" + fi + + latest_tag="$(get_latest_version)" + latest_version="$(parse_version "${latest_tag}")" + path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")" + + # If we can't get the current version for some reason assume `0` + current_version="${current_version:-0}" + + # If we can't get the latest version for some reason assume `0` + latest_version="${latest_version:-0}" + + info "Current Version: ${current_version}" + info "Latest Version: ${latest_version}" + + if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then + info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed" + return 1 + else + info "Update available" + return 0 + fi +} + set_tarball_urls() { extension="tar.gz" @@ -270,7 +312,7 @@ set_tarball_urls() { if [ "$1" = "stable" ]; then latest="$(get_netdata_latest_tag /dev/stdout)" - export NETDATA_TARBALL_URL="https://github.com/netdata/netdata/releases/download/$latest/netdata-$latest.${extension}" + 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="$NETDATA_NIGHTLIES_BASEURL/netdata-latest.${extension}" @@ -278,44 +320,28 @@ 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 ndtmpdir=$(create_tmp_directory) cd "$ndtmpdir" || exit 1 - download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" >&3 2>&3 - - current_version="$(command -v netdata > /dev/null && parse_version "$(netdata -v | cut -f 2 -d ' ')")" - latest_tag="$(get_latest_version)" - latest_version="$(parse_version "${latest_tag}")" - path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")" - - # If we can't get the current version for some reason assume `0` - current_version="${current_version:-0}" - - # If we can't get the latest version for some reason assume `0` - latest_version="${latest_version:-0}" - - info "Current Version: ${current_version}" - info "Latest Version: ${latest_version}" - - if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then - info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed" - elif [ -n "${NETDATA_TARBALL_CHECKSUM}" ] && grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then - info "Newest version is already installed" - else + if update_available; then + download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" >&3 2>&3 download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.tar.gz" - if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then - fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour." + if [ -n "${NETDATA_TARBALL_CHECKSUM}" ] && grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then + info "Newest version is already installed" + else + if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then + fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour." + fi + NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)" + tar -xf netdata-latest.tar.gz >&3 2>&3 + rm netdata-latest.tar.gz >&3 2>&3 + cd "$(find . -maxdepth 1 -name "netdata-${path_version}*" | head -n 1)" || exit 1 + RUN_INSTALLER=1 fi - NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)" - tar -xf netdata-latest.tar.gz >&3 2>&3 - rm netdata-latest.tar.gz >&3 2>&3 - cd "$(find . -maxdepth 1 -name "netdata-${path_version}*" | head -n 1)" || exit 1 - RUN_INSTALLER=1 - cd "${NETDATA_LOCAL_TARBALL_OVERRIDE}" || exit 1 fi # We got the sources, run the update now @@ -325,7 +351,8 @@ update() { possible_pids=$(pidof netdata) do_not_start= if [ -n "${possible_pids}" ]; then - kill -USR1 "${possible_pids}" + # shellcheck disable=SC2086 + kill -USR1 ${possible_pids} else # netdata is currently not running, so do not start it after updating do_not_start="--dont-start-it" @@ -367,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-${sysarch}-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= @@ -402,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}" @@ -429,44 +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 - - 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 - - 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 -- cgit v1.2.3