33set -e
44set -o pipefail
55
6- # https://github.com/terraform-docs/terraform-docs/releases/download/v0.6.0/terraform-docs-v0.6.0-linux-amd64
7- # https://github.com/terraform-docs/terraform-docs/releases/download/v0.6.0/terraform-docs-v0.6.0-darwin-amd64
6+ # starting from v0.11.0
7+ # https://github.com/terraform-docs/terraform-docs/releases/download/v0.14.1/terraform-docs-v0.14.1-darwin-amd64.tar.gz
8+ # https://github.com/terraform-docs/terraform-docs/releases/download/v0.14.1/terraform-docs-v0.14.1-linux-amd64.tar.gz
9+
10+ # up to v0.10.1
11+ # https://github.com/terraform-docs/terraform-docs/releases/download/v0.10.1/terraform-docs-v0.10.1-darwin-amd64
12+ # https://github.com/terraform-docs/terraform-docs/releases/download/v0.10.1/terraform-docs-v0.10.1-linux-amd64
813
914readonly NO_BINARY_ALTNAME=@@UNDEFINED@@
1015# shellcheck disable=SC2034
@@ -18,8 +23,9 @@ readonly g_filename_template=__BINARY_NAME__-v__VERSION_SHORT__-__PLATFORM__
1823#
1924# available : __GITHUB_COORDINATES__/__VERSION__/__VERSION_SHORT__/__FILENAME__
2025#
26+ # The .tar.gz will be added if needed in the main func according to the target version
2127# shellcheck disable=SC2034
22- readonly g_download_url_template=https://github.com/__GITHUB_COORDINATES__/releases/download/v__VERSION_SHORT__/__FILENAME__.tar.gz
28+ readonly g_download_url_template=https://github.com/__GITHUB_COORDINATES__/releases/download/v__VERSION_SHORT__/__FILENAME__
2329#
2430# available : __ARCHIVE_DIR__/__BINARY_NAME__/__VERSION__/__VERSION_SHORT__/__PLATFORM__
2531#
@@ -51,7 +57,10 @@ function log() {
5157 fi >&2
5258}
5359
54- # from https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
60+ # inspired from https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
61+ # 0 for '='
62+ # 1 for '>'
63+ # 2 for '<'
5564function vercomp() {
5665 if [[ " $1 " == " $2 " ]]; then
5766 return 0
@@ -69,13 +78,18 @@ function vercomp() {
6978 ver2[i]=0
7079 fi
7180 if (( 10 #${ver1[i]} > 10 #${ver2[i]} )) ; then
72- return 1
81+ # >
82+ echo 1
83+ exit 0
7384 fi
7485 if (( 10 #${ver1[i]} < 10 #${ver2[i]} )) ; then
75- return 2
86+ # <
87+ echo 2
88+ exit 0
7689 fi
7790 done
78- return 0
91+ # =
92+ echo 0
7993}
8094
8195install_tool () {
@@ -97,13 +111,26 @@ install_tool() {
97111 local download_url
98112 local download_target_file
99113 local download_sub_path_dir
114+ local version_short op bpath_in_archive
100115
101116 if [[ " $install_type " != " version" ]]; then
102117 log ERROR " Install of type [$install_type ] not supported"
103118 fi
104119
120+ #
121+ version_short=$( get_version_short " $version " )
122+ #
105123 platform=$( get_platform)
106124 download_url=$( get_download_url " $version " " $platform " " $binary_name " )
125+
126+ op=$( vercomp " $version_short " " 0.11.0" )
127+ if [[ " ${op} " != " 2" ]]; then
128+ download_url=" ${download_url} .tar.gz"
129+ downloaded_file_is_not_an_archive=" false"
130+ else
131+ downloaded_file_is_not_an_archive=" true"
132+ fi
133+
107134 download_sub_path_dir=$tmp_download_dir /sub
108135 mkdir -p " $download_sub_path_dir "
109136 download_target_file=" $download_sub_path_dir /" $( get_filename " $version " " $platform " " $binary_name " )
@@ -127,7 +154,11 @@ install_tool() {
127154 cp " $download_target_file " " $tmp_download_dir "
128155 fi
129156 log INFO " Copying binaries"
130- cp " $( get_binary_path_in_archive " ${tmp_download_dir} " " ${binary_name} " " ${version} " " ${platform} " ) " " ${full_path_to_binary} "
157+ bpath_in_archive=$( get_binary_path_in_archive " ${tmp_download_dir} " " ${binary_name} " " ${version} " " ${platform} " )
158+ if [[ " ${op} " == " 2" ]]; then
159+ bpath_in_archive=${bpath_in_archive} -v${version_short} -${platform}
160+ fi
161+ cp " ${bpath_in_archive} " " ${full_path_to_binary} "
131162 chmod +x " ${full_path_to_binary} "
132163 if [[ -n " $binary_alt_name " ]]; then
133164 cp " ${full_path_to_binary} " " ${full_path_to_alt_binary} "
0 commit comments