diff options
Diffstat (limited to 'packaging/installer')
-rw-r--r-- | packaging/installer/functions.sh | 52 | ||||
-rwxr-xr-x | packaging/installer/kickstart.sh | 194 | ||||
-rwxr-xr-x | packaging/installer/netdata-uninstaller.sh | 5 | ||||
-rwxr-xr-x | packaging/installer/netdata-updater.sh | 48 |
4 files changed, 238 insertions, 61 deletions
diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index 9060930ce2..d636ddcff8 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -103,13 +103,33 @@ check_for_curl() { get() { url="${1}" + checked=0 + succeeded=0 check_for_curl if [ -n "${curl}" ]; then - "${curl}" -q -o - -sSL --connect-timeout 10 --retry 3 "${url}" - elif command -v wget > /dev/null 2>&1; then - wget -T 15 -O - "${url}" + checked=1 + + if "${curl}" -q -o - -sSL --connect-timeout 10 --retry 3 "${url}"; then + succeeded=1 + fi + fi + + if [ "${succeeded}" -eq 0 ]; then + if command -v wget > /dev/null 2>&1; then + checked=1 + + if wget -T 15 -O - "${url}"; then + succeeded=1 + fi + fi + fi + + if [ "${succeeded}" -eq 1 ]; then + return 0 + elif [ "${checked}" -eq 1 ]; then + return 1 else fatal "I need curl or wget to proceed, but neither is available on this system." "L0002" fi @@ -124,9 +144,29 @@ download_file() { check_for_curl if [ -n "${curl}" ]; then - run "${curl}" -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" - elif command -v wget > /dev/null 2>&1; then - run wget -T 15 -O "${dest}" "${url}" + checked=1 + + if run "${curl}" -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 echo >&2 echo >&2 "Downloading ${name} from '${url}' failed because of missing mandatory packages." diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh index 8f9cc1c209..dc81264b66 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: F0518 # ====================================================================== # Constants @@ -311,23 +311,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 +376,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="" @@ -596,15 +613,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 @@ -613,13 +653,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 @@ -643,11 +709,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 @@ -874,32 +960,48 @@ 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}")" fi diff --git a/packaging/installer/netdata-uninstaller.sh b/packaging/installer/netdata-uninstaller.sh index dcd9d965de..1627ca6b5d 100755 --- a/packaging/installer/netdata-uninstaller.sh +++ b/packaging/installer/netdata-uninstaller.sh @@ -723,6 +723,10 @@ trap quit_msg EXIT info "Stopping a possibly running netdata..." stop_all_netdata +if [ "$(uname -s)" = "Darwin" ]; then + launchctl unload /Library/LaunchDaemons/com.github.netdata.plist 2>/dev/null +fi + #### REMOVE NETDATA FILES rm_file /etc/logrotate.d/netdata rm_file /etc/systemd/system/netdata.service @@ -741,6 +745,7 @@ rm_file /etc/periodic/daily/netdata-updater rm_file /etc/cron.daily/netdata-updater rm_file /etc/cron.d/netdata-updater rm_file /etc/cron.d/netdata-updater-daily +rm_file /Library/LaunchDaemons/com.github.netdata.plist if [ -n "${NETDATA_PREFIX}" ] && [ -d "${NETDATA_PREFIX}" ] && [ "netdata" = "$(basename "$NETDATA_PREFIX")" ] ; then diff --git a/packaging/installer/netdata-updater.sh b/packaging/installer/netdata-updater.sh index 220de6e4c5..4242721867 100755 --- a/packaging/installer/netdata-updater.sh +++ b/packaging/installer/netdata-updater.sh @@ -396,15 +396,37 @@ check_for_curl() { _safe_download() { url="${1}" dest="${2}" + succeeded=0 + checked=0 check_for_curl if [ -n "${curl}" ]; then - "${curl}" -fsSL --connect-timeout 10 --retry 3 "${url}" > "${dest}" - return $? - elif command -v wget > /dev/null 2>&1; then - wget -T 15 -O - "${url}" > "${dest}" - return $? + checked=1 + + if "${curl}" -fsSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"; 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 wget -T 15 -O - "${url}" > "${dest}"; then + succeeded=1 + else + rm -f "${dest}" + fi + fi + fi + + if [ "${succeeded}" -eq 1 ]; then + return 0 + elif [ "${checked}" -eq 1 ]; then + return 1 else return 255 fi @@ -432,13 +454,21 @@ get_netdata_latest_tag() { check_for_curl if [ -n "${curl}" ]; then - tag=$("${curl}" "${url}" -s -L -I -o /dev/null -w '%{url_effective}' | grep -Eom 1 '[^/]*/?$') - elif command -v wget >/dev/null 2>&1; then - tag=$(wget -S -O /dev/null "${url}" 2>&1 | grep -m 1 Location | grep -Eo '[^/]*/?$') - else + tag=$("${curl}" "${url}" -s -L -I -o /dev/null -w '%{url_effective}') + fi + + if [ -z "${tag}" ]; then + if command -v wget >/dev/null 2>&1; then + tag=$(wget -S -O /dev/null "${url}" 2>&1 | grep Location) + fi + fi + + if [ -z "${tag}" ]; then fatal "I need curl or wget to proceed, but neither of them are available on this system." U0006 fi + tag="$(echo "${tag}" | grep -Eom 1 '[^/]*/?$')" + # Fallback case for simpler local testing. if echo "${tag}" | grep -Eq 'latest/?$'; then if _safe_download "${url}/latest-version.txt" ./ndupdate-version.txt; then |