-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin
executable file
·88 lines (75 loc) · 2.66 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
set -ueo 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=$(cat <&0)
version=$(jq --raw-output '.version.version // empty' <<< "${payload}")
if [[ -z ${version} ]]; then
echo >&2 "Version info 'version' is missing"
exit 1
fi
source_family=$(jq -r '.source.family // empty' <<< "${payload}")
if [[ -z "${source_family}" ]]; then
echo >&2 "Source parameter 'family' is missing"
exit 1
fi
>&2 echo "Fetching assets in ${source_family} family v${version}"
pushd "${destination}" > /dev/null
echo "${version}" > version
echo "${source_family}" > family
directory="${source_family}"
if [[ "${source_family}" == 0.9.* ]]; then
directory="0.9.x"
fi
tarball_url=$(
(
curl --silent --fail --show-error --location \
--url "https://artfiles.org/openssl.org/source/old/${directory}/" \
| sed -nEe 's|^.*href="(openssl-'"${version}"'\.tar\.gz)">.*|https://www.openssl.org/source/old/'"${directory}"'/\1|p'
curl --silent --fail --show-error --location \
--url "https://artfiles.org/openssl.org/source/" \
| sed -nEe 's|^.*href="(openssl-'"${version}"'\.tar\.gz)">.*|https://www.openssl.org/source/\1|p'
) | tail --lines="1"
)
if [[ -z "${tarball_url}" ]]; then
echo >&2 "No such 'openssl-${version}.tar.gz' tarball available" \
"on 'https://artfiles.org/openssl.org/source/'" \
"or 'https://artfiles.org/openssl.org/source/old/${directory}/'"
exit 1
fi
echo >&2 "Downloading ${tarball_url}"
curl --silent --fail --show-error --location --remote-name \
--url "${tarball_url}"
if curl --silent --fail --location --output "sha256" \
--url "${tarball_url}.sha256"
then
echo >&2 "Checking sha256 fingerprint"
sha256=$(< sha256)
sha256sum --check <<< "${sha256} openssl-${version}.tar.gz"
elif curl --silent --fail --location --output "sha1" \
--url "${tarball_url}.sha1"
then
echo >&2 "Checking sha1 fingerprint"
sha1=$(< sha1)
sha1sum --check <<< "${sha1} openssl-${version}.tar.gz"
elif curl --silent --fail --location --output "md5" \
--url "${tarball_url}.md5"
then
echo >&2 "Checking md5 fingerprint"
md5=$(< md5)
md5sum --check <<< "${md5} openssl-${version}.tar.gz"
else
echo >&2 "No '.sha256', nor '.sha1', nor '.md5' fingerprint" \
"could be downloaded"
exit 1
fi
if [[ ! -f sha256 ]]; then
sha256sum "openssl-${version}.tar.gz" \
| cut --delimiter=" " --field="1" \
> sha256
fi
jq --null-input \
--arg "version" "${version}" \
'{ version: { version: $version } }' \
>&3