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.
Austin S. Hemmelgarn committed
Apr 10, 2024 at 09:59 UTC
7b0a46b71c3c48ae787bc04cbd2fddafe89dedf2
1 file changed
+29
-19
packaging/installer/kickstart.sh
+29
-19
@@ -2,7 +2,7 @@
2
#
3
# SPDX-License-Identifier: GPL-3.0-or-later
4
#
5
-# Next unused error code: F0517
5
+# Next unused error code: F0518
6
7
# ======================================================================
8
# Constants
@@ -874,31 +874,41 @@ detect_existing_install() {
874
set_tmpdir
875
876
progress "Checking for existing installations of Netdata..."
877
+ EXISTING_INSTALL_IS_NATIVE="0"
878
878
- if pkg_installed netdata; then
879
- ndprefix="/"
880
- EXISTING_INSTALL_IS_NATIVE="1"
879
+ if [ -n "${INSTALL_PREFIX}" ]; then
880
+ searchpath="/opt/netdata/bin:${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
881
+ searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}"
882
else
882
- EXISTING_INSTALL_IS_NATIVE="0"
883
- if [ -n "${INSTALL_PREFIX}" ]; then
884
- searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
885
- searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}"
886
- else
887
- searchpath="${PATH}"
888
- fi
883
+ searchpath="/opt/netdata/bin:${PATH}"
884
+ fi
885
890
- ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
886
+ while [ -n "${searchpath}" ]; do
887
+ _ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
888
892
- if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ]; then
893
- ndpath="/opt/netdata/bin/netdata"
889
+ if [ -z "${ndpath}" ]; then
890
+ ndpath="${_ndpath}"
891
+ elif [ -n "${_ndpath}" ]; then
892
+ 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
893
fi
894
896
- if [ -n "${ndpath}" ]; then
897
- case "${ndpath}" in
898
- */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;;
899
- *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;;
900
- esac
895
+ if [ -n "${INSTALL_PREFIX}" ] && [ -n "${ndpath}" ]; then
896
+ break
897
+ elif echo "${searchpath}" | grep -v ':'; then
898
+ searchpath=""
899
+ else
900
+ searchpath="$(echo "${searchpath}" | cut -f 2- -d ':')"
901
fi
902
+ done
903
+
904
+ if pkg_installed netdata; then
905
+ ndprefix="/"
906
+ EXISTING_INSTALL_IS_NATIVE="1"
907
+ elif [ -n "${ndpath}" ]; then
908
+ case "${ndpath}" in
909
+ */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;;
910
+ *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;;
911
+ esac
912
913
if echo "${ndprefix}" | grep -Eq '^/usr$'; then
914
ndprefix="$(dirname "${ndprefix}")"