diff options
author | Austin S. Hemmelgarn <austin@netdata.cloud> | 2024-04-10 14:03:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 14:03:28 -0400 |
commit | 532671b2430d5b84e13463b30d5f026887485a1f (patch) | |
tree | bfdff00e17499e36b90460b7acc0a7274c4f6c59 | |
parent | bd57b7511d17f1d90c5fefd209bdf44b92e030c7 (diff) |
Canonicalize paths before comparison when checking for multiple installs. (#17373)
For some arcane reason, many distros that have chose a merged `/usr`
layout (https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/)
insist on still putting both `/bin` and `/usr/bin` (and `/sbin` and
`/usr/sbin`) in their default `$PATH`, despite the fact that this
provides no real benefit (it’s questionable even for ‘backwards
compatibility’, anything that truly _needs_ this on a system with a
merged `/usr` layout is fundamentally broken).
To correctly handle the fact that it’s not only possible but actually
extremely likely that Netdata will show up in more than one place in
`$PATH` even if it’s a single install, we need to canonicalize the paths
before comparing them when checking for multiple installs.
Unfortunately, despite path canonicalization being an extremely common
need, there is no POSIX utility for doing it with arbitrary paths,
so we have to resort to some trickery to achieve this portably. The
exact implementation used by this change is somewhat naive and only
works if the directory the target path indicates actually exists, but we
can count on this being the case in this particular usage because we
know that we found a file within that directory.
-rwxr-xr-x | packaging/installer/kickstart.sh | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/packaging/installer/kickstart.sh b/packaging/installer/kickstart.sh index 60fd3c91c0..991eac8ed1 100755 --- a/packaging/installer/kickstart.sh +++ b/packaging/installer/kickstart.sh @@ -368,6 +368,15 @@ trap 'trap_handler 15 0' TERM # ====================================================================== # Utility functions +cannonical_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="" @@ -886,6 +895,10 @@ detect_existing_install() { while [ -n "${searchpath}" ]; do _ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)" + if [ -n "${_ndpath}" ]; then + _ndpath="$(canonical_path "$(ndpath)")" + fi + if [ -z "${ndpath}" ] && [ -n "${_ndpath}" ]; then ndpath="${_ndpath}" elif [ -n "${_ndpath}" ] && [ "${ndpath}" != "${_ndpath}" ]; then |