@cryptotaxi247 / netdata-1 / commits / 19dd150ac

Fixed handling of self-updating in updater script. (#10352)

* Fixed handling of self-updating in updater script. * Get rid of duplicate quoting. * Fix update logic to always download updater if we can’t find date for last commit. * Fix Python JSON parsing code. * Mark new updater script executable before running it.

Austin S. Hemmelgarn committed Dec 9, 2020 at 13:43 UTC 19dd150acf48f3f83ee66edd82a54193d6921130
1 file changed +19 -6
packaging/installer/netdata-updater.sh
+19 -6
@@ -28,7 +28,13 @@
28
29 set -e
30
31 -script_source="$("$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)/netdata-updater.sh")"
31 +script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
32 +
33 +if [ -x "${script_dir}/netdata-updater" ]; then
34 + script_source="${script_dir}/netdata-updater"
35 +else
36 + script_source="${script_dir}/netdata-updater.sh"
37 +fi
38
39 info() {
40 echo >&3 "$(date) : INFO: " "${@}"
@@ -144,16 +150,22 @@ newer_commit_date() {
150 echo >&3 "Checking if a newer version of the updater script is available."
151
152 if command -v jq > /dev/null 2>&1; then
147 - commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | jq '.[0].commit.committer.date')"
153 + commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | jq '.[0].commit.committer.date' | tr -d '"')"
154 elif command -v python > /dev/null 2>&1;then
149 - commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | python -c 'from __future__ import print_function;import sys,json;print(json.load(sys.stdin)["commit"]["committer"]["date"])')"
155 + commit_date="$(_safe_download "https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1" /dev/stdout | python -c 'from __future__ import print_function;import sys,json;print(json.load(sys.stdin)[0]["commit"]["committer"]["date"])')"
156 fi
157
158 if [ -z "${commit_date}" ] ; then
153 - commit_date="1970-01-01T00:00:00Z"
159 + commit_date="9999-12-31T23:59:59Z"
160 + fi
161 +
162 + if [ -e "${script_source}" ]; then
163 + script_date="$(date -r "${script_source}" +%s)"
164 + else
165 + script_date="$(date +%s)"
166 fi
167
156 - [ "$(date -d "${commit_date}" +%s)" -ge "$(date -r "${script_source}" +%s)" ]
168 + [ "$(date -d "${commit_date}" +%s)" -ge "${script_date}" ]
169 }
170
171 self_update() {
@@ -164,6 +176,7 @@ self_update() {
176 cd "$ndtmpdir" || exit 1
177
178 if _safe_download "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-updater.sh" ./netdata-updater.sh; then
179 + chmod +x ./netdata-updater.sh || exit 1
180 exec ./netdata-updater.sh --not-running-from-cron --no-self-update --tmpdir-path "$(pwd)"
181 else
182 echo >&3 "Failed to download newest version of updater script, continuing with current version."
@@ -312,7 +325,7 @@ while [ -n "${1}" ]; do
325 elif [ "${1}" = "--no-updater-self-update" ]; then
326 NETDATA_NO_UPDATER_SELF_UPDATE=1
327 shift 1
315 - elif [ "${1}" = "--tempdir-path" ]; then
328 + elif [ "${1}" = "--tmpdir-path" ]; then
329 NETDATA_TMPDIR_PATH="${2}"
330 shift 2
331 else