-
Notifications
You must be signed in to change notification settings - Fork 14
/
get-versions
executable file
·65 lines (59 loc) · 2.22 KB
/
get-versions
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
#!/usr/bin/env bash
# $1: path to the software or provider directory
# $2: software name
# $3: optional to omit sorting
function doCurlVersions() {
echo "Getting versions for ${1}"
local versions_url=$(cat "${1}/versions-url")
# range of major versions for Java
versions_url="${versions_url//\$\{major\}/[8-20]}"
local versions_url_op='awk -F '"'"'git/refs/tags/'"'"' '"'"' {print $2}'"'"' | awk -F '"'"'\"'"'"' '"'"'{print $1}'"'"' | awk NF'
if [ "${2}" != "helm" ] && [ "${2}" != "nodejs" ] && [ "${2}" != "vscode" ]
then
versions_url_op="${versions_url_op} | sed 's/v//'"
fi
if [ -f "${1}/versions-url-op" ]
then
local versions_url_op=$(cat "${1}/versions-url-op" | tr -d '\n')
fi
versions_url_op="${versions_url_op} | grep -i -Ev \"alpha|bad|beta|ce|cr|de|ec|extensionbuilders|good|heads|inside|list|next|pre|rc|rtm|sda-|servicing|test|translation|unstable|/\""
if [ -z "${3}" ]
then
versions_url_op="${versions_url_op} | sort -Vru"
fi
eval "curl -s "${versions_url}" | "${versions_url_op}"" >> "./${2}/available-versions.tmp"
}
for software in */;
do
software=${software::-1}
temp_path="./${software}/available-versions.tmp"
if [ ! -f "./${software}/versions" ]
then
doCurlVersions "./${software}" "${software}"
else
while IFS='<' read -r folder rest
do
if [ "${folder}" != "." ]
then
doCurlVersions "./${software}/${folder}" "${software}" -
fi
done < "./${software}/versions"
if [ "${software}" == "java" ]
then
# Java workaround: convert versions to a different format (e.g. 11.0.9_11 -> 11.0.9.0.0.11), sort them, and convert them back
sed -i 's/_/\.0\.0./' "${temp_path}" && sort -Vru -o "${temp_path}" "${temp_path}" && sed -i 's/\.0\.0./_/' "${temp_path}"
# Java 8 workaround: remove versions with dots (e.g. 8u272b10.1)
sed -i '/^8/{ /\./d }' "${temp_path}"
else
sort -Vru -o "${temp_path}" "${temp_path}"
fi
fi
# update available-versions if curl was successful
if [[ ! -z $(grep '[^[:space:]]' "${temp_path}") ]]
then
mv "${temp_path}" "./${software}/available-versions"
else
rm "${temp_path}"
echo "${software}: Crawling versions failed. 'available-versions' has not been updated."
fi
done