@cryptotaxi247 / netdata-1 / commits / dc38b1d15

netdata/installer: Fix error running kickstart as a non-privileged user (#6642)

* netdata/packaging: fix kickstart clean up process and others 1) when TMPDIR fails to be created (cd wont work), fail over to /tmp otherwise its going to write on / which is, well, wrong (we had rm based on TMPDIR) 2) make sure we remove the directories too when clean up and always include sudo variable, to handle situations of non-root executions 3) When deleting the dir, be extra sure it's not / or the /tmp itself * netdata/packaging: sh friendly conditionals * netdata/packaging: fix md5sum on documentation * netdata/installer: enter the tmpdir in the failover case too * netdata/installer: simplify - we dont expect mktemp to fail, if it does then something is wrong so dont make cd a soft error. simplify conditionals also * netdata/installer: update md5sum

Paul Emm. Katsoulakis committed Aug 13, 2019 at 14:40 UTC dc38b1d15df2d07f65c0f3c8f8f944fbcc89a574
3 files changed +11 -7
packaging/installer/README.md
+2 -2
@@ -45,7 +45,7 @@ $ bash <(curl -Ss https://my-netdata.io/kickstart.sh)
45 Verify the integrity of the script with this:
46
47 ``` bash
48 -[ "8a2b054081a108dff915994ce77f2f2d" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
48 +[ "b6d16c171ccad073b86327246151d875" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
49 ```
50 *It should print `OK, VALID` if the script is the one we ship.*
51
@@ -101,7 +101,7 @@ $ bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh)
101 Verify the integrity of the script with this:
102
103 ```bash
104 -[ "8779d8717ccaa8dac18d599502eef591" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
104 +[ "4415e8c13e529a795abb953a9be14ad5" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
105 ```
106
107 *It should print `OK, VALID` if the script is the one we ship.*
packaging/installer/kickstart-static64.sh
+5 -3
@@ -189,7 +189,7 @@ done
189
190 # ---------------------------------------------------------------------------------------------------------------------
191 TMPDIR=$(create_tmp_directory)
192 -cd "${TMPDIR}" || :
192 +cd "${TMPDIR}"
193
194 set_tarball_urls "${RELEASE_CHANNEL}"
195 progress "Downloading static netdata binary: ${NETDATA_TARBALL_URL}"
@@ -202,12 +202,14 @@ fi
202
203 # ---------------------------------------------------------------------------------------------------------------------
204 progress "Installing netdata"
205 -
205 run ${sudo} sh "${TMPDIR}/netdata-latest.gz.run" ${opts} ${inner_opts}
206
207 #shellcheck disable=SC2181
208 if [ $? -eq 0 ]; then
210 - rm "${TMPDIR}/netdata-latest.gz.run"
209 + run ${sudo} rm "${TMPDIR}/netdata-latest.gz.run"
210 + if [ ! "${TMPDIR}" = "/" ] && [ -d "${TMPDIR}" ]; then
211 + run ${sudo} rm -rf "${TMPDIR}"
212 + fi
213 else
214 echo >&2 "NOTE: did not remove: ${TMPDIR}/netdata-latest.gz.run"
215 fi
packaging/installer/kickstart.sh
+4 -2
@@ -304,7 +304,7 @@ if [ "${INTERACTIVE}" = "0" ]; then
304 fi
305
306 TMPDIR=$(create_tmp_directory)
307 -cd ${TMPDIR} || :
307 +cd "${TMPDIR}"
308
309 dependencies
310
@@ -328,7 +328,9 @@ cd netdata-* || fatal "Cannot cd to netdata source tree"
328 if [ -x netdata-installer.sh ]; then
329 progress "Installing netdata..."
330 run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS} "${@}" || fatal "netdata-installer.sh exited with error"
331 - rm -rf "${TMPDIR}" >/dev/null 2>&1
331 + if [ -d "${TMPDIR}" ] && [ ! "${TMPDIR}" = "/" ]; then
332 + run ${sudo} rm -rf "${TMPDIR}" >/dev/null 2>&1
333 + fi
334 else
335 fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${TMPDIR}"
336 fi