Browse Source

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 5 years ago
parent
commit
dc38b1d15d

+ 2 - 2
packaging/installer/README.md

@@ -45,7 +45,7 @@ $ bash <(curl -Ss https://my-netdata.io/kickstart.sh)
 Verify the integrity of the script with this:
 
 ``` bash
-[ "8a2b054081a108dff915994ce77f2f2d" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
+[ "b6d16c171ccad073b86327246151d875" = "$(curl -Ss https://my-netdata.io/kickstart.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
 ```
 *It should print `OK, VALID` if the script is the one we ship.*
 
@@ -101,7 +101,7 @@ $ bash <(curl -Ss https://my-netdata.io/kickstart-static64.sh)
 Verify the integrity of the script with this:
 
 ```bash
-[ "8779d8717ccaa8dac18d599502eef591" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
+[ "4415e8c13e529a795abb953a9be14ad5" = "$(curl -Ss https://my-netdata.io/kickstart-static64.sh | md5sum | cut -d ' ' -f 1)" ] && echo "OK, VALID" || echo "FAILED, INVALID"
 ```
 
 *It should print `OK, VALID` if the script is the one we ship.*

+ 5 - 3
packaging/installer/kickstart-static64.sh

@@ -189,7 +189,7 @@ done
 
 # ---------------------------------------------------------------------------------------------------------------------
 TMPDIR=$(create_tmp_directory)
-cd "${TMPDIR}" || :
+cd "${TMPDIR}"
 
 set_tarball_urls "${RELEASE_CHANNEL}"
 progress "Downloading static netdata binary: ${NETDATA_TARBALL_URL}"
@@ -202,12 +202,14 @@ fi
 
 # ---------------------------------------------------------------------------------------------------------------------
 progress "Installing netdata"
-
 run ${sudo} sh "${TMPDIR}/netdata-latest.gz.run" ${opts} ${inner_opts}
 
 #shellcheck disable=SC2181
 if [ $? -eq 0 ]; then
-	rm "${TMPDIR}/netdata-latest.gz.run"
+	run ${sudo} rm "${TMPDIR}/netdata-latest.gz.run"
+	if [ ! "${TMPDIR}" = "/" ] && [ -d "${TMPDIR}" ]; then
+		run ${sudo} rm -rf "${TMPDIR}"
+	fi
 else
 	echo >&2 "NOTE: did not remove: ${TMPDIR}/netdata-latest.gz.run"
 fi

+ 4 - 2
packaging/installer/kickstart.sh

@@ -304,7 +304,7 @@ if [ "${INTERACTIVE}" = "0" ]; then
 fi
 
 TMPDIR=$(create_tmp_directory)
-cd ${TMPDIR} || :
+cd "${TMPDIR}"
 
 dependencies
 
@@ -328,7 +328,9 @@ cd netdata-* || fatal "Cannot cd to netdata source tree"
 if [ -x netdata-installer.sh ]; then
 	progress "Installing netdata..."
 	run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS} "${@}" || fatal "netdata-installer.sh exited with error"
-	rm -rf "${TMPDIR}" >/dev/null 2>&1
+	if [ -d "${TMPDIR}" ] && [ ! "${TMPDIR}" = "/" ]; then
+		run ${sudo} rm -rf "${TMPDIR}" >/dev/null 2>&1
+	fi
 else
 	fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${TMPDIR}"
 fi