Skip to content

Commit

Permalink
Merge pull request #16 from opentofuutils/fix/install
Browse files Browse the repository at this point in the history
Skip check remote versions before installation
  • Loading branch information
Nmishin authored Jan 1, 2024
2 parents 0b64670 + 05a9b5f commit 8c52b59
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ functionality will be restored.
TOFUENV_REVERSE_REMOTE=1 tofuenv list-remote
```

##### `TOFUENV_SKIP_LIST_REMOTE`

Integer (Default: 0)

Skip list remote versions in installation step. Can be useful for a custom remote, such as Artifactory.

Disabled: 0
Enable: any other value

```console
TOFUENV_SKIP_LIST_REMOTE=1 tofuenv install 1.6.0-rc1
```

##### `TOFUENV_CONFIG_DIR`

Path (Default: `$TOFUENV_ROOT`)
Expand Down
22 changes: 19 additions & 3 deletions libexec/tofuenv-install
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ declare regex="${resolved##*\:}";

log 'debug' "Processing install for version ${version}, using regex ${regex}";

remote_version="$(tofuenv-list-remote | grep -e "${regex}" | head -n 1)";
[ -n "${remote_version}" ] && version="${remote_version}" || log 'error' "No versions matching '${requested:-$version}' found in remote";
if [[ ${version} =~ ${regex:-not} ]]; then
log 'debug' "Version and regex matched";
else
log 'debug' "Version and regex not matched";
if [ "${TOFUENV_SKIP_LIST_REMOTE:-0}" -eq 0 ]; then
remote_version="$(tofuenv-list-remote | grep -e "${regex}" | head -n 1)";
[ -n "${remote_version}" ] && version="${remote_version}" || log 'error' "No versions matching '${requested:-$version}' found in remote";
fi;
fi;

dst_path="${TOFUENV_CONFIG_DIR}/versions/${version}";
if [ -f "${dst_path}/tofu" ]; then
Expand Down Expand Up @@ -168,7 +175,16 @@ case "${TOFUENV_CURL_OUTPUT:-2}" in
esac;

log 'info' "Downloading release tarball from ${version_url}/${tarball_name}";
curlw ${curl_progress} -f -L -o "${download_tmp}/${tarball_name}" "${version_url}/${tarball_name}" || log 'error' 'Tarball download failed';

status=$(curlw ${curl_progress} -w "%{http_code}" -f -L -o "${download_tmp}/${tarball_name}" "${version_url}/${tarball_name}");

case "${status}" in
200) log 'debug' "'${requested:-$version}' version download successfully" ;;
403) log 'error' "GitHub Rate limits exceeded" ;;
404) log 'error' "No versions matching '${requested:-$version}' found in remote" ;;
*) log 'error' "Unknown error, status code = ${status}" ;;
esac;

log 'info' "Downloading SHA hash file from ${version_url}/${shasums_name}";
curlw -s -f -L -o "${download_tmp}/${shasums_name}" "${version_url}/${shasums_name}" || log 'error' 'SHA256 hashes download failed';

Expand Down

0 comments on commit 8c52b59

Please sign in to comment.