@cryptotaxi247 / netdata-1 / commits / fca2598c7

Fixed handling of environment file in updater script. (#10447)

Currently, when the script auto-updates, it is unable to find the environment file in many cases due to a coding oversight. This updates the script to pass the environment file path to the updated copy, as well as more robustly looking for the file itself instead of just failing if it was not substituted in during install.

Austin S. Hemmelgarn committed Jan 12, 2021 at 07:32 UTC fca2598c792dc9ce3138a28c7750537670eef478
1 file changed +22 -4
packaging/installer/netdata-updater.sh
+22 -4
@@ -44,6 +44,26 @@ error() {
44 echo >&3 "$(date) : ERROR: " "${@}"
45 }
46
47 +: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}"
48 +
49 +if [ "${ENVIRONMENT_FILE}" == "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; then
50 + if [ -r "${script_dir}/../../../etc/netdata/.environment" ]; then
51 + ENVIRONMENT_FILE="${script_dir}/../../../etc/netdata/.environment"
52 + elif [ -r "/etc/netdata/.environment" ]; then
53 + ENVIRONMENT_FILE="/etc/netdata/.environment"
54 + elif [ -r "/opt/netdata/etc/netdata/.environment" ]; then
55 + ENVIRONMENT_FILE="/opt/netdata/etc/netdata/.environment"
56 + else
57 + 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)"
58 + if [ -r "${envpath}" ]; then
59 + ENVIRONMENT_FILE="${envpath}"
60 + else
61 + error "Cannot find environment file, unable to update."
62 + exit 1
63 + fi
64 + fi
65 +fi
66 +
67 safe_sha256sum() {
68 # Within the contexct of the installer, we only use -c option that is common between the two commands
69 # We will have to reconsider if we start non-common options
@@ -183,7 +203,8 @@ self_update() {
203
204 if _safe_download "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-updater.sh" ./netdata-updater.sh; then
205 chmod +x ./netdata-updater.sh || exit 1
186 - exec ./netdata-updater.sh --not-running-from-cron --no-self-update --tmpdir-path "$(pwd)"
206 + export ENVIRONMENT_FILE="${ENVIRONMENT_FILE}"
207 + exec ./netdata-updater.sh --not-running-from-cron --no-self-update --tmpdir-path "$(pwd)"
208 else
209 echo >&3 "Failed to download newest version of updater script, continuing with current version."
210 fi
@@ -347,9 +368,6 @@ if [ ! -t 1 ] && [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ]; then
368 sleep $(((RANDOM % 3600) + 1))
369 fi
370
350 -# Usually stored in /etc/netdata/.environment
351 -: "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}"
352 -
371 # shellcheck source=/dev/null
372 source "${ENVIRONMENT_FILE}" || exit 1
373