@cryptotaxi247 / netdata-1 / commits / 13e630272

fix(netdata-updater.sh): use explicit paths for temp dir creation (#19293)

Ilya Mashchenko committed Jan 6, 2025 at 14:41 UTC 13e630272874937820b05bfed7254f78f9e7cd54
1 file changed +23 -22
packaging/installer/netdata-updater.sh
+23 -22
@@ -394,28 +394,29 @@ _cannot_use_tmpdir() {
394 return "${ret}"
395 }
396
397 -create_tmp_directory() {
397 +create_exec_tmp_directory() {
398 if [ -n "${NETDATA_TMPDIR_PATH}" ]; then
399 echo "${NETDATA_TMPDIR_PATH}"
400 - else
401 - if [ -z "${NETDATA_TMPDIR}" ] || _cannot_use_tmpdir "${NETDATA_TMPDIR}" ; then
402 - if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
403 - if _cannot_use_tmpdir /tmp ; then
404 - if _cannot_use_tmpdir "${PWD}" ; then
405 - fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." U0003
406 - else
407 - TMPDIR="${PWD}"
408 - fi
409 - else
410 - TMPDIR="/tmp"
411 - fi
412 - fi
413 - else
414 - TMPDIR="${NETDATA_TMPDIR}"
415 - fi
400 + return
401 + fi
402 +
403 + root_dir=""
404
417 - mktemp -d -t netdata-updater-XXXXXXXXXX
405 + if [ -n "${NETDATA_TMPDIR}" ] && ! _cannot_use_tmpdir "${NETDATA_TMPDIR}"; then
406 + root_dir="${NETDATA_TMPDIR}"
407 + elif [ -n "${TMPDIR}" ] && ! _cannot_use_tmpdir "${TMPDIR}"; then
408 + root_dir="${TMPDIR}"
409 + elif ! _cannot_use_tmpdir /tmp; then
410 + root_dir="/tmp"
411 + elif ! _cannot_use_tmpdir "${PWD}"; then
412 + root_dir="${PWD}"
413 + else
414 + fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." U0003
415 fi
416 +
417 + TMPDIR="${root_dir}"
418 +
419 + mktemp -d -p "${root_dir}" -t netdata-updater-XXXXXXXXXX
420 }
421
422 check_for_curl() {
@@ -526,7 +527,7 @@ get_netdata_latest_tag() {
527 newer_commit_date() {
528 info "Checking if a newer version of the updater script is available."
529
529 - ndtmpdir="$(create_tmp_directory)"
530 + ndtmpdir="$(create_exec_tmp_directory)"
531 commit_check_file="${ndtmpdir}/latest-commit.json"
532 commit_check_url="https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1"
533 python_version_check="
@@ -580,7 +581,7 @@ self_update() {
581 if [ -z "${NETDATA_NO_UPDATER_SELF_UPDATE}" ] && newer_commit_date; then
582 info "Downloading newest version of updater script."
583
583 - ndtmpdir=$(create_tmp_directory)
584 + ndtmpdir=$(create_exec_tmp_directory)
585 cd "$ndtmpdir" || exit 1
586
587 if _safe_download "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-updater.sh" ./netdata-updater.sh; then
@@ -737,7 +738,7 @@ update_build() {
738 [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
739
740 RUN_INSTALLER=0
740 - ndtmpdir=$(create_tmp_directory)
741 + ndtmpdir=$(create_exec_tmp_directory)
742 cd "$ndtmpdir" || fatal "Failed to change current working directory to ${ndtmpdir}" U0016
743
744 install_build_dependencies
@@ -836,7 +837,7 @@ update_build() {
837 }
838
839 update_static() {
839 - ndtmpdir="$(create_tmp_directory)"
840 + ndtmpdir="$(create_exec_tmp_directory)"
841 PREVDIR="$(pwd)"
842
843 info "Entering ${ndtmpdir}"