diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2024-04-10 09:59:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 09:59:04 -0400 |
commit | 7b0a46b71c3c48ae787bc04cbd2fddafe89dedf2 (patch) | |
tree | b8e9995d543f267402d7a048254cf537f47e09f4 | |
parent | 5ce422daf086189fc8a97d77c71d5308e355025a (diff) |
kickstart: Add detection of multiple concurrent installs. (#16555)
* Add detection of multiple concurrent installs.
And refuse to operate on such setups in most cases.
* Fix exit cases for existing install detection loop.
-rwxr-xr-x | packaging/installer/kickstart.sh | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh index 8f9cc1c209..437d9ecfd1 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 @@ -874,31 +874,41 @@ 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 [ -z "${ndpath}" ]; then + ndpath="${_ndpath}" + elif [ -n "${_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 "${ndpath}" ]; then - case "${ndpath}" in - */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;; - *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;; - esac + if [ -n "${INSTALL_PREFIX}" ] && [ -n "${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}")" |