summaryrefslogtreecommitdiffstats
path: root/packaging/installer/kickstart.sh
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/installer/kickstart.sh')
-rwxr-xr-xpackaging/installer/kickstart.sh229
1 files changed, 180 insertions, 49 deletions
diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh
index 6d9f4ea0e..dde738c28 100755
--- a/packaging/installer/kickstart.sh
+++ b/packaging/installer/kickstart.sh
@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
-# Next unused error code: F0517
+# Next unused error code: F051A
# ======================================================================
# Constants
@@ -196,6 +196,7 @@ USAGE: kickstart.sh [options]
--no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer.
--local-build-options Specify additional options to pass to the installer code when building locally. Only valid if --build-only is also specified.
--static-install-options Specify additional options to pass to the static installer code. Only valid if --static-only is also specified.
+ --offline-architecture Limit an offline install source being prepared with --prepare-offline-install-source to only include the specified static build architecture.
The following options are mutually exclusive and specifiy special operations other than trying to install Netdata normally or update an existing install:
@@ -311,23 +312,31 @@ telemetry_event() {
EOF
)"
+ succeeded=0
+
if [ -n "${CURL}" ]; then
- "${CURL}" --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null
- elif command -v wget > /dev/null 2>&1; then
- if wget --help 2>&1 | grep BusyBox > /dev/null 2>&1; then
- # BusyBox-compatible version of wget, there is no --no-check-certificate option
- wget -q -O - \
- -T 1 \
- --header 'Content-Type: application/json' \
- --post-data "${REQ_BODY}" \
- "${TELEMETRY_URL}" > /dev/null
- else
- wget -q -O - --no-check-certificate \
- --method POST \
- --timeout=1 \
- --header 'Content-Type: application/json' \
- --body-data "${REQ_BODY}" \
- "${TELEMETRY_URL}" > /dev/null
+ if "${CURL}" --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null; then
+ succeeded=1
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 0 ]; then
+ if command -v wget > /dev/null 2>&1; then
+ if wget --help 2>&1 | grep BusyBox > /dev/null 2>&1; then
+ # BusyBox-compatible version of wget, there is no --no-check-certificate option
+ wget -q -O - \
+ -T 1 \
+ --header 'Content-Type: application/json' \
+ --post-data "${REQ_BODY}" \
+ "${TELEMETRY_URL}" > /dev/null
+ else
+ wget -q -O - --no-check-certificate \
+ --method POST \
+ --timeout=1 \
+ --header 'Content-Type: application/json' \
+ --body-data "${REQ_BODY}" \
+ "${TELEMETRY_URL}" > /dev/null
+ fi
fi
fi
}
@@ -368,6 +377,15 @@ trap 'trap_handler 15 0' TERM
# ======================================================================
# Utility functions
+canonical_path() {
+ cd "$(dirname "${1}")" || exit 1
+ case "$(basename "${1}")" in
+ ..) dirname "$(pwd -P)" ;;
+ .) pwd -P ;;
+ *) echo "$(pwd -P)/$(basename "${1}")" ;;
+ esac
+}
+
setup_terminal() {
TPUT_RESET=""
TPUT_WHITE=""
@@ -534,11 +552,15 @@ run_script() {
# shellcheck disable=SC2086
run ${ROOTCMD} "${@}"
+ ret="$?"
+
if [ -r "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
# shellcheck disable=SC1090
. "${NETDATA_SCRIPT_STATUS_PATH}"
rm -f "${NETDATA_SCRIPT_STATUS_PATH}"
fi
+
+ return "${ret}"
}
warning() {
@@ -592,15 +614,38 @@ set_tmpdir() {
check_for_remote_file() {
url="${1}"
+ succeeded=0
+ checked=0
if echo "${url}" | grep -Eq "^file:///"; then
[ -e "${url#file://}" ] || return 1
+ return 0
elif [ -n "${NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT}" ]; then
return 0
- elif [ -n "${CURL}" ]; 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
+ fi
+
+ if [ -n "${CURL}" ]; then
+ checked=1
+
+ if "${CURL}" --output /dev/null --silent --head --fail "${url}"; then
+ succeeded=1
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 0 ]; then
+ if command -v wget > /dev/null 2>&1; then
+ checked=1
+
+ if wget -S --spider "${url}" 2>&1 | grep -q 'HTTP/1.1 200 OK'; then
+ succeeded=1
+ fi
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 1 ]; then
+ return 0
+ elif [ "${checked}" -eq 1 ]; then
+ return 1
else
fatal "${ERROR_F0003}" F0003
fi
@@ -609,13 +654,39 @@ check_for_remote_file() {
download() {
url="${1}"
dest="${2}"
+ succeeded=0
+ checked=0
if echo "${url}" | grep -Eq "^file:///"; then
run cp "${url#file://}" "${dest}" || return 1
- elif [ -n "${CURL}" ]; then
- run "${CURL}" --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1
- elif command -v wget > /dev/null 2>&1; then
- run wget -T 15 -O "${dest}" "${url}" || return 1
+ return 0
+ fi
+
+
+ if [ -n "${CURL}" ]; then
+ checked=1
+
+ if run "${CURL}" --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"; then
+ succeeded=1
+ else
+ rm -f "${dest}"
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 0 ]; then
+ if command -v wget > /dev/null 2>&1; then
+ checked=1
+
+ if run wget -T 15 -O "${dest}" "${url}"; then
+ succeeded=1
+ fi
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 1 ]; then
+ return 0
+ elif [ "${checked}" -eq 1 ]; then
+ return 1
else
fatal "${ERROR_F0003}" F0003
fi
@@ -639,11 +710,31 @@ get_actual_version() {
get_redirect() {
url="${1}"
+ succeeded=0
+ checked=0
if [ -n "${CURL}" ]; then
- run sh -c "${CURL} ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -Eo '[^/]+$'" || return 1
- elif command -v wget > /dev/null 2>&1; then
- run sh -c "wget -S -O /dev/null ${url} 2>&1 | grep -m 1 Location | grep -Eo '[^/]+$'" || return 1
+ checked=1
+
+ if run sh -c "${CURL} ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -Eo '[^/]+$'"; then
+ succeeded=1
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 0 ]; then
+ if command -v wget > /dev/null 2>&1; then
+ checked=1
+
+ if run sh -c "wget -S -O /dev/null ${url} 2>&1 | grep -m 1 Location | grep -Eo '[^/]+$'"; then
+ succeeded=1
+ fi
+ fi
+ fi
+
+ if [ "${succeeded}" -eq 1 ]; then
+ return 0
+ elif [ "${checked}" -eq 1 ]; then
+ return 1
else
fatal "${ERROR_F0003}" F0003
fi
@@ -802,6 +893,10 @@ update() {
opts="--interactive"
fi
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
+ export NETDATA_OFFLINE_INSTALL_SOURCE="${NETDATA_OFFLINE_INSTALL_SOURCE}"
+ fi
+
if run_script "${updater}" ${opts} --not-running-from-cron; then
progress "Updated existing install at ${ndprefix}"
return 0
@@ -870,31 +965,47 @@ detect_existing_install() {
set_tmpdir
progress "Checking for existing installations of Netdata..."
+ EXISTING_INSTALL_IS_NATIVE="0"
- if pkg_installed netdata; then
- ndprefix="/"
- EXISTING_INSTALL_IS_NATIVE="1"
+ if [ -n "${INSTALL_PREFIX}" ]; then
+ searchpath="/opt/netdata/bin:${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
- EXISTING_INSTALL_IS_NATIVE="0"
- 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
+ searchpath="/opt/netdata/bin:${PATH}"
+ fi
- ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
+ while [ -n "${searchpath}" ]; do
+ _ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
- if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ]; then
- ndpath="/opt/netdata/bin/netdata"
+ if [ -n "${_ndpath}" ]; then
+ _ndpath="$(canonical_path "${_ndpath}")"
fi
- if [ -n "${ndpath}" ]; then
- case "${ndpath}" in
- */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;;
- *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;;
- esac
+ if [ -z "${ndpath}" ] && [ -n "${_ndpath}" ]; then
+ ndpath="${_ndpath}"
+ elif [ -n "${_ndpath}" ] && [ "${ndpath}" != "${_ndpath}" ]; then
+ fatal "Multiple installs of Netdata agent detected (located at '${ndpath}' and '${_ndpath}'). Such a setup is not generally supported. If you are certain you want to operate on one of them despite this, use the '--install-prefix' option to specifiy the install you want to operate on." F0517
+ fi
+
+ if [ -n "${INSTALL_PREFIX}" ] && [ -n "${ndpath}" ]; then
+ break
+ elif [ -z "${_ndpath}" ]; then
+ break
+ elif echo "${searchpath}" | grep -v ':'; then
+ searchpath=""
+ else
+ searchpath="$(echo "${searchpath}" | cut -f 2- -d ':')"
fi
+ done
+
+ if pkg_installed netdata; then
+ ndprefix="/"
+ EXISTING_INSTALL_IS_NATIVE="1"
+ elif [ -n "${ndpath}" ]; then
+ case "${ndpath}" in
+ */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;;
+ *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;;
+ esac
if echo "${ndprefix}" | grep -Eq '^/usr$'; then
ndprefix="$(dirname "${ndprefix}")"
@@ -1705,9 +1816,15 @@ try_static_install() {
opts="${opts} --accept"
fi
+ env_cmd="env NETDATA_CERT_TEST_URL=${NETDATA_CLAIM_URL} NETDATA_CERT_MODE=check"
+
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
+ env_cmd="env NETDATA_CERT_TEST_URL=${NETDATA_CLAIM_URL} NETDATA_CERT_MODE=auto"
+ fi
+
progress "Installing netdata"
# shellcheck disable=SC2086
- if ! run_as_root sh "${tmpdir}/${netdata_agent}" ${opts} -- ${NETDATA_INSTALLER_OPTIONS}; then
+ if ! run_as_root ${env_cmd} /bin/sh "${tmpdir}/${netdata_agent}" ${opts} -- ${NETDATA_INSTALLER_OPTIONS}; then
warning "Failed to install static build of Netdata on ${SYSARCH}."
run rm -rf /opt/netdata
return 2
@@ -1915,10 +2032,10 @@ prepare_offline_install_source() {
fi
if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
- for arch in ${STATIC_INSTALL_ARCHES}; do
+ for arch in $(echo "${NETDATA_OFFLINE_ARCHES:-${STATIC_INSTALL_ARCHES}}" | awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}'); do
set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "${arch}"
- if check_for_remote_file "${NETDATA_STATIC_ARCH_URL}"; then
+ if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
progress "Fetching ${NETDATA_STATIC_ARCHIVE_URL}"
if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "netdata-${arch}-latest.gz.run"; then
warning "Failed to download static installer archive for ${arch}. ${BADNET_MSG}."
@@ -2134,6 +2251,10 @@ validate_args() {
case "${NETDATA_FORCE_METHOD}" in
native|build) fatal "Offline installs are only supported for static builds currently." F0502 ;;
esac
+
+ if [ ! -d "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
+ fatal "Offline install source must be a directory." F0519
+ fi
fi
if [ -n "${LOCAL_BUILD_OPTIONS}" ]; then
@@ -2343,9 +2464,19 @@ parse_args() {
fatal "A target directory must be specified with the --prepare-offline-install-source option." F0500
fi
;;
+ "--offline-architecture")
+ if echo "${STATIC_INSTALL_ARCHES}" | grep -qw "${2}"; then
+ NETDATA_OFFLINE_ARCHES="${NETDATA_OFFLINE_ARCHES} ${2}"
+ else
+ fatal "${2} is not a recognized static build architecture (supported architectures are ${STATIC_INSTALL_ARCHES})" F0518
+ fi
+ shift 1
+ ;;
"--offline-install-source")
if [ -d "${2}" ]; then
NETDATA_OFFLINE_INSTALL_SOURCE="${2}"
+ # shellcheck disable=SC2164
+ NETDATA_TARBALL_BASEURL="file://$(cd "${2}"; pwd)"
shift 1
else
fatal "A source directory must be specified with the --offline-install-source option." F0501