-
Notifications
You must be signed in to change notification settings - Fork 6
/
in
executable file
·53 lines (42 loc) · 1.39 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
#!/bin/bash
set -e
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 [[ "${version}X" == "X" ]]; then
>&2 echo "Version info 'version' is missing"
exit 1
fi
source_project=$(jq -r '.source.project // empty' < "$payload")
if [[ "${source_project}X" == "X" ]]; then
>&2 echo "Source parameter 'project' is missing"
exit 1
fi
params_regexp=$(jq -r '.params.regexp // empty' < "$payload")
curl -sf "https://releases.hashicorp.com/${source_project}/index.json" > /dev/null || (
>&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 -s "https://releases.hashicorp.com/${source_project}/index.json" | jq -r ".versions[\"${version}\"].builds[].url")
if [[ ! -z $params_regexp ]]; then
set +e
build_urls=$(echo "${build_urls}" | grep "${params_regexp}")
set -e
fi
if [[ ! -z $build_urls ]]; then
for url in $build_urls; do
>&2 echo "Downloading $url"
curl -O "$url"
done
else
>&2 echo "regexp '$params_regexp' did not match any build URLs"
exit 1
fi
jq -n --arg version "${version}" '{version: { version: $version }}' >&3