This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·140 lines (126 loc) · 3.73 KB
/
update.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
set -e
set -Euo pipefail
set -x
trap 'rm -rf ${TEMP_DIR}' EXIT
TEMP_DIR=$(mktemp -d)
CHECKSUM_DIR=$(readlink -f ./checksums)
METADATA_DIR=$(readlink -f ./metadata)
function ensure_directory {
if [ ! -d "${1}" ]
then
mkdir -p "${1}"
fi
}
function get_extensions {
case "${1}" in
"linux") echo 'tar.gz'
;;
"macosx") echo 'tar.gz' 'pkg'
;;
"windows") echo 'zip' 'msi'
;;
esac
}
function get_archs {
case "${1}" in
"linux") echo 'x64' 'aarch64'
;;
"macosx") echo 'x64'
;;
"windows") echo 'x64'
;;
esac
}
function archive_filename {
local version="${1}"
local os="${2}"
local arch="${3}"
local ext="${4}"
echo -n "amazon-corretto-${version}-${os}-${arch}.${ext}"
}
function download {
local version="${1}"
local os="${2}"
local arch="${3}"
local ext="${4}"
local filename
filename="$(archive_filename "${version}" "${os}" "${arch}" "${ext}")"
local url
local metadata_file="${METADATA_DIR}/${filename}.json"
local archive="${TEMP_DIR}/${filename}"
if [[ -f "${metadata_file}" ]]
then
echo "Skipping ${filename}"
else
if curl --silent --show-error --fail --head "https://corretto.aws/downloads/resources/${version}/${filename}"
then
url="https://corretto.aws/downloads/resources/${version}/${filename}"
else
url="https://d3pxv6yz143wms.cloudfront.net/${version}/${filename}"
fi
curl --silent --show-error --fail -w "%{filename_effective}\n" --output "${archive}" "${url}" || return 1
local MD5
MD5=$(md5sum "${archive}" | cut -f 1 -d ' ')
echo "${MD5} ${filename}" > "${CHECKSUM_DIR}/${filename}.md5"
local SHA1
SHA1=$(sha1sum "${archive}"| cut -f 1 -d ' ')
echo "${SHA1} ${filename}" > "${CHECKSUM_DIR}/${filename}.sha1"
local SHA256
SHA256=$(sha256sum "${archive}" | cut -f 1 -d ' ')
echo "${SHA256} ${filename}" > "${CHECKSUM_DIR}/${filename}.sha256"
local SHA512
SHA512=$(sha512sum "${archive}" | cut -f 1 -d ' ')
echo "${SHA512} ${filename}" > "${CHECKSUM_DIR}/${filename}.sha512"
local json="{
\"filename\": \"${filename}\",
\"url\": \"${url}\",
\"md5\": \"${MD5}\",
\"md5_file\": \"${filename}.md5\",
\"sha1\": \"${SHA1}\",
\"sha1_file\": \"${filename}.sha1\",
\"sha256\": \"${SHA256}\",
\"sha256_file\": \"${filename}.sha256\",
\"sha512\": \"${SHA512}\",
\"sha512_file\": \"${filename}.sha512\",
\"version\": \"${version}\",
\"os\": \"${os}\",
\"arch\": \"${arch}\",
\"archive_type\": \"${ext}\"
}"
echo "${json}" > "${metadata_file}"
rm -f "${archive}"
fi
}
ensure_directory "${CHECKSUM_DIR}"
ensure_directory "${METADATA_DIR}"
CURL_ARGS=('--silent' '--show-error' '--fail' '--output' "${TEMP_DIR}/releases-#1.json")
if [[ -n "${GITHUB_API_TOKEN:-}" ]]; then
CURL_ARGS+=('-H' "Authorization: token ${GITHUB_API_TOKEN}")
fi
curl "${CURL_ARGS[@]}" 'https://api.github.com/repos/corretto/{corretto-8}/releases'
curl "${CURL_ARGS[@]}" 'https://api.github.com/repos/corretto/{corretto-11}/releases'
CORRETTO_VERSIONS=$(jq -r '.[].name' "${TEMP_DIR}/releases-corretto-8.json" "${TEMP_DIR}/releases-corretto-11.json" | sort -V)
for CORRETTO_VERSION in ${CORRETTO_VERSIONS}
do
for OS in 'linux' 'macosx' 'windows'
do
for EXT in $(get_extensions "${OS}")
do
for ARCH in $(get_archs "${OS}")
do
download "${CORRETTO_VERSION}" "${OS}" "${ARCH}" "${EXT}" || echo "Cannot download $(archive_filename "${CORRETTO_VERSION}" "${OS}" "${ARCH}" "${EXT}")"
done
done
done
done
jq -M -s -S . "${METADATA_DIR}"/amazon-corretto-*.json > "${METADATA_DIR}/releases.json"
for OS in 'linux' 'macosx' 'windows'
do
for ARCH in $(get_archs "${OS}")
do
DIR="${METADATA_DIR}/${OS}/${ARCH}"
ensure_directory "${DIR}"
jq -M -S ".[] | select(.os == \"${OS}\") | select(.arch == \"${ARCH}\")" "${METADATA_DIR}/releases.json" > "${DIR}/releases.json"
done
done