Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordrak authored May 27, 2020
2 parents 919e85b + 4054aff commit a0a648f
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv---version
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-exec
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions libexec/tfenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -95,13 +95,17 @@ case "$(uname -s)" in
CYGWIN_NT*)
os="windows_${TFENV_ARCH}";
;;
FreeBSD*)
os="freebsd_${TFENV_ARCH}"
;;
*)
os="linux_${TFENV_ARCH}";
;;
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}";
Expand Down Expand Up @@ -137,7 +141,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;

Expand Down Expand Up @@ -226,14 +230,22 @@ 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';
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 -o "${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}");
Expand Down
4 changes: 2 additions & 2 deletions libexec/tfenv-list
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-list-remote
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-min-required
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-resolve-version
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions libexec/tfenv-uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,5 +112,9 @@ dst_path="${TFENV_ROOT}/versions/${version}";
if [ -f "${dst_path}/terraform" ]; then
log 'info' "Uninstall Terraform v${version}";
rm -r "${dst_path}";

# If no versions remain, remove the versions directory
rmdir "${TFENV_ROOT}/versions" 2>/dev/null;

log 'info' "Terraform v${version} is successfully uninstalled";
fi;
fi;
2 changes: 1 addition & 1 deletion libexec/tfenv-use
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-version-file
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libexec/tfenv-version-name
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions test/test_uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ for ((test_num=0; test_num<${tests_count}; ++test_num )) ; do
|| error_and_proceed "Test uninstall of version ${version} (via ${keyword}) failed";
done;

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
log 'warn' "===== The following list tests failed =====";
for error in "${errors[@]}"; do
Expand Down

0 comments on commit a0a648f

Please sign in to comment.