forked from Kasama/tfenv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tfenv-uninstall
executable file
·39 lines (32 loc) · 1.18 KB
/
tfenv-uninstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
[ -n "${TFENV_DEBUG}" ] && set -x
source "${TFENV_ROOT}/libexec/helpers"
[ "${#}" -gt 1 ] && error_and_die "usage: tfenv uninstall [<version>]"
declare version_requested version regex
if [ -z "${1}" ]; then
version_file="$(tfenv-version-file)"
if [ "${version_file}" != "${TFENV_ROOT}/version" ];then
version_requested="$(cat "${version_file}" || true)"
fi
else
version_requested="${1}"
fi
if [[ "${version_requested}" =~ ^latest\:.*$ ]]; then
version="${version_requested%%\:*}"
regex="${version_requested##*\:}"
elif [[ "${version_requested}" =~ ^latest$ ]]; then
version="${version_requested}"
regex=""
else
version="${version_requested}"
regex="^${version_requested}$"
fi
[ -n "${version}" ] || error_and_die "Version is not specified"
version="$(tfenv-list | sed -E 's/^(\*| )? //g; s/ \(set by .+\)$//' | grep -e "${regex}" | head -n 1)"
[ -n "${version}" ] || error_and_die "No versions matching '${1}' found in local"
dst_path="${TFENV_ROOT}/versions/${version}"
if [ -f "${dst_path}/terraform" ]; then
info "Uninstall Terraform v${version}"
rm -r "${dst_path}"
info "\033[0;32mTerraform v${version} is successfully uninstalled\033[0;39m"
fi