#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-or-later
# shellcheck disable=SC1090,SC1091,SC1117,SC2002,SC2034,SC2044,SC2046,SC2086,SC2129,SC2162,SC2166,SC2181
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
uniquepath() {
local path=""
while read; do
if [[ ! ${path} =~ (^|:)"${REPLY}"(:|$) ]]; then
[ ! -z "${path}" ] && path="${path}:"
path="${path}${REPLY}"
fi
done < <(echo "${PATH}" | tr ":" "\n")
[ ! -z "${path}" ] && [[ ${PATH} =~ /bin ]] && [[ ${PATH} =~ /sbin ]] && export PATH="${path}"
}
uniquepath
netdata_source_dir="$(pwd)"
installer_dir="$(dirname "${0}")"
if [ "${netdata_source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ]; then
echo >&2 "Warning: you are currently in '${netdata_source_dir}' but the installer is in '${installer_dir}'."
fi
# -----------------------------------------------------------------------------
# reload the user profile
[ -f /etc/profile ] && . /etc/profile
# make sure /etc/profile does not change our current directory
cd "${netdata_source_dir}" || exit 1
# -----------------------------------------------------------------------------
# load the required functions
if [ -f "${installer_dir}/packaging/installer/functions.sh" ]; then
source "${installer_dir}/packaging/installer/functions.sh" || exit 1
else
source "${netdata_source_dir}/packaging/installer/functions.sh" || exit 1
fi
download() {
url="${1}"
dest="${2}"
if command -v wget >/dev/null 2>&1; then
if [ -t 1 ]; then
run wget -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
else
run wget --progress=dot:mega -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
fi
elif command -v curl >/dev/null 2>&1; then
run curl "${url}" >"${dest}" || fatal "Cannot download ${url}"
else
fatal "I need curl or wget to proceed, but neither is available on this system."
fi
}
# make sure we save all commands we run
run_logfile="netdata-installer.log"
# -----------------------------------------------------------------------------
# fix PKG_CHECK_MODULES error
if [ -d /usr/share/aclocal ]; then
ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
export ACLOCAL_PATH
fi
export LC_ALL=C
umask 002
# Be nice on production environments
renice 19 $$ >/dev/null 2>/dev/null
# you can set CFLAGS before running installer
CFLAGS="${CFLAGS--O2}"
[ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
# keep a log of this command
printf "\n# " >>netdata-installer.log
date >>netdata-installer.log
printf 'CFLAGS="%s" ' "${CFLAGS}" >>netdata-installer.log
printf "%q " "$0" "${@}" >>netdata-installer.log
printf "\n" >>netdata-installer.log
REINSTALL_PWD="${PWD}"
REINSTALL_COMMAND="$(
printf "%q " "$0" "${@}"
printf "\n"
)"
# remove options that shown not be inherited by netdata-updater.sh
REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-wait/}"
REINSTALL_COMMAND=