@cryptotaxi247 / netdata-1 / commits / 7a416ecdc

Made the update script significantly more robust and user friendly. (#10261)

* Fix authroship and copyright information in updater. * Better handle lack of executable installer script during updates. * Attempt to update the updater prior to running updates. * Fix kickstart script checksum.

Austin S. Hemmelgarn committed Dec 7, 2020 at 07:49 UTC 7a416ecdcba6c1f4dda389731404afa7cc62a3f3
3 files changed +97 -18
packaging/installer/kickstart.sh
+10 -2
@@ -471,12 +471,20 @@ cd netdata-* || fatal "Cannot cd to netdata source tree"
471 # ---------------------------------------------------------------------------------------------------------------------
472 # install netdata from source
473
474 -if [ -x netdata-installer.sh ]; then
474 +install() {
475 progress "Installing netdata..."
476 run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS} "${@}" || fatal "netdata-installer.sh exited with error"
477 if [ -d "${ndtmpdir}" ] && [ ! "${ndtmpdir}" = "/" ]; then
478 run ${sudo} rm -rf "${ndtmpdir}" > /dev/null 2>&1
479 fi
480 +}
481 +
482 +if [ -x netdata-installer.sh ]; then
483 + install "$@"
484 else
481 - fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${ndtmpdir}"
485 + if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
486 + cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && install "$@"
487 + else
488 + fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${ndtmpdir}"
489 + fi
490 fi
packaging/installer/methods/kickstart.md
+1 -1
@@ -61,7 +61,7 @@ To use `md5sum` to verify the intregity of the `kickstart.sh` script you will do
61 run the following:
62
63 ```bash
64 -[ "794498f7009012116aafe466d8f544ae" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
64 +[ "02efc9e5ae084ad3aff072837dbedb1c" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
65 ```
66
67 If the script is valid, this command will return `OK, VALID`.
packaging/installer/netdata-updater.sh
+86 -15
@@ -19,13 +19,17 @@
19 # - TMPDIR (set to a usable temporary directory)
20 # - NETDATA_NIGHTLIES_BASEURL (set the base url for downloading the dist tarball)
21 #
22 -# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
22 +# Copyright: 2018-2020 Netdata Inc.
23 +# SPDX-License-Identifier: GPL-3.0-or-later
24 #
25 # Author: Paweł Krupa <paulfantom@gmail.com>
26 # Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
27 +# Author: Austin S. Hemmelgarn <austin@netdata.cloud>
28
29 set -e
30
31 +script_source="$("$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)/netdata-updater.sh")"
32 +
33 info() {
34 echo >&3 "$(date) : INFO: " "${@}"
35 }
@@ -85,32 +89,85 @@ _cannot_use_tmpdir() {
89 }
90
91 create_tmp_directory() {
88 - if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
89 - if _cannot_use_tmpdir /tmp ; then
90 - if _cannot_use_tmpdir "${PWD}" ; then
91 - echo >&2
92 - echo >&2 "Unable to find a usable temprorary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again."
93 - exit 1
92 + if [ -n "${NETDATA_TMPDIR_PATH}" ]; then
93 + echo "${NETDATA_TMPDIR_PATH}"
94 + else
95 + if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
96 + if _cannot_use_tmpdir /tmp ; then
97 + if _cannot_use_tmpdir "${PWD}" ; then
98 + echo >&2
99 + echo >&2 "Unable to find a usable temprorary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again."
100 + exit 1
101 + else
102 + TMPDIR="${PWD}"
103 + fi
104 else
95 - TMPDIR="${PWD}"
105 + TMPDIR="/tmp"
106 fi
97 - else
98 - TMPDIR="/tmp"
107 fi
100 - fi
108
102 - mktemp -d -t netdata-updater-XXXXXXXXXX
109 + mktemp -d -t netdata-updater-XXXXXXXXXX
110 + fi
111 }
112
105 -download() {
113 +_safe_download() {
114 url="${1}"
115 dest="${2}"
116 if command -v curl > /dev/null 2>&1; then
109 - curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${dest}" || fatal "Cannot download ${url}"
117 + curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"
118 + return $?
119 elif command -v wget > /dev/null 2>&1; then
111 - wget -T 15 -O - "${url}" > "${dest}" || fatal "Cannot download ${url}"
120 + wget -T 15 -O - "${url}" > "${dest}"
121 + return $?
122 else
123 + return 255
124 + fi
125 +}
126 +
127 +download() {
128 + url="${1}"
129 + dest="${2}"
130 +
131 + _safe_download "${url}" "${dest}"
132 + ret=$?
133 +
134 + if [ ${ret} -eq 0 ]; then
135 + return 0
136 + elif [ ${ret} -eq 255 ]; then
137 fatal "I need curl or wget to proceed, but neither is available on this system."
138 + else
139 + fatal "Cannot download ${url}"
140 + fi
141 +}
142 +
143 +newer_commit_date() {
144 + echo >&3 "Checking if a newer version of the updater script is available."
145 +
146 + 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')"
148 + 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"])')"
150 + fi
151 +
152 + if [ -z "${commit_date}" ] ; then
153 + commit_date="1970-01-01T00:00:00Z"
154 + fi
155 +
156 + [ "$(date -d "${commit_date}" +%s)" -ge "$(date -r "${script_source}" +%s)" ]
157 +}
158 +
159 +self_update() {
160 + if [ -z "${NETDATA_NO_UPDATER_SELF_UPDATE}" ] && newer_commit_date; then
161 + echo >&3 "Downloading newest version of updater script."
162 +
163 + ndtmpdir=$(create_tmp_directory)
164 + cd "$ndtmpdir" || exit 1
165 +
166 + if _safe_download "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-updater.sh" ./netdata-updater.sh; then
167 + exec ./netdata-updater.sh --not-running-from-cron --no-self-update --tmpdir-path "$(pwd)"
168 + else
169 + echo >&3 "Failed to download newest version of updater script, continuing with current version."
170 + fi
171 fi
172 }
173
@@ -221,6 +278,12 @@ update() {
278 env="NETDATA_SELECTED_DASHBOARD=${NETDATA_SELECTED_DASHBOARD}"
279 fi
280
281 + if [ ! -x ./netdata-installer.sh ]; then
282 + if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
283 + cd "$(find . -mindepth 1 -maxdepth 1 -type d)" || exit 1
284 + fi
285 + fi
286 +
287 info "Re-installing netdata..."
288 eval "${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start}" >&3 2>&3 || fatal "FAILED TO COMPILE/INSTALL NETDATA"
289
@@ -246,6 +309,12 @@ while [ -n "${1}" ]; do
309 if [ "${1}" = "--not-running-from-cron" ]; then
310 NETDATA_NOT_RUNNING_FROM_CRON=1
311 shift 1
312 + elif [ "${1}" = "--no-updater-self-update" ]; then
313 + NETDATA_NO_UPDATER_SELF_UPDATE=1
314 + shift 1
315 + elif [ "${1}" = "--tempdir-path" ]; then
316 + NETDATA_TMPDIR_PATH="${2}"
317 + shift 2
318 else
319 break
320 fi
@@ -290,6 +359,8 @@ else
359 exec 3> "${logfile}"
360 fi
361
362 +self_update
363 +
364 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
365
366 if [ "${IS_NETDATA_STATIC_BINARY}" == "yes" ]; then