@cryptotaxi247 / netdata-1 / commits / 9f7ddf5fd

Fix handling of temp directory in kickstart when uninstalling. (#13056)

This makes temporary directory creation idempotent, and ensures it’s invoked in each place that needs it. It also tidies up the cleanup code so that it only tries to remove the temporary directory if one was created.

Austin S. Hemmelgarn committed Jun 3, 2022 at 07:32 UTC 9f7ddf5fd6fd400a12a7822b31e45bac207c4f03
1 file changed +12 -4
packaging/installer/kickstart.sh
+12 -4
@@ -101,9 +101,7 @@ main() {
101 ;;
102 esac
103
104 - tmpdir="$(create_tmp_directory)"
105 - progress "Using ${tmpdir} as a temporary directory."
106 - cd "${tmpdir}" || fatal "Failed to change current working directory to ${tmpdir}." F000A
104 + set_tmpdir
105
106 if [ -n "${INSTALL_VERSION}" ]; then
107 if echo "${INSTALL_VERSION}" | grep -E -o "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$" > /dev/null 2>&1; then
@@ -373,7 +371,8 @@ success_banner() {
371 }
372
373 cleanup() {
376 - if [ -z "${NO_CLEANUP}" ]; then
374 + if [ -z "${NO_CLEANUP}" ] && [ -n "${tmpdir}" ]; then
375 + cd || true
376 ${ROOTCMD} rm -rf "${tmpdir}"
377 fi
378 }
@@ -506,6 +505,14 @@ create_tmp_directory() {
505 mktemp -d -t netdata-kickstart-XXXXXXXXXX
506 }
507
508 +set_tmpdir() {
509 + if [ -z "${tmpdir}" ]; then
510 + tmpdir="$(create_tmp_directory)"
511 + progress "Using ${tmpdir} as a temporary directory."
512 + cd "${tmpdir}" || fatal "Failed to change current working directory to ${tmpdir}." F000A
513 + fi
514 +}
515 +
516 check_for_remote_file() {
517 url="${1}"
518
@@ -710,6 +717,7 @@ update() {
717 }
718
719 uninstall() {
720 + set_tmpdir
721 get_system_info
722 detect_existing_install
723