@cryptotaxi247 / netdata-1 / commits / eb42d2ad4

Add better checks for existing installs to the kickstart scripts. (#9408)

* Added better checks for existing installs to the kickstart scripts. This adds more robust checks to our Kickstart install scripts to prevent users from accidentally installing Netdata over top of an existing install (which can lead to all kinds of problematic situations). The logic for these checks works as follows: - See if `netdata` is located somewhere in `$PATH` (using `command -v`), and if present assume there's an existing install. - Otherwise, check if `/opt/netdata/bin/netdata` exists, if so assume there's an existing install, otherwise continue under the assumption there isn't. - If there is an existing install, check if it's one done through our install scripts, if not stop the installation process. - If it is one of our installs, look for and attempt to use the updater script to update the existing install (exiting with an error message if that fails). This also adds a switch called '--allow-duplicate-install' which will cause the install to continue if it would normally refuse to continue due to an existing install. * Update checksums. * Address feedback from @prologic.

Austin S. Hemmelgarn committed Jul 20, 2020 at 07:25 UTC eb42d2ad43680e0aa71dca21adb40cfcf2b505e8
4 files changed +104 -22
packaging/installer/kickstart-static64.sh
+56 -6
@@ -4,12 +4,13 @@
4 # shellcheck disable=SC1117,SC2039,SC2059,SC2086
5 #
6 # Options to run
7 -# --dont-wait do not wait for input
8 -# --non-interactive do not wait for input
9 -# --dont-start-it do not start netdata after install
10 -# --stable-channel Use the stable release channel, rather than the nightly to fetch sources
11 -# --disable-telemetry Opt-out of anonymous telemetry program (DO_NOT_TRACK=1)
12 -# --local-files Use a manually provided tarball for the installation
7 +# --dont-wait do not wait for input
8 +# --non-interactive do not wait for input
9 +# --dont-start-it do not start netdata after install
10 +# --stable-channel Use the stable release channel, rather than the nightly to fetch sources
11 +# --disable-telemetry Opt-out of anonymous telemetry program (DO_NOT_TRACK=1)
12 +# --local-files Use a manually provided tarball for the installation
13 +# --allow-duplicate-install do not bail if we detect a duplicate install
14 #
15 # Environment options:
16 #
@@ -179,6 +180,52 @@ sudo=""
180 [ -z "${UID}" ] && UID="$(id -u)"
181 [ "${UID}" -ne "0" ] && sudo="sudo"
182
183 +# ---------------------------------------------------------------------------------------------------------------------
184 +# look for an existing install and try to update that instead if it exists
185 +
186 +ndpath="$(command -v netdata 2>/dev/null)"
187 +if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
188 + ndpath="/opt/netdata/bin/netdata"
189 +fi
190 +
191 +if [ -n "$ndpath" ] ; then
192 + ndprefix="$(dirname "$(dirname "${ndpath}")")"
193 +
194 + if [ "${ndprefix}" = /usr ] ; then
195 + ndprefix="/"
196 + fi
197 +
198 + progress "Found existing install of Netdata under: ${ndprefix}"
199 +
200 + if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
201 + if [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
202 + progress "Attempting to update existing install instead of creating a new one"
203 + if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ; then
204 + progress "Updated existing install at ${ndpath}"
205 + exit 0
206 + else
207 + fatal "Failed to update existing Netdata install"
208 + exit 1
209 + fi
210 + else
211 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
212 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
213 + exit 1
214 + else
215 + progress "User explicitly requested duplicate install, proceeding."
216 + fi
217 + fi
218 + else
219 + progress "Existing install appears to be handled manually or through the system package manager."
220 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
221 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
222 + exit 1
223 + else
224 + progress "User explicitly requested duplicate install, proceeding."
225 + fi
226 + fi
227 +fi
228 +
229 # ----------------------------------------------------------------------------
230 if [ "$(uname -m)" != "x86_64" ]; then
231 fatal "Static binary versions of netdata are available only for 64bit Intel/AMD CPUs (x86_64), but yours is: $(uname -m)."
@@ -228,6 +275,9 @@ while [ -n "${1}" ]; do
275
276 NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${1}"
277 shift 1
278 + elif [ "${1}" = "--allow-duplicate-install" ]; then
279 + NETDATA_ALLOW_DUPLICATE_INSTALL=1
280 + shift 1
281 else
282 echo >&2 "Unknown option '${1}' or invalid number of arguments. Please check the README for the available arguments of ${0} and try again"
283 exit 1
packaging/installer/kickstart.sh
+46 -14
@@ -14,6 +14,7 @@
14 # --non-interactive do not prompt for user input
15 # --no-updates do not install script for daily updates
16 # --local-files set the full path of the desired tarball to run install with
17 +# --allow-duplicate-install do not bail if we detect a duplicate install
18 #
19 # Environment options:
20 #
@@ -278,21 +279,49 @@ sudo=""
279 export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
280
281 # ---------------------------------------------------------------------------------------------------------------------
281 -# try to update using autoupdater in the first place
282 -
283 -updater=""
284 -[ -x /etc/periodic/daily/netdata-updater ] && updater=/etc/periodic/daily/netdata-updater
285 -[ -x /etc/cron.daily/netdata-updater ] && updater=/etc/cron.daily/netdata-updater
286 -if [ -L "${updater}" ]; then
287 - # remove old updater (symlink)
288 - run ${sudo} rm -f "${updater}"
289 - updater=""
282 +# look for an existing install and try to update that instead if it exists
283 +
284 +ndpath="$(command -v netdata 2>/dev/null)"
285 +if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
286 + ndpath="/opt/netdata/bin/netdata"
287 fi
291 -if [ -n "${updater}" ]; then
292 - # attempt to run the updater, to respect any compilation settings already in place
293 - progress "Re-installing netdata..."
294 - run ${sudo} "${updater}" -f || fatal "Failed to forcefully update netdata"
295 - exit 0
288 +
289 +if [ -n "$ndpath" ] ; then
290 + ndprefix="$(dirname "$(dirname "${ndpath}")")"
291 +
292 + if [ "${ndprefix}" = /usr ] ; then
293 + ndprefix="/"
294 + fi
295 +
296 + progress "Found existing install of Netdata under: ${ndprefix}"
297 +
298 + if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
299 + if [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
300 + progress "Attempting to update existing install instead of creating a new one"
301 + if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ; then
302 + progress "Updated existing install at ${ndpath}"
303 + exit 0
304 + else
305 + fatal "Failed to update existing Netdata install"
306 + exit 1
307 + fi
308 + else
309 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
310 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
311 + exit 1
312 + else
313 + progress "User explicitly requested duplicate install, proceeding."
314 + fi
315 + fi
316 + else
317 + progress "Existing install appears to be handled manually or through the system package manager."
318 + if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
319 + fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
320 + exit 1
321 + else
322 + progress "User explicitly requested duplicate install, proceeding."
323 + fi
324 + fi
325 fi
326
327 # ---------------------------------------------------------------------------------------------------------------------
@@ -318,6 +347,9 @@ while [ -n "${1}" ]; do
347 RELEASE_CHANNEL="stable"
348 NETDATA_INSTALLER_OPTIONS="$NETDATA_INSTALLER_OPTIONS --stable-channel"
349 shift 1
350 + elif [ "${1}" = "--allow-duplicate-install" ]; then
351 + NETDATA_ALLOW_DUPLICATE_INSTALL=1
352 + shift 1
353 elif [ "${1}" = "--local-files" ]; then
354 shift 1
355 if [ -z "${1}" ]; then
packaging/installer/methods/kickstart-64.md
+1 -1
@@ -77,7 +77,7 @@ To use `md5sum` to verify the intregity of the `kickstart-static64.sh` script yo
77 command above, run the following:
78
79 ```bash
80 -[ "ff717737ccc2212a3363dad7fa8bd20d" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
80 +[ "f47630f78c0c5e651cb6788301d8e05c" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
81 ```
82
83 If the script is valid, this command will return `OK, VALID`.
packaging/installer/methods/kickstart.md
+1 -1
@@ -58,7 +58,7 @@ To use `md5sum` to verify the intregity of the `kickstart.sh` script you will do
58 run the following:
59
60 ```bash
61 -[ "2057599f8b11ce56f85aa7f26ce7b15b" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
61 +[ "05e3a23be90de1c2c62b2dbd8a3fb682" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
62 ```
63
64 If the script is valid, this command will return `OK, VALID`.