diff options
Diffstat (limited to 'packaging/installer')
28 files changed, 1188 insertions, 385 deletions
diff --git a/packaging/installer/README.md b/packaging/installer/README.md index f2f826ed..2854d072 100644 --- a/packaging/installer/README.md +++ b/packaging/installer/README.md @@ -188,26 +188,21 @@ visit the Agent dashboard at `http://NODE:19999`, you need to update Netdata's p system. Run `ls -la /usr/share/netdata/web/index.html` to find the file's permissions. You may need to change this path based on -the error you're seeing in your browser. In the below example, the file is owned by the user `netdata` and the group -`netdata`. +the error you're seeing in your browser. In the below example, the file is owned by the user `root` and the group +`root`. ```bash ls -la /usr/share/netdata/web/index.html --rw-r--r--. 1 netdata netdata 89377 May 5 06:30 /usr/share/netdata/web/index.html +-rw-r--r--. 1 root root 89377 May 5 06:30 /usr/share/netdata/web/index.html ``` -Open your `netdata.conf` file and find the `[web]` section, plus the `web files owner`/`web files group` settings. Edit -the lines to match the output from `ls -la` above and uncomment them if necessary. +These files need to have the same user and group used to install your netdata. Suppose you installed netdata with user +`netdata` and group `netdata`, in this scenario you will need to run the following command to fix the error: -```conf -[web] - web files owner = netdata - web files group = netdata +```bash +# chown -R netdata.netdata /usr/share/netdata/web ``` -Save the file, restart Netdata using `sudo systemctl restart netdata`, or the [appropriate -method](/docs/configure/start-stop-restart.md) for your system, and try accessing the dashboard again. - ### Multiple versions of OpenSSL We've received reports from the community about issues with running the `kickstart.sh` script on systems that have both @@ -220,4 +215,4 @@ Our current build process has some issues when using certain configurations of t section on `nonrepresentable section on output` errors](/packaging/installer/methods/manual.md#nonrepresentable-section-on-output-errors) for a workaround. -[![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%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/REINSTALL.md b/packaging/installer/REINSTALL.md index 1398551d..ddfc8bcb 100644 --- a/packaging/installer/REINSTALL.md +++ b/packaging/installer/REINSTALL.md @@ -33,4 +33,4 @@ installer](/packaging/installer/methods/kickstart.md). You can also post to our [community forums](https://community.netdata.cloud/c/support/13) or create a new [bug report](https://github.com/netdata/netdata/issues/new?assignees=&labels=bug%2Cneeds+triage&template=BUG_REPORT.yml). -[![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%2Finstaller%2FREINSTALL&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/UNINSTALL.md b/packaging/installer/UNINSTALL.md index c18a1bfc..87c76ca6 100644 --- a/packaging/installer/UNINSTALL.md +++ b/packaging/installer/UNINSTALL.md @@ -51,4 +51,4 @@ The default `environment_file` is `/etc/netdata/.environment`. > Note: This uninstallation method assumes previous installation with `netdata-installer.sh` or the kickstart script. > Currently using it when Netdata was installed by a package manager can work or cause unexpected results. -[![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%2Finstaller%2FUNINSTALL&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/UPDATE.md b/packaging/installer/UPDATE.md index 8230d00c..009e970f 100644 --- a/packaging/installer/UPDATE.md +++ b/packaging/installer/UPDATE.md @@ -6,8 +6,9 @@ custom_edit_url: https://github.com/netdata/netdata/edit/master/packaging/instal # Update the Netdata Agent -By default, the Netdata Agent automatically updates with the latest nightly version. If you opted out of automatic -updates, you need to update your Netdata Agent to the latest nightly or stable version. +By default, the Netdata Agent automatically updates with the latest nightly or stable version depending on which +you installed. If you opted out of automatic updates, you need to update your Netdata Agent to the latest nightly +or stable version. You can also [enable or disable automatic updates on an existing install](#control-automatic-updates). > 💡 Looking to reinstall the Netdata Agent to enable a feature, update an Agent that cannot update automatically, or > troubleshoot an error during the installation process? See our [reinstallation doc](/packaging/installer/REINSTALL.md) @@ -16,32 +17,43 @@ updates, you need to update your Netdata Agent to the latest nightly or stable v Before you update the Netdata Agent, check to see if your Netdata Agent is already up-to-date by clicking on the update icon in the local Agent dashboard's top navigation. This modal informs you whether your Agent needs an update or not. -![Opening the Agent's Update modal](https://user-images.githubusercontent.com/1153921/99738428-add06780-2a87-11eb-8268-0e17b689eb3f.gif) +The exact update method to use depends on the install type: + +- Installs with an install type of 'custom' usually indicate installing a third-party package through the system + package manager. To update these installs, you should update the package just like you would any other package + on your system. +- Installs with an install type starting with `binpkg` or ending with `build` or `static` can be updated using + our [regular update method](#updates-for-most-systems). +- Installs with an install type of 'oci' were created from our official Docker images, and should be updated + using our [Docker](#docker) update procedure. +- macOS users should check [our update instructions for macOS](#macos). +- Manually built installs should check [our update instructions for manual builds](#manual-installation-from-git). ## Determine which installation method you used -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`. +Starting with netdata v1.33.0, you can use Netdata itself to determine the installation type by running: + +```bash +netdata -W buildinfo | grep 'Install type:' +``` + +If you are using an older version of Netdata, or the above command produces no output, you can run our one-line +installation script in dry-run mode to attempt to determine what method to use to update by running the following +command: -Use `cd` to navigate to the Netdata config directory, then use `ls -a` to look for a file called `.install-type`. +```bash +wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh --dry-run +``` -- 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). +Note that if you installed Netdata using an installation prefix, you will need to add an `--install` option +specifying that prefix to make sure it finds the existing install. -Next, use the appropriate method to update the Netdata Agent: +If you see a line starting with `--- Would attempt to update existing installation by running the updater script +located at:`, then our [regular update method](#updates-for-most-systems) will work for you. -- [Updates for most systems](#updates-for-most-systems) -- [Docker](#docker) -- [macOS](#macos) -- [Manual installation from Git](#manual-installation-from-git) +Otherwise, it should either indicate that the installation type is not supported (which probably means you either +have a `custom` instal or built Netdata manually) or indicate that it would create a new install (which means that +you either used a non-standard install path, or that you don’t actually have Netdata installed). ## Updates for most systems @@ -56,9 +68,21 @@ that prefix to this command to make sure it finds Netdata. 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. +### Issues with older binpkg installs + +The above command is known not to work with binpkg type installs for stable releases with a version number of +v1.33.1 or earlier, and nightly builds with a version number of v1.33.1-93 or earlier. If you have such a system, +the above command will report that it found an existing install, and then issue a warning about not being able to +find the updater script. + +On such installs, you can update Netdata using your distribution package manager. + +### If the kickstart script does not work + +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 just like updating +normally would, though you will need to specify any installation options you used originally again. ## Docker @@ -95,6 +119,9 @@ Homebrew downloads the latest Netdata via the [formulae](https://github.com/Homebrew/homebrew-core/blob/master/Formula/netdata.rb), ensures all dependencies are met, and updates Netdata via reinstallation. +If you instead installed Netdata using our one-line installation script, you can use our [regular update +instructions](#updates-for-most-systems) to update Netdata. + ## Manual installation from Git If you installed [Netdata manually from Git](/packaging/installer/methods/manual.md), you can run that installer again @@ -117,4 +144,31 @@ sudo ./netdata-installer.sh > ⚠️ If you installed Netdata with any optional parameters, such as `--no-updates` to disable automatic updates, and > want to retain those settings, you need to set them again during this process. -[![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%2Finstaller%2FUPDATE&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) +## Control automatic updates + +Starting with Netdata v1.34.0, you can easily enable or disable automatic updates on an existing installation +using the updater script. + +For most installs on Linux, you can enable auto-updates with: + +```bash +/usr/libexec/netdata/netdata-updater.sh --enable-auto-updates +``` + +and disable them with: + +```bash +/usr/libexec/netdata/netdata-updater.sh --disable-auto-updates +``` + +For static installs, instead use: + +```bash +/opt/netdata/usr/libexec/netdata/netdata-updater.sh --enable-auto-updates +``` + +and: + +```bash +/opt/netdata/usr/libexec/netdata/netdata-updater.sh --disable-auto-updates +``` diff --git a/packaging/installer/dependencies/alpine.sh b/packaging/installer/dependencies/alpine.sh index 8cbd98ad..cc3908d2 100755 --- a/packaging/installer/dependencies/alpine.sh +++ b/packaging/installer/dependencies/alpine.sh @@ -16,6 +16,7 @@ package_tree=" autoconf cmake make + libatomic libtool pkgconfig tar diff --git a/packaging/installer/dependencies/centos.sh b/packaging/installer/dependencies/centos.sh index d1791166..738a0ce7 100755 --- a/packaging/installer/dependencies/centos.sh +++ b/packaging/installer/dependencies/centos.sh @@ -12,6 +12,7 @@ declare -a package_tree=( autoconf-archive autogen automake + libatomic libtool pkgconfig cmake @@ -36,7 +37,7 @@ os_version() { # shellcheck disable=SC2002 cat /etc/os-release | grep VERSION_ID | cut -d'=' -f2 | cut -d'"' -f2 else - echo "Erorr: Cannot determine OS version!" + echo "Error: Cannot determine OS version!" exit 1 fi } diff --git a/packaging/installer/dependencies/debian.sh b/packaging/installer/dependencies/debian.sh index 66a4b682..e8c2d0c6 100755 --- a/packaging/installer/dependencies/debian.sh +++ b/packaging/installer/dependencies/debian.sh @@ -17,6 +17,7 @@ package_tree=" autoconf autoconf-archive autogen + libatomic1 libtool pkg-config tar diff --git a/packaging/installer/dependencies/fedora.sh b/packaging/installer/dependencies/fedora.sh index edb695bc..62a129f4 100755 --- a/packaging/installer/dependencies/fedora.sh +++ b/packaging/installer/dependencies/fedora.sh @@ -12,7 +12,7 @@ os_version() { # shellcheck disable=SC2002 cat /etc/os-release | grep VERSION_ID | cut -d'=' -f2 else - echo "Erorr: Cannot determine OS version!" + echo "Error: Cannot determine OS version!" exit 1 fi } @@ -32,6 +32,7 @@ declare -a package_tree=( autoconf-archive autogen automake + libatomic libtool cmake nmap-ncat diff --git a/packaging/installer/dependencies/ol.sh b/packaging/installer/dependencies/ol.sh index 4b95722a..8d0feb3f 100755 --- a/packaging/installer/dependencies/ol.sh +++ b/packaging/installer/dependencies/ol.sh @@ -15,6 +15,7 @@ declare -a package_tree=( autoconf-archive autogen automake + libatomic libtool pkgconfig cmake diff --git a/packaging/installer/dependencies/opensuse.sh b/packaging/installer/dependencies/opensuse.sh index cfaaf675..7c5b840e 100755 --- a/packaging/installer/dependencies/opensuse.sh +++ b/packaging/installer/dependencies/opensuse.sh @@ -17,6 +17,7 @@ declare -a package_tree=( autoconf-archive autogen automake + libatomic1 libtool pkg-config cmake diff --git a/packaging/installer/dependencies/rockylinux.sh b/packaging/installer/dependencies/rockylinux.sh index 1cf07fc5..92050a45 100755 --- a/packaging/installer/dependencies/rockylinux.sh +++ b/packaging/installer/dependencies/rockylinux.sh @@ -15,6 +15,7 @@ declare -a package_tree=( autoconf-archive autogen automake + libatomic libtool pkgconfig cmake diff --git a/packaging/installer/dependencies/ubuntu.sh b/packaging/installer/dependencies/ubuntu.sh index 3d0bb595..2bf116a1 100755 --- a/packaging/installer/dependencies/ubuntu.sh +++ b/packaging/installer/dependencies/ubuntu.sh @@ -17,6 +17,7 @@ package_tree=" autoconf autoconf-archive autogen + libatomic1 libtool pkg-config tar diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index 56f1a565..471e6457 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -632,7 +632,7 @@ stop_all_netdata() { fi fi - if [ -n "$(netdata_pids)" ] && [ -n "$(type netdatacli)" ]; then + if [ -n "$(netdata_pids)" ] && [ -n "$(command -v netdatacli)" ]; then netdatacli shutdown-agent sleep 20 fi @@ -667,7 +667,7 @@ restart_netdata() { # shellcheck disable=SC2086 run ${NETDATA_INSTALLER_START_CMD} && started=1 - if [ ${started} -eq 1 ] && [ -z "$(netdata_pids)" ]; then + if [ ${started} -eq 1 ] && sleep 5 && [ -z "$(netdata_pids)" ]; then echo >&2 "Ooops! it seems netdata is not started." started=0 fi @@ -677,13 +677,14 @@ restart_netdata() { # shellcheck disable=SC2086 run ${NETDATA_INSTALLER_START_CMD} && started=1 fi - fi - if [ ${started} -eq 1 ] && [ -z "$(netdata_pids)" ]; then - echo >&2 "Hm... it seems netdata is still not started." - started=0 + if [ ${started} -eq 1 ] && sleep 5 && [ -z "$(netdata_pids)" ]; then + echo >&2 "Hm... it seems netdata is still not started." + started=0 + fi fi + if [ ${started} -eq 0 ]; then # still not started... another forced attempt, just run the binary echo >&2 "Netdata service still not started, attempting another forced restart by running '${netdata} ${*}'" @@ -968,76 +969,6 @@ cleanup_old_netdata_updater() { return 0 } -enable_netdata_updater() { - - if [ -n "${1}" ] ; then - updater_type="${1}" - else - updater_type="$(_get_scheduler_type)" - fi - - case "${updater_type}" in - "systemd") - systemctl enable netdata-updater.timer - - echo >&2 "Auto-updating has been enabled using a systemd timer unit." - echo >&2 - echo >&2 "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure." - echo >&2 "Successful updates should produce empty logs." - echo >&2 - ;; - "interval") - ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_intervaldir)/netdata-updater" - - echo >&2 "Auto-updating has been enabled through cron, updater script linked to ${TPUT_RED}${TPUT_BOLD}$(_get_intervaldir)/netdata-updater${TPUT_RESET}" - echo >&2 - echo >&2 "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure." - echo >&2 "Successful updates will not send an email." - echo >&2 - ;; - "crontab") - cat "${NETDATA_SOURCE_DIR}/system/netdata.crontab" > "/etc/cron.d/netdata-updater" - - echo >&2 "Auto-updating has been enabled through cron, using a crontab at ${TPUT_RED}${TPUT_BOLD}/etc/cron.d/netdata-updater${TPUT_RESET}" - echo >&2 - echo >&2 "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure." - echo >&2 "Successful updates will not send an email." - echo >&2 - ;; - *) - echo >&2 "Unable to determine what type of auto-update scheduling to use, not enabling auto-updates." - echo >&2 - return 1 - esac - - return 0 -} - -disable_netdata_updater() { - echo >&2 "You chose *NOT* to enable auto-update, removing any links to the updater from cron (it may have happened if you are reinstalling)" - echo >&2 - - if issystemd && [ -n "$(get_systemd_service_dir)" ] ; then - systemctl disable netdata-updater.timer - fi - - if [ -d /etc/cron.daily ]; then - rm -f /etc/cron.daily/netdata-updater.sh - rm -f /etc/cron.daily/netdata-updater - fi - - if [ -d /etc/periodic/daily ]; then - rm -f /etc/periodic/daily/netdata-updater.sh - rm -f /etc/periodic/daily/netdata-updater - fi - - if [ -d /etc/cron.d ]; then - rm -f /etc/cron.d/netdata-updater - fi - - return 0 -} - set_netdata_updater_channel() { sed -i -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" "${NETDATA_USER_CONFIG_DIR}/.environment" } diff --git a/packaging/installer/install-required-packages.sh b/packaging/installer/install-required-packages.sh index 52fdc348..7bfbeaaf 100755 --- a/packaging/installer/install-required-packages.sh +++ b/packaging/installer/install-required-packages.sh @@ -198,7 +198,7 @@ get_os_release() { eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" "${os_release_file}")" for x in "${ID}" ${ID_LIKE}; do case "${x,,}" in - alpine | arch | centos | clear-linux-os | debian | fedora | gentoo | manjaro | opensuse-leap | ol | rhel | rocky | sabayon | sles | suse | ubuntu) + almalinux | alpine | arch | centos | clear-linux-os | debian | fedora | gentoo | manjaro | opensuse-leap | ol | rhel | rocky | sabayon | sles | suse | ubuntu) distribution="${x}" version="${VERSION_ID}" codename="${VERSION}" @@ -419,12 +419,12 @@ detect_package_manager_from_distribution() { fi ;; - centos* | clearos* | rocky*) + centos* | clearos* | rocky* | almalinux*) package_installer="" tree="centos" - [ -n "${dnf}" ] && package_installer="install_dnf" [ -n "${yum}" ] && package_installer="install_yum" - if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${yum}" ]; then + [ -n "${dnf}" ] && package_installer="install_dnf" + if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${package_installer}" ]; then echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system." exit 1 fi @@ -433,8 +433,8 @@ detect_package_manager_from_distribution() { fedora* | redhat* | red\ hat* | rhel*) package_installer= tree="rhel" - [ -n "${dnf}" ] && package_installer="install_dnf" [ -n "${yum}" ] && package_installer="install_yum" + [ -n "${dnf}" ] && package_installer="install_dnf" if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${package_installer}" ]; then echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system." exit 1 @@ -444,8 +444,8 @@ detect_package_manager_from_distribution() { ol*) package_installer= tree="ol" - [ -n "${dnf}" ] && package_installer="install_dnf" [ -n "${yum}" ] && package_installer="install_yum" + [ -n "${dnf}" ] && package_installer="install_dnf" if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${package_installer}" ]; then echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system." exit 1 @@ -699,6 +699,19 @@ declare -A pkg_json_c_dev=( ['default']="json-c-devel" ) +declare -A pkg_libatomic=( + ['arch']="NOTREQUIRED" + ['clearlinux']="NOTREQUIRED" + ['debian']="libatomic1" + ['freebsd']="NOTREQUIRED" + ['gentoo']="NOTREQUIRED" + ['macos']="NOTREQUIRED" + ['sabayon']="NOTREQUIRED" + ['suse']="libatomic1" + ['ubuntu']="libatomic1" + ['default']="libatomic" +) + declare -A pkg_bridge_utils=( ['gentoo']="net-misc/bridge-utils" ['clearlinux']="network-basic" @@ -1339,6 +1352,7 @@ packages() { # basic build environment suitable_package distro-sdk + suitable_package libatomic require_cmd git || suitable_package git require_cmd find || suitable_package find diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh index 3f119740..ffc95155 100755 --- a/packaging/installer/kickstart.sh +++ b/packaging/installer/kickstart.sh @@ -5,9 +5,16 @@ # ====================================================================== # Constants +AGENT_BUG_REPORT_URL="https://github.com/netdata/netdata/issues/new/choose" +CLOUD_BUG_REPORT_URL="https://github.com/netdata/netdata-cloud/issues/new/choose" +DISCUSSIONS_URL="https://github.com/netdata/netdata/discussions" +DISCORD_INVITE="https://discord.gg/5ygS846fR6" +DOCS_URL="https://learn.netdata.cloud/docs/" +FORUM_URL="https://community.netdata.cloud/" 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" +PUBLIC_CLOUD_URL="https://app.netdata.cloud" REPOCONFIG_URL_PREFIX="https://packagecloud.io/netdata/netdata-repoconfig/packages" REPOCONFIG_VERSION="1-1" TELEMETRY_URL="https://posthog.netdata.cloud/capture/" @@ -16,20 +23,29 @@ START_TIME="$(date +%s)" # ====================================================================== # Defaults for environment variables +DRY_RUN=0 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_CLAIM_URL="${PUBLIC_CLOUD_URL}" NETDATA_DISABLE_CLOUD=0 NETDATA_ONLY_BUILD=0 NETDATA_ONLY_NATIVE=0 NETDATA_ONLY_STATIC=0 NETDATA_REQUIRE_CLOUD=1 RELEASE_CHANNEL="nightly" +WARNINGS="" + +if [ -n "$DISABLE_TELEMETRY" ]; then + NETDATA_DISABLE_TELEMETRY="${DISABLE_TELEMETRY}" +elif [ -n "$DO_NOT_TRACK" ]; then + NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK}" +else + NETDATA_DISABLE_TELEMETRY=0 +fi -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}" @@ -44,6 +60,56 @@ else INTERACTIVE=1 fi +main() { + if [ "${ACTION}" = "uninstall" ]; then + uninstall + printf >&2 "Finished uninstalling the Netdata Agent." + deferred_warnings + cleanup + trap - EXIT + exit 0 + fi + + if [ "${ACTION}" = "reinstall-clean" ]; then + NEW_INSTALL_PREFIX="${INSTALL_PREFIX}" + uninstall + cleanup + + ACTION= + INSTALL_PREFIX="${NEW_INSTALL_PREFIX}" + # shellcheck disable=SC2086 + main + + trap - EXIT + exit 0 + fi + + tmpdir="$(create_tmp_directory)" + progress "Using ${tmpdir} as a temporary directory." + cd "${tmpdir}" || fatal "Failed to change current working directory to ${tmpdir}." F000A + + 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 + + set_auto_updates + + printf >&2 "%s\n\n" "Successfully installed the Netdata Agent." + deferred_warnings + success_banner + telemetry_event INSTALL_SUCCESS "" "" + cleanup + trap - EXIT +} + # ====================================================================== # Usage info @@ -55,10 +121,12 @@ USAGE: kickstart.sh [options] --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) + --dry-run Report what we would do with the given options on this system, but don’t actually do anything. --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) + --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method) --auto-update Enable automatic updates. + --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab) --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. @@ -68,11 +136,14 @@ USAGE: kickstart.sh [options] --disable-cloud Disable support for Netdata Cloud (default: detect) --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud. --install <path> Specify an installation prefix for local builds (default: autodetect based on system type). + --old-install-prefix <path> Specify an old local builds installation prefix for uninstall/reinstall (if it's not default). --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. + --uninstall Uninstall an existing installation of Netdata. + --reinstall-clean Clean reinstall Netdata. Additionally, this script may use the following environment variables: @@ -83,7 +154,7 @@ Additionally, this script may use the following environment variables: 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. + DISABLE_TELEMETRY 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 @@ -93,7 +164,7 @@ HEREDOC # Telemetry functions telemetry_event() { - if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then + if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ] || [ "${DRY_RUN}" -eq 1 ]; then return 0 fi @@ -130,7 +201,7 @@ telemetry_event() { if [ -f /etc/machine-id ]; then DISTINCT_ID="$(cat /etc/machine-id)" elif command -v uuidgen > /dev/null 2>&1; then - DISTINCT_ID="$(uuidgen)" + DISTINCT_ID="$(uuidgen | tr '[:upper:]' '[:lower:]')" else DISTINCT_ID="null" fi @@ -185,8 +256,21 @@ trap_handler() { code="${1}" lineno="${2}" + deferred_warnings + printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})" + case "${code}" in + 0) + printf >&2 "%s\n" "This is almost certainly the result of a bug. If you have time, please report it at ${AGENT_BUG_REPORT_URL}." + ;; + *) + printf >&2 "%s\n" "This is probably a result of a transient issue on your system. Things should work correctly if you try again." + printf >&2 "%s\n" "If you continue to experience this issue, you can reacn out to us for support on:" + support_list + ;; + esac + telemetry_event INSTALL_CRASH "Installer exited unexpectedly (${code}-${lineno})" "E${code}-${lineno}" trap - EXIT @@ -234,38 +318,58 @@ setup_terminal() { return 0 } +support_list() { + printf >&2 "%s\n" " - GitHub: ${DISCUSSIONS_URL}" + printf >&2 "%s\n" " - Discord: ${DISCORD_INVITE}" + printf >&2 "%s\n" " - Our community forums: ${FORUM_URL}" +} + +success_banner() { + printf >&2 "%s\n\n" "Official documentation can be found online at ${DOCS_URL}." + + if [ -z "${CLAIM_TOKEN}" ]; then + printf >&2 "%s\n\n" "Looking to monitor all of your infrastructure with Netdata? Check out Netdata Cloud at ${PUBLIC_CLOUD_URL}." + fi + + printf >&2 "%s\n" "Join our community and connect with us on:" + support_list +} + cleanup() { if [ -z "${NO_CLEANUP}" ]; then ${ROOTCMD} rm -rf "${tmpdir}" fi } +deferred_warnings() { + if [ -n "${WARNINGS}" ]; then + printf >&2 "%s\n" "The following non-fatal warnings or errors were encountered:" + echo >&2 "${WARNINGS}" + printf >&2 "\n" + fi +} + fatal() { + deferred_warnings printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}" + printf >&2 "%s\n" "For community support, you can connect with us on:" + support_list 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 +if printf "%s " test > /dev/null 2>&1; then ESCAPED_PRINT_METHOD="printfq" fi escaped_print() { if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then # shellcheck disable=SC3050 - printf "%q " "${@}" + printf "%s " "${@}" else printf "%s" "${*}" fi @@ -289,6 +393,10 @@ run() { info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ " fi + if [ "${DRY_RUN}" -eq 1 ]; then + printf >&2 "%s" "Would run command:\n" + fi + { printf "%s" "${info}" escaped_print "${@}" @@ -299,14 +407,19 @@ run() { escaped_print >&2 "${@}" printf >&2 "%s\n" "${TPUT_RESET}" - "${@}" + if [ "${DRY_RUN}" -ne 1 ]; then + "${@}" + ret=$? + else + ret=0 + fi - ret=$? if [ ${ret} -ne 0 ]; then - run_failed + printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}" printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}" + WARNINGS="${WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}." else - run_ok + printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}" printf "OK\n" >> "${run_logfile}" fi @@ -315,6 +428,7 @@ run() { warning() { printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}" + WARNINGS="${WARNINGS}\n - ${*}" } _cannot_use_tmpdir() { @@ -353,6 +467,17 @@ create_tmp_directory() { mktemp -d -t netdata-kickstart-XXXXXXXXXX } +check_for_remote_file() { + url="${1}" + if command -v curl > /dev/null 2>&1; then + curl --output /dev/null --silent --head --fail "${url}" || return 1 + elif command -v wget > /dev/null 2>&1; then + wget -S --spider "${url}" 2>&1 | grep -q 'HTTP/1.1 200 OK' || return 1 + else + fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003 + fi +} + download() { url="${1}" dest="${2}" @@ -380,10 +505,10 @@ get_redirect() { 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 + if command -v shasum > /dev/null 2>&1; then shasum -a 256 "$@" + elif command -v sha256sum > /dev/null 2>&1; then + sha256sum "$@" else fatal "I could not find a suitable checksum binary to use" F0004 fi @@ -421,7 +546,7 @@ get_system_info() { opensuse-leap) DISTRO_COMPAT_NAME="opensuse" ;; - rocky|rhel) + almalinux|rocky|rhel) DISTRO_COMPAT_NAME="centos" ;; *) @@ -514,6 +639,11 @@ update() { updater="${ndprefix}/usr/libexec/netdata/netdata-updater.sh" if [ -x "${updater}" ]; then + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to update existing installation by running the updater script located at: ${updater}" + return 0 + fi + if run ${ROOTCMD} "${updater}" --not-running-from-cron; then progress "Updated existing install at ${ndprefix}" return 0 @@ -521,15 +651,61 @@ update() { fatal "Failed to update existing Netdata install at ${ndprefix}" F0100 fi else + warning "Could not find a usable copy of the updater script." return 1 fi } +uninstall() { + get_system_info + detect_existing_install + + if [ -n "${OLD_INSTALL_PREFIX}" ]; then + INSTALL_PREFIX="$(echo "${OLD_INSTALL_PREFIX}/" | sed 's/$/netdata/g')" + else + INSTALL_PREFIX="${ndprefix}" + fi + + uninstaller="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh" + uninstaller_url="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-uninstaller.sh" + + if [ $INTERACTIVE = 0 ]; then + FLAGS="--yes --force" + else + FLAGS="--yes" + fi + + if [ -x "${uninstaller}" ]; then + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to uninstall existing install with uninstaller script found at: ${uninstaller}" + return 0 + else + progress "Found existing netdata-uninstaller. Running it.." + if ! run ${ROOTCMD} "${uninstaller}" $FLAGS; then + warning "Uninstaller failed. Some parts of Netdata may still be present on the system." + fi + fi + else + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would download installer script from: ${uninstaller_url}" + progress "Would attempt to uninstall existing install with downloaded uninstaller script." + return 0 + else + progress "Downloading netdata-uninstaller ..." + download "${uninstaller_url}" "${tmpdir}/netdata-uninstaller.sh" + chmod +x "${tmpdir}/netdata-uninstaller.sh" + if ! run ${ROOTCMD} "${tmpdir}/netdata-uninstaller.sh" $FLAGS; then + warning "Uninstaller failed. Some parts of Netdata may still be present on the system." + fi + fi + fi +} + detect_existing_install() { + progress "Checking for existing installations of Netdata..." + if pkg_installed netdata; then ndprefix="/" - elif [ -n "${INSTALL_PREFIX}" ]; then - ndprefix="${INSTALL_PREFIX}" else if [ -n "${INSTALL_PREFIX}" ]; then searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}" @@ -548,7 +724,7 @@ detect_existing_install() { ndprefix="$(dirname "$(dirname "${ndpath}")")" fi - if echo "${ndprefix}" | grep -Eq '/usr$'; then + if echo "${ndprefix}" | grep -Eq '^/usr$'; then ndprefix="$(dirname "${ndprefix}")" fi fi @@ -557,20 +733,34 @@ detect_existing_install() { typefile="${ndprefix}/etc/netdata/.install-type" if [ -r "${typefile}" ]; then ${ROOTCMD} sh -c "cat \"${typefile}\" > \"${tmpdir}/install-type\"" - # shellcheck disable=SC1091 + # shellcheck disable=SC1090,SC1091 . "${tmpdir}/install-type" else INSTALL_TYPE="unknown" fi - fi - INSTALL_PREFIX="${ndprefix}" + envfile="${ndprefix}/etc/netdata/.environment" + if [ "${INSTALL_TYPE}" = "unknown" ] || [ "${INSTALL_TYPE}" = "custom" ]; then + if [ -r "${envfile}" ]; then + ${ROOTCMD} sh -c "cat \"${envfile}\" > \"${tmpdir}/environment\"" + # shellcheck disable=SC1091 + . "${tmpdir}/environment" + if [ -n "${NETDATA_IS_STATIC_INSTALL}" ]; then + if [ "${NETDATA_IS_STATIC_INSTALL}" = "yes" ]; then + INSTALL_TYPE="legacy-static" + else + INSTALL_TYPE="legacy-build" + fi + fi + fi + fi + fi } handle_existing_install() { detect_existing_install - if [ -z "${INSTALL_PREFIX}" ] || [ -z "${INSTALL_TYPE}" ]; then + if [ -z "${ndprefix}" ] || [ -z "${INSTALL_TYPE}" ]; then progress "No existing installations of netdata found, assuming this is a fresh install." return 0 fi @@ -578,13 +768,14 @@ handle_existing_install() { case "${INSTALL_TYPE}" in kickstart-*|legacy-*|binpkg-*|manual-static|unknown) if [ "${INSTALL_TYPE}" = "unknown" ]; then - warning "Found an existing netdata install at ${INSTALL_PREFIX}, but could not determine the install type." + warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type." + warning "Usually this means you installed Netdata through your distribution’s regular package repositories or some other unsupported method." else - progress "Found an existing netdata install at ${INSTALL_PREFIX}, with installation type '${INSTALL_TYPE}'." + 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 ${INSTALL_PREFIX}, but user requested reinstall, continuing." + progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing." case "${INSTALL_TYPE}" in binpkg-*) NETDATA_ONLY_NATIVE=1 ;; @@ -606,34 +797,41 @@ handle_existing_install() { esac return 0 + elif [ "${INSTALL_TYPE}" = "unknown" ]; then + fatal "We do not support trying to update or claim installations when we cannot determine the install type. You will need to uninstall the existing install using the same method you used to install it to proceed." F0106 fi ret=0 - if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then + if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ]; then if ! update; then - warning "Unable to find usable updater script, not updating existing install at ${INSTALL_PREFIX}." + warning "Failed to update existing Netdata install at ${ndprefix}." + else + progress "Successfully updated existing netdata install at ${ndprefix}." fi else - warning "Not updating existing install at ${INSTALL_PREFIX}." + warning "Not updating existing install at ${ndprefix}." fi if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then - progress "Attempting to claim existing install at ${INSTALL_PREFIX}." + 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 ${INSTALL_PREFIX} (no claiming token provided)." + progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)." fi + deferred_warnings + success_banner 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 + fatal "This is an OCI container, use the regular container lifecycle management commands for your container tools instead of this script for managing it." F0203 ;; *) if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then @@ -649,7 +847,20 @@ handle_existing_install() { fi fi else - fatal "Found an existing netdata install at ${INSTALL_PREFIX}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103 + if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then + progress "Attempting to claim existing install at ${ndprefix}." + INSTALL_PREFIX="${ndprefix}" + claim + ret=$? + + cleanup + trap - EXIT + exit $ret + elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then + fatal "User asked to claim, but did not proide a claiming token." F0202 + 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 fi ;; esac @@ -690,7 +901,7 @@ EOF 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 + fatal "The \`--install\` option is only supported together with the \`--build-only\` option." F0204 fi if [ -n "${INSTALL_PREFIX}" ]; then @@ -715,7 +926,7 @@ confirm_install_prefix() { 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 + fatal "Invalid claiming options, claim rooms may only be specified when a token is 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 @@ -748,28 +959,128 @@ is_netdata_running() { } claim() { + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to claim agent to ${NETDATA_CLAIM_URL}" + else + progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}" + fi + progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}" - if [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then + if command -v netdata-claim.sh > /dev/null 2>&1; then + NETDATA_CLAIM_PATH="$(command -v netdata-claim.sh)" + elif [ -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" + elif [ ! -d "${INSTALL_PREFIX}/netdata" ]; then + if [ -d "${INSTALL_PREFIX}/usr" ]; then + NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/usr/sbin/netdata-claim.sh" + else + NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/sbin/netdata-claim.sh" + fi else NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh" fi + if [ ! -x "${NETDATA_CLAIM_PATH}" ]; then + fatal "Unable to find usable claiming script." F0106 + fi + if ! is_netdata_running; 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" + run ${ROOTCMD} "${NETDATA_CLAIM_PATH}" -token="${NETDATA_CLAIM_TOKEN}" -rooms="${NETDATA_CLAIM_ROOMS}" -url="${NETDATA_CLAIM_URL}" ${NETDATA_CLAIM_EXTRA} + case $? in + 0) + progress "Successfully claimed node" + return 0 + ;; + 1) + warning "Unable to claim node due to invalid claiming options. If you are seeing this message, you’ve probably found a bug and should open a bug report at ${AGENT_BUG_REPORT_URL}" + ;; + 2) + warning "Unable to claim node due to issues creating the claiming directory or preparing the local claiming key. Make sure you have a working openssl command and that ${INSTALL_PREFIX}/var/lib/netdata/cloud.d exists, then try again." + ;; + 3) + warning "Unable to claim node due to missing dependencies. Usually this means that the Netdata Agent was built without support for Netdata Cloud. If you built the agent from source, please install all needed dependencies for Cloud support. If you used the regular installation script and see this error, please file a bug." + ;; + 4) + warning "Failed to claim node due to inability to connect to ${NETDATA_CLAIM_URL}. Usually this either means that the specified claiming URL is wrong, or that you are having networking problems." + ;; + 5) + progress "Successfully claimed node, but was not able to notify the Netdata Agent. You will need to restart the Netdata service on this node before it will show up in the Cloud." + return 0 + ;; + 8) + warning "Failed to claim node due to an invalid agent ID. You can usually resolve this by removing ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restarting the agent. Then try to claim it again using the same options." + ;; + 9) + warning "Failed to claim node due to an invalid node name. This probably means you tried to specify a custom name for this node (for example, using the --claim-hostname option), but the hostname itself was either empty or consisted solely of whitespace. You can resolve this by specifying a valid host name and trying again." + ;; + 10) + warning "Failed to claim node due to an invalid room ID. This issue is most likely caused by a typo. Please check if the room(s) you are trying to add appear on the list of rooms provided to the --claim-rooms option ('${NETDATA_CLAIM_ROOMS}'). Then verify if the rooms are visible in Netdata Cloud and try again." + ;; + 11) + warning "Failed to claim node due to an issue with the generated RSA key pair. You can usually resolve this by removing all files in ${INSTALL_PREFIX}/var/lib/netdata/cloud.d and then trying again." + ;; + 12) + warning "Failed to claim node due to an invalid or expired claiming token. Please check that the token specified with the --claim-token option ('${NETDATA_CLAIM_TOKEN}') matches what you see in the Cloud and try again." + ;; + 13) + warning "Failed to claim node because the Cloud thinks it is already claimed. If this node was created by cloning a VM or as a container from a template, please remove the file ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restart the agent. Then try to claim it again with the same options. Otherwise, if you are certain this node has never been claimed before, you can use the --claim-id option to specify a new node ID to use for claiming, for example by using the uuidgen command like so: --claim-id \"\$(uuidgen)\"" + ;; + 14) + warning "Failed to claim node because the node is already in the process of being claimed. You should not need to do anything to resolve this, the node should show up properly in the Cloud soon. If it does not, please report a bug at ${AGENT_BUG_REPORT_URL}." + ;; + 15|16|17) + warning "Failed to claim node due to an internal server error in the Cloud. Please retry claiming this node later, and if you still see this message file a bug report at ${CLOUD_BUG_REPORT_URL}." + ;; + 18) + warning "Unable to claim node because this Netdata installation does not have a unique ID yet. Make sure the agent is running and started up correctly, and then try again." + ;; + *) + warning "Failed to claim node for an unknown reason. This usually means either networking problems or a bug. Please retry claiming later, and if you still see this message file a bug report at ${AGENT_BUG_REPORT_URL}" + ;; + esac + + if [ -z "${NETDATA_NEW_INSTALL}" ]; then + deferred_warnings + printf >&2 "%s\n" "For community support, you can connect with us on:" + support_list + cleanup + trap - EXIT + exit 1 + fi +} + +# ====================================================================== +# Auto-update handling code. +set_auto_updates() { + if [ -x "${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh" ]; then + updater="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh" + elif [ -x "${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh" ]; then + updater="${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh" else - warning "Unable to claim node, you must do so manually." - if [ -z "${NETDATA_NEW_INSTALL}" ]; then - cleanup - trap - EXIT - exit 1 + warning "Could not find netdata-updater.sh. This means that auto-updates cannot (currently) be enabled on this system. See https://learn.netdata.cloud/docs/agent/packaging/installer/update for more information about updating Netdata." + return 0 + fi + + if [ "${NETDATA_AUTO_UPDATES}" = "1" ]; then + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would have attempted to enable automatic updates." + # This first case is for catching using a new kickstart script with an old build. It can be safely removed after v1.34.0 is released. + elif ! grep -q '\-\-enable-auto-updates' ${updater}; then + echo + elif ! ${ROOTCMD} ${updater} --enable-auto-updates "${NETDATA_AUTO_UPDATE_TYPE}"; then + warning "Failed to enable auto updates. Netdata will still work, but you will need to update manually." + fi + else + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would have attempted to disable automatic updates." + else + ${ROOTCMD} ${updater} --disable-auto-updates fi fi } @@ -803,7 +1114,7 @@ netdata_avail_check() { ;; centos|fedora|ol) # shellcheck disable=SC2086 - ${pm_cmd} search -v netdata | grep -qE 'Repo *: netdata(-edge)?$' + ${pm_cmd} search --nogpgcheck -v netdata | grep -qE 'Repo *: netdata(-edge)?$' return $? ;; opensuse) @@ -820,12 +1131,10 @@ netdata_avail_check() { 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." + if ${pm_cmd} search --nogpgcheck -v libuv | grep -q "No matches found"; then + progress "libuv not found, checking for EPEL availability." + if ${pm_cmd} search --nogpgcheck -v epel-release | grep -q "No matches found"; then + warning "Unable to find a suitable source for libuv, cannot install using native packages on this system." return 1 else progress "EPEL is available, attempting to install so that required dependencies are available." @@ -845,10 +1154,14 @@ check_special_native_deps() { try_package_install() { if [ -z "${DISTRO}" ] || [ "${DISTRO}" = "unknown" ]; then warning "Unable to determine Linux distribution for native packages." - return 1 + return 2 fi - progress "Attempting to install using native packages..." + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to install using native packages..." + else + progress "Attempting to install using native packages..." + fi if [ "${RELEASE_CHANNEL}" = "nightly" ]; then release="-edge" @@ -962,14 +1275,17 @@ try_package_install() { 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." + progress "Checking for availability of repository configuration package." + if ! check_for_remote_file "${repoconfig_url}"; then + warning "No repository configuration package available for ${DISTRO} ${SYSVERSION}." return 2 fi + if ! download "${repoconfig_url}" "${tmpdir}/${repoconfig_file}"; then + fatal "Failed to download repository configuration package." F0209 + 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." @@ -977,7 +1293,6 @@ try_package_install() { 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." @@ -985,10 +1300,9 @@ try_package_install() { 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 + fatal "Failed to refresh repository metadata." F0205 fi fi else @@ -996,7 +1310,7 @@ try_package_install() { fi if ! check_special_native_deps; then - warning "Could not find secondary dependencies ${DISTRO} on ${SYSARCH}." + warning "Could not find secondary dependencies for ${DISTRO} on ${SYSARCH}." if [ -z "${NO_CLEANUP}" ]; then progress "Attempting to uninstall repository configuration package." # shellcheck disable=SC2086 @@ -1005,7 +1319,6 @@ try_package_install() { 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 @@ -1021,7 +1334,6 @@ try_package_install() { 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." @@ -1050,19 +1362,32 @@ set_static_archive_urls() { try_static_install() { set_static_archive_urls "${RELEASE_CHANNEL}" - progress "Downloading static netdata binary: ${NETDATA_STATIC_ARCHIVE_URL}" + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to install using static build..." + else + progress "Attempting to install using static build..." + fi - if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "${tmpdir}/netdata-${SYSARCH}-latest.gz.run"; then - warning "Unable to download static build archive for ${SYSARCH}." + # Check status code first, so that we can provide nicer fallback for dry runs. + if ! check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then + warning "No static build available for ${SYSARCH} CPUs." return 2 fi + if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "${tmpdir}/netdata-${SYSARCH}-latest.gz.run"; then + fatal "Unable to download static build archive for ${SYSARCH}." F0208 + 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 + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would validate SHA256 checksum of downloaded static build archive." + else + 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 fi if [ "${INTERACTIVE}" -eq 0 ]; then @@ -1077,18 +1402,20 @@ try_static_install() { return 2 fi + if [ "${DRY_RUN}" -ne 1 ]; then 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 + 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=SC1090,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}" + ${ROOTCMD} chown netdata:netdata "${tmpdir}/install-type" + ${ROOTCMD} cp "${tmpdir}/install-type" "${install_type_file}" + fi fi } @@ -1114,33 +1441,38 @@ install_local_build_dependencies() { return 1 fi - progress "Fetching script to detect required packages..." - download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh" + if ! download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh"; then + fatal "Failed to download dependency handling script for local build." F000D + fi - if [ ! -s "${tmpdir}/install-required-packages.sh" ]; then - warning "Downloaded dependency installation script is empty." + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would run downloaded script to install required build dependencies..." else - progress "Running downloaded script to detect required packages..." + progress "Running downloaded script to install required build dependencies..." + fi - if [ "${INTERACTIVE}" -eq 0 ]; then - opts="--dont-wait --non-interactive" - fi + if [ "${INTERACTIVE}" -eq 0 ]; then + opts="--dont-wait --non-interactive" + fi - if [ "${SYSTYPE}" = "Darwin" ]; then - sudo="" - else - sudo="${ROOTCMD}" - 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 + # shellcheck disable=SC2086 + if ! run ${sudo} "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then + warning "Failed to install all required packages, but installation might still be possible." fi } build_and_install() { - progress "Building netdata" + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to build netdata..." + else + progress "Building netdata..." + fi echo "INSTALL_TYPE='kickstart-build'" > system/.install-type @@ -1169,40 +1501,57 @@ build_and_install() { case $? in 1) - fatal "netdata-installer.sh exited with error" F0007 + fatal "netdata-installer.sh failed to run correctly." F0007 ;; 2) - fatal "Insufficient RAM to install netdata" F0008 + fatal "Insufficient RAM to install netdata." F0008 ;; esac } try_build_install() { + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would attempt to install by building locally..." + else + progress "Attempting to install by building locally..." + fi + 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 ! download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-latest.tar.gz"; then + fatal "Failed to download source tarball for local build." F000B + fi + + if ! download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"; then + fatal "Failed to download checksums for source tarball verification." F000C + fi - 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 + if [ "${DRY_RUN}" -eq 1 ]; then + progress "Would validate SHA256 checksum of downloaded source archive." + else + 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 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 [ "${DRY_RUN}" -ne 1 ]; then + cd "$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name netdata-)" || fatal "Cannot change directory to netdata source tree" F0006 + fi - if [ -x netdata-installer.sh ]; then + if [ -x netdata-installer.sh ] || [ "${DRY_RUN}" -eq 1 ]; 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 + fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh)." F0009 fi fi } @@ -1218,6 +1567,7 @@ install_on_linux() { case "$?" in 0) NETDATA_INSTALL_SUCCESSFUL=1 + INSTALL_PREFIX="/" ;; 1) fatal "Unable to install on this system." F0300 @@ -1329,9 +1679,22 @@ while [ -n "${1}" ]; do "--no-cleanup") NO_CLEANUP=1 ;; "--dont-wait"|"--non-interactive") INTERACTIVE=0 ;; "--interactive") INTERACTIVE=1 ;; + "--dry-run") DRY_RUN=1 ;; "--stable-channel") RELEASE_CHANNEL="stable" ;; "--no-updates") NETDATA_AUTO_UPDATES=0 ;; "--auto-update") NETDATA_AUTO_UPDATES="1" ;; + "--auto-update-method") + NETDATA_AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')" + case "${NETDATA_AUTO_UPDATE_TYPE}" in + systemd|interval|crontab) + shift 1 + ;; + *) + echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab" + exit 1 + ;; + esac + ;; "--reinstall") NETDATA_REINSTALL=1 ;; "--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;; "--claim-only") NETDATA_CLAIM_ONLY=1 ;; @@ -1355,6 +1718,16 @@ while [ -n "${1}" ]; do INSTALL_PREFIX="${2}" shift 1 ;; + "--old-install-prefix") + OLD_INSTALL_PREFIX="${2}" + shift 1 + ;; + "--uninstall") + ACTION="uninstall" + ;; + "--reinstall-clean") + ACTION="reinstall-clean" + ;; "--native-only") NETDATA_ONLY_NATIVE=1 NETDATA_ONLY_STATIC=0 @@ -1385,11 +1758,11 @@ while [ -n "${1}" ]; do NETDATA_CLAIM_URL="${2}" shift 1 ;; - "--claim-*") + "--claim-"*) optname="$(echo "${1}" | cut -d '-' -f 4-)" case "${optname}" in id|proxy|user|hostname) - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname} ${2}" + NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}=${2}" shift 1 ;; verbose|insecure|noproxy|noreload|daemon-not-running) @@ -1413,24 +1786,8 @@ 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 +if [ -z "${ACTION}" ]; then + handle_existing_install fi -telemetry_event INSTALL_SUCCESS "" "" -cleanup -trap - EXIT +main diff --git a/packaging/installer/methods/cloud-providers.md b/packaging/installer/methods/cloud-providers.md index 08c0ed9d..bc5c9aae 100644 --- a/packaging/installer/methods/cloud-providers.md +++ b/packaging/installer/methods/cloud-providers.md @@ -123,4 +123,4 @@ Name: Netdata Click **Add** to apply your new inbound security rule. -[![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%2Fcloud-providers&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/methods/freebsd.md b/packaging/installer/methods/freebsd.md index 9c3db900..12b55d6a 100644 --- a/packaging/installer/methods/freebsd.md +++ b/packaging/installer/methods/freebsd.md @@ -93,16 +93,15 @@ The `netdata-updater.sh` script will update your Agent. | `--disable-plugin-nfacct` | Disable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available| | `--enable-plugin-xenstat` | Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available| | `--disable-plugin-xenstat` | Disable the xenstat plugin| -| `--enable-backend-kinesis` | Enable AWS Kinesis backend. Default: enable it when libaws_cpp_sdk_kinesis and libraries (it depends on are available)| -| `--disable-backend-kinesis` | Disable AWS Kinesis backend. Default: enable it when libaws_cpp_sdk_kinesis and libraries (it depends on are available)| -| `--enable-backend-prometheus-remote-write` | Enable Prometheus remote write backend. Default: enable it when libprotobuf and libsnappy are available| -| `--disable-backend-prometheus-remote-write` | Disable Prometheus remote write backend. Default: enable it when libprotobuf and libsnappy are available| -| `--enable-backend-mongodb` | Enable MongoDB backend. Default: enable it when libmongoc is available| -| `--disable-backend-mongodb` | Disable MongoDB backend| +| `--disable-exporting-kinesis` | Disable AWS Kinesis exporting connector. Default: enable it when libaws_cpp_sdk_kinesis and libraries (it depends on are available)| +| `--enable-exporting-prometheus-remote-write` | Enable Prometheus remote write exporting connector. Default: enable it when libprotobuf and libsnappy are available| +| `--disable-exporting-prometheus-remote-write` | Disable Prometheus remote write exporting connector. Default: enable it when libprotobuf and libsnappy are available| +| `--enable-exporting-mongodb` | Enable MongoDB exporting connector. Default: enable it when libmongoc is available| +| `--disable-exporting-mongodb` | Disable MongoDB exporting connector| | `--enable-lto` | Enable Link-Time-Optimization. Default: enabled| | `--disable-lto` | Disable Link-Time-Optimization. Default: enabled| | `--disable-x86-sse` | Disable SSE instructions. By default SSE optimizations are enabled| | `--zlib-is-really-here` or `--libs-are-really-here` | If you get errors about missing zlib or libuuid but you know it is available, you might have a broken pkg-config. Use this option to proceed without checking pkg-config| -|`--disable-telemetry` | Use this flag to opt-out from our anonymous telemetry program. (DO_NOT_TRACK=1)| +|`--disable-telemetry` | Use this flag to opt-out from our anonymous telemetry program. (DISABLE_TELEMETRY=1)| + -[![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%2Ffreebsd&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) diff --git a/packaging/installer/methods/freenas.md b/packaging/installer/methods/freenas.md index a0dafdff..a69f1e3f 100644 --- a/packaging/installer/methods/freenas.md +++ b/packaging/installer/methods/freenas.md @@ -21,4 +21,4 @@ To start the Netdata service: service netdata start ``` -[![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%2Ffreenas&_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 5bd9633d..2ff20cfd 100644 --- a/packaging/installer/methods/kickstart.md +++ b/packaging/installer/methods/kickstart.md @@ -12,7 +12,7 @@ import { OneLineInstallWget, OneLineInstallCurl } from '../../../../../src/compo This page covers detailed instructions on using and configuring the automatic one-line installation script named `kickstart.sh`. -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.md) before continuing. +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](macos.md) before continuing. > 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. @@ -48,7 +48,8 @@ The `kickstart.sh` script accepts a number of optional parameters to control how - `--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` -- `--dont-start-it`: Don’t auto-start the daemon after installing. This parameter is not gauranteed to work. +- `--dry-run`: Show what the installer would do, but don’t actually do any of it. +- `--dont-start-it`: Don’t auto-start the daemon after installing. This parameter is not guaranteed 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). @@ -63,6 +64,9 @@ The `kickstart.sh` script accepts a number of optional parameters to control how use runtime configuration to disable cloud support. - `--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). +- `--old-install-prefix`: Specify the custom local build's installation prefix that should be removed. +- `--uninstall`: Uninstall an existing installation of Netdata. +- `--reinstall-clean`: Performs an uninstall of Netdata and clean installation. 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): @@ -73,15 +77,21 @@ should not need to use special values for any of these): - `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. +- `DISABLE_TELEMETRY`: 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 -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). +The `kickstart.sh` script accepts additional parameters to automatically [connect](/claim/README.md) your node to Netdata Cloud immediately after installation. + +> Note: You either need to run the command with root privileges or run it with the user that is running the agent. More details: [Connect an agent without root privileges](/claim/README.md#connect-an-agent-without-root-privileges) section. + +To automatically claim nodes after installation: + +1. Sign in to [Netdata Cloud](https://app.netdata.cloud/sign-in?cloudRoute=/spaces) +2. Go to the [Spaces management area](https://learn.netdata.cloud/docs/cloud/spaces#manage-spaces) +3. Click on **Connect Nodes** +4. Find the `token` and `rooms` strings and specify your nodes: - `--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. @@ -93,11 +103,9 @@ area](https://learn.netdata.cloud/docs/cloud/spaces#manage-spaces). For example: ```bash -wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-kickstart.sh --claim-token=TOKEN --claim-rooms=ROOM1,ROOM2 +wget -O /tmp/netdata-kickstart.sh https://my-netdata.io/kickstart.sh && sh /tmp/netdata-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](/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 @@ -136,7 +144,7 @@ To use `md5sum` to verify the integrity of the `kickstart.sh` script you will do run the following: ```bash -[ "2ea326514c5166eabf02622e75d10a53" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID" +[ "<checksum-will-be-added-in-documentation-processing>" = "$(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`. @@ -152,4 +160,4 @@ Read through Netdata's [documentation](https://learn.netdata.cloud/docs), which 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&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/methods/kubernetes.md b/packaging/installer/methods/kubernetes.md index f1285066..216703a3 100644 --- a/packaging/installer/methods/kubernetes.md +++ b/packaging/installer/methods/kubernetes.md @@ -194,4 +194,4 @@ utilization metrics, and application metrics. - [Netdata Helm chart](https://github.com/netdata/helmchart) - [Netdata service discovery](https://github.com/netdata/agent-service-discovery/) -[![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%2Fkubernetes&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/methods/macos.md b/packaging/installer/methods/macos.md index 4fa0300c..7257e1a6 100644 --- a/packaging/installer/methods/macos.md +++ b/packaging/installer/methods/macos.md @@ -12,13 +12,13 @@ You could also use a macOS system as the parent node in a [streaming configurati You can install Netdata in one of the three following ways: - **[Install Netdata with the our automatic one-line installation script (recommended)](#install-netdata-with-our-automatic-one-line-installation-script)**, -- [Install Netdata via Homebrew](#install-netdata-with-the-homebrew-package) +- [Install Netdata via Homebrew](#install-netdata-via-homebrew) - [Install Netdata from source](#install-netdata-from-source) Each of these installation option requires [Homebrew](https://brew.sh/) for handling dependencies. > The Netdata Homebrew package is community-created and -maintained. -> Community-maintained packages _may_ receive support from Netdata, but are only a best-effort affair. Learn more about [Netdata's platform support policy](/packaging/platform_support). +> Community-maintained packages _may_ receive support from Netdata, but are only a best-effort affair. Learn more about [Netdata's platform support policy](/packaging/PLATFORM_SUPPORT.md). ## Install Netdata with our automatic one-line installation script @@ -52,7 +52,7 @@ curl https://my-netdata.io/kickstart.sh > /tmp/netdata-kickstart.sh && sh /tmp/n ``` The Netdata Agent is installed under `/usr/local/netdata` on your machine. Your machine will also show up as a node in your Netdata Cloud. -If you experience issues while claiming your node, follow the steps in our [Troubleshooting](claim/README.md#troubleshooting) documentation. +If you experience issues while claiming your node, follow the steps in our [Troubleshooting](/claim/README.md#troubleshooting) documentation. ## Install Netdata via Homebrew To install Netdata and all its dependencies, run Homebrew using the following command: @@ -108,4 +108,4 @@ When you're finished with installation, check out our [single-node](/docs/quicks Or, skip straight to [configuring the Netdata Agent](/docs/configure/nodes.md). -[![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%2Fmacos&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/methods/manual.md b/packaging/installer/methods/manual.md index 6d88fbd8..aaf1451d 100644 --- a/packaging/installer/methods/manual.md +++ b/packaging/installer/methods/manual.md @@ -244,4 +244,4 @@ Read through Netdata's [documentation](https://learn.netdata.cloud/docs), which 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%2Fmanual&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/methods/offline.md b/packaging/installer/methods/offline.md index c978dd61..53390c71 100644 --- a/packaging/installer/methods/offline.md +++ b/packaging/installer/methods/offline.md @@ -86,5 +86,3 @@ 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%2Foffline&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]() diff --git a/packaging/installer/methods/pfsense.md b/packaging/installer/methods/pfsense.md index 6d9de760..f0d73003 100644 --- a/packaging/installer/methods/pfsense.md +++ b/packaging/installer/methods/pfsense.md @@ -81,4 +81,4 @@ workaround from <https://redmine.pfsense.org/issues/6643> **Note:** In pfSense, the Netdata configuration files are located under `/usr/local/etc/netdata`. -[![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%2Fpfsense&_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 737ea166..a25323f0 100644 --- a/packaging/installer/methods/source.md +++ b/packaging/installer/methods/source.md @@ -234,4 +234,4 @@ repository](https://github.com/netdata/kernel-collector/blob/master/README.md), which outlines both the required dependencies, as well as multiple options for building the code. -[![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%2Fsource&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/methods/synology.md b/packaging/installer/methods/synology.md index 8e55924c..30ec3035 100644 --- a/packaging/installer/methods/synology.md +++ b/packaging/installer/methods/synology.md @@ -34,9 +34,7 @@ chown -R netdata:netdata /opt/netdata/var/lib/netdata /opt/netdata/var/cache/net chown -R netdata:root /opt/netdata/var/log/netdata ``` -4. Uncomment and set `web files owner` to `root`, and `web files group` to `netdata` in - the `/opt/netdata/etc/netdata/netdata.conf`. -5. Restart Netdata +4. Restart Netdata ```sh /etc/rc.netdata restart @@ -58,4 +56,4 @@ installed. You'll have to do this manually: 3. Make sure `/etc/rc.netdata` is executable: `chmod 0755 /etc/rc.netdata`. -[![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%2Fsynology&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)](<>) + diff --git a/packaging/installer/netdata-uninstaller.sh b/packaging/installer/netdata-uninstaller.sh index a248860d..f2cc7b7c 100755 --- a/packaging/installer/netdata-uninstaller.sh +++ b/packaging/installer/netdata-uninstaller.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # # This is the netdata uninstaller script # @@ -21,6 +21,7 @@ where: FILE_REMOVAL_STATUS=0 ENVIRONMENT_FILE="/etc/netdata/.environment" +# shellcheck disable=SC2034 INTERACTIVITY="-i" YES=0 while :; do @@ -35,6 +36,7 @@ while :; do ;; -y | --yes) YES=1 + FLAG=-y shift ;; -e | --env) @@ -55,15 +57,219 @@ if [ "$YES" != "1" ]; then exit 1 fi -if [[ $EUID -ne 0 ]]; then +if [ "$(id -u)" -ne 0 ]; then echo >&2 "This script SHOULD be run as root or otherwise it won't delete all installed components." key="n" - read -r -s -n 1 -p "Do you want to continue as non-root user [y/n] ? " key + read -r 1 -p "Do you want to continue as non-root user [y/n] ? " key if [ "$key" != "y" ] && [ "$key" != "Y" ]; then exit 1 fi fi +user_input() { + if [ "${INTERACTIVITY}" = "-i" ]; then + TEXT="$1 [y/n]" + + while true; do + echo "$TEXT" + read -r yn + + case "$yn" in + [Yy]*) return 0;; + [Nn]*) return 1;; + *) echo "Please answer yes or no.";; + esac + done + fi +} + +_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 +} + +tmpdir="$(create_tmp_directory)" + +detect_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" + envfile="${ndprefix}/etc/netdata/.environment" + if [ -r "${typefile}" ]; then + ${ROOTCMD} sh -c "cat \"${typefile}\" > \"${tmpdir}/install-type\"" + # shellcheck disable=SC1090,SC1091 + . "${tmpdir}/install-type" + else + INSTALL_TYPE="unknown" + fi + + if [ "${INSTALL_TYPE}" = "unknown" ] || [ "${INSTALL_TYPE}" = "custom" ]; then + if [ -r "${envfile}" ]; then + ${ROOTCMD} sh -c "cat \"${envfile}\" > \"${tmpdir}/environment\"" + # shellcheck disable=SC1091 + . "${tmpdir}/environment" + if [ -n "${NETDATA_IS_STATIC_INSTALL}" ]; then + if [ "${NETDATA_IS_STATIC_INSTALL}" = "yes" ]; then + INSTALL_TYPE="legacy-static" + else + INSTALL_TYPE="legacy-build" + fi + fi + fi + fi + fi +} + +pkg_installed() { + case "${DISTRO_COMPAT_NAME}" in + debian|ubuntu) + dpkg-query --show --showformat '${Status}' "${1}" 2>&1 | cut -f 1 -d ' ' | grep -q '^install$' + return $? + ;; + centos|fedora|opensuse|ol) + rpm -q "${1}" > /dev/null 2>&1 + return $? + ;; + *) + return 1 + ;; + esac +} + +detect_existing_install + +if [ -x "$(command -v apt-get)" ] && [ "${INSTALL_TYPE}" = "binpkg-deb" ]; then + if dpkg -s netdata > /dev/null; then + echo "Found netdata native installation" + if user_input "Do you want to remove netdata? "; then + apt-get remove netdata ${FLAG} + fi + if dpkg -s netdata-repo-edge > /dev/null; then + if user_input "Do you want to remove netdata-repo-edge? "; then + apt-get remove netdata-repo-edge ${FLAG} + fi + fi + if dpkg -s netdata-repo > /dev/null; then + if user_input "Do you want to remove netdata-repo? "; then + apt-get remove netdata-repo ${FLAG} + fi + fi + exit 0 + fi +elif [ -x "$(command -v dnf)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then + if rpm -q netdata > /dev/null; then + echo "Found netdata native installation." + if user_input "Do you want to remove netdata? "; then + dnf remove netdata ${FLAG} + fi + if rpm -q netdata-repo-edge > /dev/null; then + if user_input "Do you want to remove netdata-repo-edge? "; then + dnf remove netdata-repo-edge ${FLAG} + fi + fi + if rpm -q netdata-repo > /dev/null; then + if user_input "Do you want to remove netdata-repo? "; then + dnf remove netdata-repo ${FLAG} + fi + fi + exit 0 + fi +elif [ -x "$(command -v yum)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then + if rpm -q netdata > /dev/null; then + echo "Found netdata native installation." + if user_input "Do you want to remove netdata? "; then + yum remove netdata ${FLAG} + fi + if rpm -q netdata-repo-edge > /dev/null; then + if user_input "Do you want to remove netdata-repo-edge? "; then + yum remove netdata-repo-edge ${FLAG} + fi + fi + if rpm -q netdata-repo > /dev/null; then + if user_input "Do you want to remove netdata-repo? "; then + yum remove netdata-repo ${FLAG} + fi + fi + exit 0 + fi +elif [ -x "$(command -v zypper)" ] && [ "${INSTALL_TYPE}" = "binpkg-rpm" ]; then + if [ "${FLAG}" = "-y" ]; then + FLAG=-n + fi + if zypper search -i netdata > /dev/null; then + echo "Found netdata native installation." + if user_input "Do you want to remove netdata? "; then + zypper ${FLAG} remove netdata + fi + if zypper search -i netdata-repo-edge > /dev/null; then + if user_input "Do you want to remove netdata-repo-edge? "; then + zypper ${FLAG} remove netdata-repo-edge + fi + fi + if zypper search -i netdata-repo > /dev/null; then + if user_input "Do you want to remove netdata-repo? "; then + zypper ${FLAG} remove netdata-repo + fi + fi + exit 0 + fi +fi + # ----------------------------------------------------------------------------- # portable service command @@ -72,7 +278,8 @@ rcservice_cmd="$(command -v rc-service 2> /dev/null)" systemctl_cmd="$(command -v systemctl 2> /dev/null)" service() { - local cmd="${1}" action="${2}" + cmd="${1}" + action="${2}" if [ -n "${systemctl_cmd}" ]; then run "${systemctl_cmd}" "${action}" "${cmd}" @@ -127,12 +334,12 @@ run_failed() { } ESCAPED_PRINT_METHOD= -if printf "%q " test > /dev/null 2>&1; then +if printf "%s " test > /dev/null 2>&1; then ESCAPED_PRINT_METHOD="printfq" fi escaped_print() { if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then - printf "%q " "${@}" + printf "%s " "${@}" else printf "%s" "${*}" fi @@ -141,9 +348,10 @@ escaped_print() { 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 @@ -163,7 +371,7 @@ run() { "${@}" - local ret=$? + ret=$? if [ ${ret} -ne 0 ]; then run_failed printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}" @@ -176,7 +384,7 @@ run() { } portable_del_group() { - local groupname="${1}" + groupname="${1}" # Check if group exist echo >&2 "Removing ${groupname} user group ..." @@ -206,7 +414,11 @@ portable_del_group() { } issystemd() { - local pids p myns ns systemctl + pids='' + p='' + myns='' + ns='' + systemctl='' # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then @@ -240,7 +452,7 @@ issystemd() { } portable_del_user() { - local username="${1}" + username="${1}" echo >&2 "Deleting ${username} user account ..." # Linux @@ -258,7 +470,8 @@ portable_del_user() { } portable_del_user_from_group() { - local groupname="${1}" username="${2}" + groupname="${1}" + username="${2}" # username is not in group echo >&2 "Deleting ${username} user from ${groupname} group ..." @@ -296,30 +509,25 @@ quit_msg() { fi } -user_input() { - TEXT="$1" - if [ "${INTERACTIVITY}" = "-i" ]; then - read -r -p "$TEXT" >&2 - fi -} - rm_file() { FILE="$1" if [ -f "${FILE}" ]; then - run rm -v ${INTERACTIVITY} "${FILE}" + if user_input "Do you want to delete this file '$FILE' ? "; then + run rm -v "${FILE}" + fi fi } rm_dir() { DIR="$1" if [ -n "$DIR" ] && [ -d "$DIR" ]; then - user_input "Press ENTER to recursively delete directory '$DIR' > " - run rm -v -f -R "${DIR}" + if user_input "Do you want to delete this directory '$DIR' ? "; then + run rm -v -f -R "${DIR}" + fi fi } safe_pidof() { - local pidof_cmd pidof_cmd="$(command -v pidof 2> /dev/null)" if [ -n "${pidof_cmd}" ]; then ${pidof_cmd} "${@}" @@ -345,7 +553,9 @@ pidisnetdata() { } stop_netdata_on_pid() { - local pid="${1}" ret=0 count=0 + pid="${1}" + ret=0 + count=0 pidisnetdata "${pid}" || return 0 @@ -386,7 +596,8 @@ stop_netdata_on_pid() { } netdata_pids() { - local p myns ns + p='' + ns='' myns="$(readlink /proc/self/ns/pid 2> /dev/null)" @@ -403,9 +614,9 @@ netdata_pids() { } stop_all_netdata() { - local p + p='' - if [ "${UID}" -eq 0 ]; then + if [ "$(id -u)" -eq 0 ]; then uname="$(uname 2> /dev/null)" # Any of these may fail, but we need to not bail if they do. @@ -428,7 +639,7 @@ stop_all_netdata() { fi fi - if [ -n "$(netdata_pids)" ] && [ -n "$(builtin type -P netdatacli)" ]; then + if [ -n "$(netdata_pids)" ] && [ -n "$(command -v netdatacli)" ]; then netdatacli shutdown-agent sleep 20 fi @@ -441,8 +652,9 @@ stop_all_netdata() { trap quit_msg EXIT -#shellcheck source=/dev/null -source "${ENVIRONMENT_FILE}" || exit 1 +# shellcheck source=/dev/null +# shellcheck disable=SC1090 +. "${ENVIRONMENT_FILE}" || exit 1 #### STOP NETDATA echo >&2 "Stopping a possibly running netdata..." @@ -484,16 +696,19 @@ FILE_REMOVAL_STATUS=1 #### REMOVE NETDATA USER FROM ADDED GROUPS if [ -n "$NETDATA_ADDED_TO_GROUPS" ]; then - user_input "Press ENTER to delete 'netdata' from following groups: '$NETDATA_ADDED_TO_GROUPS' > " - for group in $NETDATA_ADDED_TO_GROUPS; do - portable_del_user_from_group "${group}" "netdata" - done + if user_input "Do you want to delete 'netdata' from following groups: '$NETDATA_ADDED_TO_GROUPS' ? "; then + for group in $NETDATA_ADDED_TO_GROUPS; do + portable_del_user_from_group "${group}" "netdata" + done + fi fi #### REMOVE USER -user_input "Press ENTER to delete 'netdata' system user > " -portable_del_user "netdata" || : +if user_input "Do you want to delete 'netdata' system user ? "; then + portable_del_user "netdata" || : +fi ### REMOVE GROUP -user_input "Press ENTER to delete 'netdata' system group > " -portable_del_group "netdata" || : +if user_input "Do you want to delete 'netdata' system group ? "; then + portable_del_group "netdata" || : +fi diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index bfb5503c..63280437 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -30,6 +30,8 @@ set -e +PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh" + script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" if [ -x "${script_dir}/netdata-updater" ]; then @@ -46,32 +48,195 @@ else INTERACTIVE=1 fi +if [ -n "${script_source}" ]; then + script_name="$(basename "${script_source}")" +else + script_name="netdata-updater.sh" +fi + info() { - echo >&3 "$(date) : INFO: " "${@}" + echo >&3 "$(date) : INFO: ${script_name}: " "${@}" } error() { - echo >&3 "$(date) : ERROR: " "${@}" + echo >&3 "$(date) : ERROR: ${script_name}: " "${@}" } -: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}" +fatal() { + echo >&3 "$(date) : FATAL: ${script_name}: FAILED TO UPDATE NETDATA: " "${@}" + exit 1 +} -if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; then - if [ -r "${script_dir}/../../../etc/netdata/.environment" ]; then - ENVIRONMENT_FILE="${script_dir}/../../../etc/netdata/.environment" - elif [ -r "/etc/netdata/.environment" ]; then - ENVIRONMENT_FILE="/etc/netdata/.environment" - elif [ -r "/opt/netdata/etc/netdata/.environment" ]; then - ENVIRONMENT_FILE="/opt/netdata/etc/netdata/.environment" +issystemd() { + # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd + if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then + return 1 + fi + + # if there is no systemctl command, it is not systemd + systemctl=$(command -v systemctl 2> /dev/null) + if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then + return 1 + fi + + # if pid 1 is systemd, it is systemd + [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0 + + # if systemd is not running, it is not systemd + pids=$(safe_pidof systemd 2> /dev/null) + [ -z "${pids}" ] && return 1 + + # check if the running systemd processes are not in our namespace + myns="$(readlink /proc/self/ns/pid 2> /dev/null)" + for p in ${pids}; do + ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)" + + # if pid of systemd is in our namespace, it is systemd + [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0 + done + + # else, it is not systemd + return 1 +} + +_get_intervaldir() { + if [ -d /etc/cron.daily ]; then + echo /etc/cron.daily + elif [ -d /etc/periodic/daily ]; then + echo /etc/periodic/daily else - envpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.environment' -type f 2> /dev/null | head -n 1)" - if [ -r "${envpath}" ]; then - ENVIRONMENT_FILE="${envpath}" - else - fatal "Cannot find environment file, unable to update." + return 1 + fi + + return 0 +} + +_get_scheduler_type() { + if _get_intervaldir > /dev/null ; then + echo 'interval' + elif issystemd ; then + echo 'systemd' + elif [ -d /etc/cron.d ] ; then + echo 'crontab' + else + echo 'none' + fi +} + +install_build_dependencies() { + bash="$(command -v bash 2> /dev/null)" + + if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then + error "Unable to find a usable version of \`bash\` (required for local build)." + return 1 + fi + + info "Fetching dependency handling script..." + download "${PACKAGES_SCRIPT}" "./install-required-packages.sh" || true + + if [ ! -s "./install-required-packages.sh" ]; then + error "Downloaded dependency installation script is empty." + else + info "Running dependency handling script..." + + opts="--dont-wait --non-interactive" + + # shellcheck disable=SC2086 + if ! "${bash}" "./install-required-packages.sh" ${opts} netdata >&3 2>&3; then + error "Installing build dependencies failed. The update should still work, but you might be missing some features." fi fi -fi +} + +enable_netdata_updater() { + updater_type="$(echo "${1}" | tr '[:upper:]' '[:lower:]')" + case "${updater_type}" in + systemd|interval|crontab) + updater_type="${1}" + ;; + "") + updater_type="$(_get_scheduler_type)" + ;; + *) + error "Unrecognized updater type ${updater_type} requested. Supported types are 'systemd', 'interval', and 'crontab'." + exit 1 + ;; + esac + + case "${updater_type}" in + "systemd") + if issystemd; then + systemctl enable netdata-updater.timer + + info "Auto-updating has been ENABLED using a systemd timer unit.\n" + info "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure." + info "Successful updates should produce empty logs." + else + error "Systemd-based auto-update scheduling requested, but this does not appear to be a systemd system." + error "Auto-updates have NOT been enabled." + return 1 + fi + ;; + "interval") + if _get_intervaldir > /dev/null; then + ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_intervaldir)/netdata-updater" + + info "Auto-updating has been ENABLED through cron, updater script linked to $(_get_intervaldir)/netdata-updater\n" + info "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure." + info "Successful updates will not send an email." + else + error "Interval-based auto-update scheduling requested, but I could not find an interval scheduling directory." + error "Auto-updates have NOT been enabled." + return 1 + fi + ;; + "crontab") + if [ -d "/etc/cron.d" ]; then + cat > "/etc/cron.d/netdata-updater" <<-EOF + 2 57 * * * root ${NETDATA_PREFIX}/netdata-updater.sh + EOF + + info "Auto-updating has been ENABLED through cron, using a crontab at /etc/cron.d/netdata-updater\n" + info "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure." + info "Successful updates will not send an email." + else + error "Crontab-based auto-update scheduling requested, but there is no '/etc/cron.d'." + error "Auto-updates have NOT been enabled." + return 1 + fi + ;; + *) + error "Unable to determine what type of auto-update scheduling to use." + error "Auto-updates have NOT been enabled." + return 1 + esac + + return 0 +} + +disable_netdata_updater() { + if issystemd && ( systemctl list-units --full -all | grep -Fq "netdata-updater.timer" ) ; then + systemctl disable netdata-updater.timer + fi + + if [ -d /etc/cron.daily ]; then + rm -f /etc/cron.daily/netdata-updater.sh + rm -f /etc/cron.daily/netdata-updater + fi + + if [ -d /etc/periodic/daily ]; then + rm -f /etc/periodic/daily/netdata-updater.sh + rm -f /etc/periodic/daily/netdata-updater + fi + + if [ -d /etc/cron.d ]; then + rm -f /etc/cron.d/netdata-updater + fi + + info "Auto-updates have been DISABLED." + + return 0 +} str_in_list() { printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$" @@ -90,12 +255,6 @@ safe_sha256sum() { fi } -# this is what we will do if it fails (head-less only) -fatal() { - error "FAILED TO UPDATE NETDATA : ${1}" - exit 1 -} - cleanup() { if [ -n "${logfile}" ]; then cat >&2 "${logfile}" @@ -117,7 +276,7 @@ _cannot_use_tmpdir() { if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}" ; then if chmod +x "${testfile}" ; then - if [ "$("${testfile}")" = "SUCCESS" ] ; then + if [ "$("${testfile}" 2>/dev/null)" = "SUCCESS" ] ; then ret=1 fi fi @@ -199,16 +358,27 @@ get_netdata_latest_tag() { newer_commit_date() { info "Checking if a newer version of the updater script is available." + commit_check_url="https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" + python_version_check="from __future__ import print_function;import sys,json;data = json.load(sys.stdin);print(data[0]['commit']['committer']['date'] if isinstance(data, list) else '')" + if command -v jq > /dev/null 2>&1; then - commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | jq '.[0].commit.committer.date' | tr -d '"')" + commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | jq '.[0].commit.committer.date' 2>/dev/null | tr -d '"')" elif command -v python > /dev/null 2>&1;then - commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | python -c 'from __future__ import print_function;import sys,json;print(json.load(sys.stdin)[0]["commit"]["committer"]["date"])')" + commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | python -c "${python_version_check}")" elif command -v python3 > /dev/null 2>&1;then - commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | python3 -c 'from __future__ import print_function;import sys,json;print(json.load(sys.stdin)[0]["commit"]["committer"]["date"])')" + commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | python3 -c "${python_version_check}")" fi if [ -z "${commit_date}" ] ; then - commit_date="9999-12-31T23:59:59Z" + return 0 + elif [ "$(uname)" = "Linux" ]; then + commit_date="$(date -d "${commit_date}" +%s)" + else # assume BSD-style `date` if we are not on Linux + commit_date="$(/bin/date -j -f "%Y-%m-%dT%H:%M:%SZ" "${commit_date}" +%s 2>/dev/null)" + + if [ -z "${commit_date}" ]; then + return 0 + fi fi if [ -e "${script_source}" ]; then @@ -217,7 +387,7 @@ newer_commit_date() { script_date="$(date +%s)" fi - [ "$(date -d "${commit_date}" +%s)" -ge "${script_date}" ] + [ "${commit_date}" -ge "${script_date}" ] } self_update() { @@ -269,7 +439,19 @@ get_latest_version() { fi } +validate_environment_file() { + if [ -n "${RELEASE_CHANNEL}" ] && [ -n "${NETDATA_PREFIX}" ] && [ -n "${REINSTALL_OPTIONS}" ] && [ -n "${IS_NETDATA_STATIC_BINARY}" ]; then + return 0 + else + error "Environment file located at ${ENVIRONMENT_FILE} is not valid, unable to update." + fi +} + update_available() { + if [ "$NETDATA_FORCE_UPDATE" = "1" ]; then + info "Force update requested" + return 0 + fi 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}" @@ -333,10 +515,14 @@ update_build() { ndtmpdir=$(create_tmp_directory) cd "$ndtmpdir" || exit 1 + install_build_dependencies + 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 [ -n "${NETDATA_TARBALL_CHECKSUM}" ] && grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3; then + if [ -n "${NETDATA_TARBALL_CHECKSUM}" ] && + grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3 && + [ "$NETDATA_FORCE_UPDATE" != "1" ]; then info "Newest version is already installed" else if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then @@ -382,6 +568,10 @@ update_build() { install_type="INSTALL_TYPE='legacy-build'" fi + if [ "${INSTALL_TYPE}" = "custom" ] && [ -f "${NETDATA_PREFIX}" ]; then + install_type="INSTALL_TYPE='legacy-build'" + fi + info "Re-installing netdata..." eval "${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start}" >&3 2>&3 || fatal "FAILED TO COMPILE/INSTALL NETDATA" @@ -488,7 +678,7 @@ update_binpkg() { upgrade_cmd="upgrade" pkg_install_opts="${interactive_opts}" repo_update_opts="${interactive_opts}" - pkg_installed_check="dpkg -l" + pkg_installed_check="dpkg -s" INSTALL_TYPE="binpkg-deb" ;; ubuntu) @@ -497,7 +687,7 @@ update_binpkg() { upgrade_cmd="upgrade" pkg_install_opts="${interactive_opts}" repo_update_opts="${interactive_opts}" - pkg_installed_check="dpkg -l" + pkg_installed_check="dpkg -s" INSTALL_TYPE="binpkg-deb" ;; centos) @@ -574,6 +764,50 @@ ndtmpdir= trap cleanup EXIT +if [ -t 2 ]; then + # we are running on a terminal + # open fd 3 and send it to stderr + exec 3>&2 +else + # we are headless + # create a temporary file for the log + logfile="$(mktemp -t netdata-updater.log.XXXXXX)" + # open fd 3 and send it to logfile + exec 3> "${logfile}" +fi + +: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}" + +if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; then + if [ -r "${script_dir}/../../../etc/netdata/.environment" ] || [ -r "${script_dir}/../../../etc/netdata/.install-type" ]; then + ENVIRONMENT_FILE="${script_dir}/../../../etc/netdata/.environment" + elif [ -r "/etc/netdata/.environment" ] || [ -r "/etc/netdata/.install-type" ]; then + ENVIRONMENT_FILE="/etc/netdata/.environment" + elif [ -r "/opt/netdata/etc/netdata/.environment" ] || [ -r "/opt/netdata/etc/netdata/.install-type" ]; then + ENVIRONMENT_FILE="/opt/netdata/etc/netdata/.environment" + else + envpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.environment' -type f 2> /dev/null | head -n 1)" + itpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.install-type' -type f 2> /dev/null | head -n 1)" + if [ -r "${envpath}" ]; then + ENVIRONMENT_FILE="${envpath}" + elif [ -r "${itpath}" ]; then + ENVIRONMENT_FILE="$(dirname "${itpath}")/.environment" + else + fatal "Cannot find environment file or install type file, unable to update." + fi + fi +fi + +if [ -r "${ENVIRONMENT_FILE}" ] ; then + # shellcheck source=/dev/null + . "${ENVIRONMENT_FILE}" || exit 1 +fi + +if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then + # shellcheck source=/dev/null + . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || exit 1 +fi + while [ -n "${1}" ]; do if [ "${1}" = "--not-running-from-cron" ]; then NETDATA_NOT_RUNNING_FROM_CRON=1 @@ -581,9 +815,18 @@ while [ -n "${1}" ]; do elif [ "${1}" = "--no-updater-self-update" ]; then NETDATA_NO_UPDATER_SELF_UPDATE=1 shift 1 + elif [ "${1}" = "--force-update" ]; then + NETDATA_FORCE_UPDATE=1 + shift 1 elif [ "${1}" = "--tmpdir-path" ]; then NETDATA_TMPDIR_PATH="${2}" shift 2 + elif [ "${1}" = "--enable-auto-updates" ]; then + enable_netdata_updater "${2}" + exit $? + elif [ "${1}" = "--disable-auto-updates" ]; then + disable_netdata_updater + exit $? else break fi @@ -601,14 +844,6 @@ if [ ! -t 1 ] && [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ]; then sleep $(((rnd % 3600) + 1)) 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}" @@ -618,31 +853,21 @@ export NETDATA_LIB_DIR="${NETDATA_LIB_DIR:-${NETDATA_PREFIX}/var/lib/netdata}" # Grab the nightlies baseurl (defaulting to our Google Storage bucket) export NETDATA_NIGHTLIES_BASEURL="${NETDATA_NIGHTLIES_BASEURL:-https://storage.googleapis.com/netdata-nightlies}" -if [ "${INSTALL_UID}" != "$(id -u)" ]; then +if echo "$INSTALL_TYPE" | grep -qv ^binpkg && [ "${INSTALL_UID}" != "$(id -u)" ]; then fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" fi -if [ -t 2 ]; then - # we are running on a terminal - # open fd 3 and send it to stderr - exec 3>&2 -else - # we are headless - # create a temporary file for the log - logfile="$(mktemp -t netdata-updater.log.XXXXXX)" - # open fd 3 and send it to logfile - exec 3> "${logfile}" -fi - self_update # shellcheck disable=SC2153 case "${INSTALL_TYPE}" in *-build) + validate_environment_file || exit 1 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}" update_build && exit 0 ;; *-static*) + validate_environment_file || exit 1 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}" update_static && exit 0 ;; @@ -650,15 +875,16 @@ case "${INSTALL_TYPE}" in update_binpkg && exit 0 ;; "") # Fallback case for no `.install-type` file. This just works like the old install type detection. + validate_environment_file || exit 1 update_legacy ;; custom) - # At this point, we _should_ have a valid `.environment` file, but it0s best to just check. + # At this point, we _should_ have a valid `.environment` file, but it's best to just check. # If we do, then behave like the legacy updater. - if [ -n "${RELEASE_CHANNEL}" ] && [ -n "${NETDATA_PREFIX}" ] && [ -n "${REINSTALL_OPTIONS}" ]; then + if validate_environment_file; then update_legacy else - fatal "This script does not support updating custom installations." + fatal "This script does not support updating custom installations without valid environment files." fi ;; oci) |