Allow updates without environment files in some cases. (#12400)
Specifically, if there is a valid install type file _and_ the insall is a binpkg-type install, we don’t need an environment file so we shouldn’t fail if one is missing. Also adds better validation of the environment file before attempting to update when we do need it.
Austin S. Hemmelgarn committed
Mar 21, 2022 at 07:07 UTC
e778ed51f9bb9b833a19970486764945cdbb7188
1 file changed
+25
-9
packaging/installer/netdata-updater.sh
+25
-9
@@ -64,18 +64,21 @@ fatal() {
64
: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}"
65
66
if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; then
67
- if [ -r "${script_dir}/../../../etc/netdata/.environment" ]; then
67
+ if [ -r "${script_dir}/../../../etc/netdata/.environment" ] || [ -r "${script_dir}/../../../etc/netdata/.install-type" ]; then
68
ENVIRONMENT_FILE="${script_dir}/../../../etc/netdata/.environment"
69
- elif [ -r "/etc/netdata/.environment" ]; then
69
+ elif [ -r "/etc/netdata/.environment" ] || [ -r "/etc/netdata/.install-type" ]; then
70
ENVIRONMENT_FILE="/etc/netdata/.environment"
71
- elif [ -r "/opt/netdata/etc/netdata/.environment" ]; then
71
+ elif [ -r "/opt/netdata/etc/netdata/.environment" ] || [ -r "/opt/netdata/etc/netdata/.install-type" ]; then
72
ENVIRONMENT_FILE="/opt/netdata/etc/netdata/.environment"
73
else
74
envpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.environment' -type f 2> /dev/null | head -n 1)"
75
+ itpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.install-type' -type f 2> /dev/null | head -n 1)"
76
if [ -r "${envpath}" ]; then
77
ENVIRONMENT_FILE="${envpath}"
78
+ elif [ -r "${itpath}" ]; then
79
+ ENVIRONMENT_FILE="$(dirname "${itpath}")/.environment"
80
else
78
- fatal "Cannot find environment file, unable to update."
81
+ fatal "Cannot find environment file or install type file, unable to update."
82
fi
83
fi
84
fi
@@ -452,6 +455,14 @@ get_latest_version() {
455
fi
456
}
457
458
+validate_environment_file() {
459
+ if [ -n "${RELEASE_CHANNEL}" ] && [ -n "${NETDATA_PREFIX}" ] && [ -n "${REINSTALL_OPTIONS}" ] && [ -n "${IS_NETDATA_STATIC_BINARY}" ]; then
460
+ return 0
461
+ else
462
+ error "Environment file located at ${ENVIRONMENT_FILE} is not valid, unable to update."
463
+ fi
464
+}
465
+
466
update_available() {
467
basepath="$(dirname "$(dirname "$(dirname "${NETDATA_LIB_DIR}")")")"
468
searchpath="${basepath}/bin:${basepath}/sbin:${basepath}/usr/bin:${basepath}/usr/sbin:${PATH}"
@@ -763,10 +774,12 @@ ndtmpdir=
774
775
trap cleanup EXIT
776
766
-# shellcheck source=/dev/null
767
-. "${ENVIRONMENT_FILE}" || exit 1
777
+if [ -r "${ENVIRONMENT_FILE}" ] ; then
778
+ # shellcheck source=/dev/null
779
+ . "${ENVIRONMENT_FILE}" || exit 1
780
+fi
781
769
-if [ -f "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
782
+if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
783
# shellcheck source=/dev/null
784
. "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || exit 1
785
fi
@@ -834,10 +847,12 @@ self_update
847
# shellcheck disable=SC2153
848
case "${INSTALL_TYPE}" in
849
*-build)
850
+ validate_environment_file || exit 1
851
set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
852
update_build && exit 0
853
;;
854
*-static*)
855
+ validate_environment_file || exit 1
856
set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
857
update_static && exit 0
858
;;
@@ -845,15 +860,16 @@ case "${INSTALL_TYPE}" in
860
update_binpkg && exit 0
861
;;
862
"") # Fallback case for no `.install-type` file. This just works like the old install type detection.
863
+ validate_environment_file || exit 1
864
update_legacy
865
;;
866
custom)
867
# At this point, we _should_ have a valid `.environment` file, but it's best to just check.
868
# If we do, then behave like the legacy updater.
853
- if [ -n "${RELEASE_CHANNEL}" ] && [ -n "${NETDATA_PREFIX}" ] && [ -n "${REINSTALL_OPTIONS}" ]; then
869
+ if validate_environment_file; then
870
update_legacy
871
else
856
- fatal "This script does not support updating custom installations."
872
+ fatal "This script does not support updating custom installations without valid environment files."
873
fi
874
;;
875
oci)