forked from egen/hashicorp-release-resource
-
Notifications
You must be signed in to change notification settings - Fork 0
/
in
executable file
·58 lines (47 loc) · 1.64 KB
/
in
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
set -eo pipefail
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
destination=$1
payload=$(mktemp "${TMPDIR}/resource-check.XXXXXX")
cat > "${payload}" <&0
version=$(jq -r '.version.version // empty' < "${payload}")
if [[ -z ${version} ]]; then
>&2 echo "Version info 'version' is missing"
exit 1
fi
source_project=$(jq -r '.source.project // empty' < "${payload}")
if [[ -z ${source_project} ]]; then
>&2 echo "Source parameter 'project' is missing"
exit 1
fi
params_regexp=$(jq -r '.params.regexp // empty' < "${payload}")
curl --silent --fail --show-error --location --output /dev/null \
--url "https://releases.hashicorp.com/${source_project}/index.json" || (
>&2 echo "Unknown hashicorp project '${source_project}'"
exit 1
)
>&2 echo "Fetching assets ${source_project} v${version}"
cd "${destination}"
echo "${version}" > version
echo "${source_project}" > project
build_urls=$(
curl --silent --fail --show-error --location \
--url "https://releases.hashicorp.com/${source_project}/index.json" \
| jq -r ".versions[\"${version}\"].builds[].url"
)
if [[ -n "${params_regexp}" ]]; then
set +e
build_urls=$(grep "${params_regexp}" <<< "${build_urls}")
set -e
fi
if [[ -z "${build_urls}" ]]; then
>&2 echo "Regexp '${params_regexp}' did not match any build URLs"
exit 1
fi
for url in ${build_urls}; do
>&2 echo "Downloading ${url}"
curl --silent --fail --show-error --location --remote-name \
--url "${url}"
done
jq --null-input --arg version "${version}" '{ version: { version: $version } }' >&3