From 0a43afe9bcce3a3869d9e5ee2345ee97db358d91 Mon Sep 17 00:00:00 2001 From: Eashwar Ranganathan Date: Fri, 26 Jul 2019 20:07:58 -0700 Subject: [PATCH 1/7] Remove the versions directory when the last version is uninstalled --- libexec/tfenv-uninstall | 1 + test/test_uninstall.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/libexec/tfenv-uninstall b/libexec/tfenv-uninstall index 7e679fc..69ab923 100755 --- a/libexec/tfenv-uninstall +++ b/libexec/tfenv-uninstall @@ -35,5 +35,6 @@ dst_path="${TFENV_ROOT}/versions/${version}" if [ -f "${dst_path}/terraform" ]; then info "Uninstall Terraform v${version}" rm -r "${dst_path}" + rmdir "${TFENV_ROOT}/versions" 2> /dev/null info "\033[0;32mTerraform v${version} is successfully uninstalled\033[0;39m" fi diff --git a/test/test_uninstall.sh b/test/test_uninstall.sh index a0b1966..b70f741 100755 --- a/test/test_uninstall.sh +++ b/test/test_uninstall.sh @@ -46,6 +46,18 @@ v="$(tfenv list-remote | grep 0.8 | head -n 1)" check_version "${v}" && exit 1 || exit 0 ) || error_and_proceed "Uninstalling latest version "${v}" with Regex" +echo "### Uninstall removes versions directory" +cleanup || error_and_die "Cleanup failed?!" +( + tfenv install 0.12.1 || exit 1 + tfenv install 0.12.2 || exit 1 + [ -d "./versions" ] || exit 1 + tfenv uninstall 0.12.1 || exit 1 + [ -d "./versions" ] || exit 1 + tfenv uninstall 0.12.2 || exit 1 + [ -d "./versions" ] && exit 1 || exit 0 +) || error_and_proceed "Removing last version deletes versions directory" + if [ "${#errors[@]}" -gt 0 ]; then echo -e "\033[0;31m===== The following list tests failed =====\033[0;39m" >&2 for error in "${errors[@]}"; do From 2e0961d5f7d0de7f63b148bfbe182bf636412df4 Mon Sep 17 00:00:00 2001 From: Mike Peachey Date: Tue, 26 May 2020 16:54:54 +0100 Subject: [PATCH 2/7] Fix #177 --- libexec/tfenv-install | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libexec/tfenv-install b/libexec/tfenv-install index 33d39b8..781a92b 100755 --- a/libexec/tfenv-install +++ b/libexec/tfenv-install @@ -137,7 +137,7 @@ case "${TFENV_CURL_OUTPUT:-2}" in curl_progress="-s"; ;; *) - log 'error' 'TFENV_CURL_OUTPUT specified, but not with a support value ([0,1,2])'; + log 'error' 'TFENV_CURL_OUTPUT specified, but not with a supported value ([0,1,2])'; ;; esac; @@ -233,7 +233,8 @@ fi; mkdir -p "${dst_path}" || log 'error' "Failed to make directory ${dst_path}"; -declare unzip_output="$(unzip "${download_tmp}/${tarball_name}" -d "${dst_path}" || log 'error' 'Tarball unzip failed')"; +declare unzip_output; +unzip_output="$(unzip "${download_tmp}/${tarball_name}" -d "${dst_path}")" || log 'error' 'Tarball unzip failed'; while IFS= read -r unzip_line; do log 'info' "${unzip_line}"; done < <(printf '%s\n' "${unzip_output}"); From 73850e5537630507d3a07604731716f8f8ef73b4 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 16 Mar 2020 18:08:56 +0800 Subject: [PATCH 3/7] Quote "${TFENV_ROOT}" argument in all `[ -n ]` Reference: https://github.com/koalaman/shellcheck/wiki/SC2070 ``` [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; ^-----------^ SC2070: -n doesn't work with unquoted arguments. Quote or use [[ ]]. ``` --- libexec/tfenv---version | 2 +- libexec/tfenv-exec | 2 +- libexec/tfenv-install | 2 +- libexec/tfenv-list | 2 +- libexec/tfenv-list-remote | 2 +- libexec/tfenv-min-required | 2 +- libexec/tfenv-resolve-version | 2 +- libexec/tfenv-uninstall | 2 +- libexec/tfenv-use | 2 +- libexec/tfenv-version-file | 2 +- libexec/tfenv-version-name | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libexec/tfenv---version b/libexec/tfenv---version index 6bc8e28..2e819ac 100755 --- a/libexec/tfenv---version +++ b/libexec/tfenv---version @@ -36,7 +36,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-exec b/libexec/tfenv-exec index 6ebcb04..975e5b2 100755 --- a/libexec/tfenv-exec +++ b/libexec/tfenv-exec @@ -40,7 +40,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-install b/libexec/tfenv-install index 781a92b..f05f925 100755 --- a/libexec/tfenv-install +++ b/libexec/tfenv-install @@ -26,7 +26,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-list b/libexec/tfenv-list index b8e232a..d9913b3 100755 --- a/libexec/tfenv-list +++ b/libexec/tfenv-list @@ -27,7 +27,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-list-remote b/libexec/tfenv-list-remote index 8b04997..ff99959 100755 --- a/libexec/tfenv-list-remote +++ b/libexec/tfenv-list-remote @@ -27,7 +27,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-min-required b/libexec/tfenv-min-required index b886e93..1399856 100755 --- a/libexec/tfenv-min-required +++ b/libexec/tfenv-min-required @@ -29,7 +29,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-resolve-version b/libexec/tfenv-resolve-version index d488e52..e6c54e5 100755 --- a/libexec/tfenv-resolve-version +++ b/libexec/tfenv-resolve-version @@ -29,7 +29,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-uninstall b/libexec/tfenv-uninstall index 19a506e..5e811af 100755 --- a/libexec/tfenv-uninstall +++ b/libexec/tfenv-uninstall @@ -27,7 +27,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-use b/libexec/tfenv-use index 2a96a2d..33817d3 100755 --- a/libexec/tfenv-use +++ b/libexec/tfenv-use @@ -26,7 +26,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-version-file b/libexec/tfenv-version-file index e4f0ce7..6b9697a 100755 --- a/libexec/tfenv-version-file +++ b/libexec/tfenv-version-file @@ -29,7 +29,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; diff --git a/libexec/tfenv-version-name b/libexec/tfenv-version-name index d9bbe5d..b8923c4 100755 --- a/libexec/tfenv-version-name +++ b/libexec/tfenv-version-name @@ -28,7 +28,7 @@ if [ -z "${TFENV_ROOT:-""}" ]; then }; TFENV_ROOT="$(cd "$(dirname "$(readlink_f "${0}")")/.." && pwd)"; - [ -n ${TFENV_ROOT} ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; + [ -n "${TFENV_ROOT}" ] || early_death "Failed to 'cd \"\$(dirname \"\$(readlink_f \"${0}\")\")/..\" && pwd' while trying to determine TFENV_ROOT"; else TFENV_ROOT="${TFENV_ROOT%/}"; fi; From d423b93023df2882618ecc31b98ff0d4aae29e84 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 16 Mar 2020 18:14:50 +0800 Subject: [PATCH 4/7] Remove deplicated export of $version_file in tfenv-list --- libexec/tfenv-list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/tfenv-list b/libexec/tfenv-list index d9913b3..c3897a8 100755 --- a/libexec/tfenv-list +++ b/libexec/tfenv-list @@ -73,7 +73,7 @@ version_name="$(tfenv-version-name)" \ || log 'error' "tfenv-version-name failed"; export version_name; -export version_file="$(tfenv-version-file)" \ +version_file="$(tfenv-version-file)" \ && log 'debug' "tfenv-version-file reported: ${version_file}" \ || log 'error' "tfenv-version-file failed"; export version_file; From dd8381758fcde63acbcd98662eeea14cda0a46c9 Mon Sep 17 00:00:00 2001 From: orotalt Date: Mon, 26 Aug 2019 15:34:26 +0200 Subject: [PATCH 5/7] Adding freebsd support --- libexec/tfenv-install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libexec/tfenv-install b/libexec/tfenv-install index f05f925..4f471ec 100755 --- a/libexec/tfenv-install +++ b/libexec/tfenv-install @@ -95,6 +95,9 @@ case "$(uname -s)" in CYGWIN_NT*) os="windows_${TFENV_ARCH}"; ;; + FreeBSD*) + os="freebsd_${TFENV_ARCH}" + ;; *) os="linux_${TFENV_ARCH}"; ;; From 44831e1c0d3a14666279c8097d2ae538f554e36c Mon Sep 17 00:00:00 2001 From: Yann Soubeyrand Date: Fri, 28 Feb 2020 10:38:36 +0100 Subject: [PATCH 6/7] Add support for sha256sum command --- libexec/tfenv-install | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libexec/tfenv-install b/libexec/tfenv-install index 4f471ec..a91da3b 100755 --- a/libexec/tfenv-install +++ b/libexec/tfenv-install @@ -105,6 +105,7 @@ esac; keybase_bin="$(command -v keybase 2>/dev/null)"; shasum_bin="$(command -v shasum 2>/dev/null)"; +sha256sum_bin="$(command -v sha256sum 2>/dev/null)"; TFENV_REMOTE="${TFENV_REMOTE:-https://releases.hashicorp.com}"; version_url="${TFENV_REMOTE}/terraform/${version}"; @@ -229,6 +230,13 @@ if [[ -n "${shasum_bin}" && -x "${shasum_bin}" ]]; then -c <(grep -F "${tarball_name}" "${shasums_name}") \ || log 'error' 'SHA256 hash does not match!'; ); +elif [[ -n "${sha256sum_bin}" && -x "${sha256sum_bin}" ]]; then + ( + cd "${download_tmp}"; + "${sha256sum_bin}" \ + -c <(grep -F "${tarball_name}" "${shasums_name}") \ + || log 'error' 'SHA256 hash does not match!'; + ); else # Lack of shasum deserves a proper warning log 'warn' 'No shasum tool available. Skipping SHA256 hash validation'; From df3a01a9099c23ba1d0c99188c3c8e665aad46a0 Mon Sep 17 00:00:00 2001 From: Florian Woerner Date: Tue, 21 Apr 2020 09:09:53 +0200 Subject: [PATCH 7/7] Update typo in CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a61c6f3..203e489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 2.0.0 (Unreleased) +## 2.0.0 (April 20, 2020) * New logging and debugging library * Massive testing, logging and loading refactoring