summaryrefslogtreecommitdiffstats
path: root/netdata-installer.sh
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2020-08-27 07:17:39 -0400
committerGitHub <noreply@github.com>2020-08-27 07:17:39 -0400
commit9c3b49ee99c1cbadff983a362733cd283a4fc783 (patch)
treeb4b4f5f39583d3030e8ce8958e467ffc15800966 /netdata-installer.sh
parentf01cec0216d77b580a6b518ec1379cdb337d2d7f (diff)
Improved temporary directory checking in installer and updater. (#9797)
Update temporary directory checking in installer. This updates the checks that our installer and updater make to choose what to use for a temporary directory to be both more robust and more portable. The new checks use the following logic: * For each directory to be checked, verify that it is both writable by the current user, and that the current user can execute files they write there. * If `$TMPDIR` is set, preferentially use that. * If that fials, try `/tmp`. * If that also fails, fall back to `$PWD`. * If all checks fail, bail early with an explanation instead of failing when we first tryto do things with the directory. It also adds the same checks to the `netdata-installer.sh` script, which was previously completely missing them.
Diffstat (limited to 'netdata-installer.sh')
-rwxr-xr-xnetdata-installer.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/netdata-installer.sh b/netdata-installer.sh
index bc2e1cbe0b..c40d03473e 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -42,6 +42,43 @@ fi
cd "${NETDATA_SOURCE_DIR}" || exit 1
# -----------------------------------------------------------------------------
+# figure out an appropriate temporary directory
+_cannot_use_tmpdir() {
+ local testfile ret
+ testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
+ ret=0
+
+ if [ -z "${testfile}" ] ; then
+ return "${ret}"
+ fi
+
+ if /bin/echo -e '#!/bin/sh\necho SUCCESS\n' > "${testfile}" ; then
+ if chmod +x "${testfile}" ; then
+ if [ "$("${testfile}")" = "SUCCESS" ] ; then
+ ret=1
+ fi
+ fi
+ fi
+
+ rm -f "${testfile}"
+ return "${ret}"
+}
+
+if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
+ if _cannot_use_tmpdir /tmp ; then
+ if _cannot_use_tmpdir "${PWD}" ; then
+ echo >&2
+ 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."
+ exit 1
+ else
+ TMPDIR="${PWD}"
+ fi
+ else
+ TMPDIR="/tmp"
+ fi
+fi
+
+# -----------------------------------------------------------------------------
# set up handling for deferred error messages
NETDATA_DEFERRED_ERRORS=""
@@ -324,6 +361,10 @@ cat << BANNER1
You are about to build and install netdata to your system.
+ The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
+ any temporary files. You can override this by setting \$TMPDIR to a
+ writable directory where you can execute files.
+
It will be installed at these locations:
- the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}