forked from docker-library/mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
versions.sh
executable file
·141 lines (125 loc) · 3.88 KB
/
versions.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
141
#!/usr/bin/env bash
set -Eeuo pipefail
defaultDebianSuite='bullseye'
declare -A debianSuites=(
[5.7]='buster'
)
defaultOracleVariant='8-slim'
declare -A oracleVariants=(
[5.7]='7-slim'
)
# https://repo.mysql.com/yum/mysql-8.0-community/docker/
declare -A bashbrewArchToRpmArch=(
[amd64]='x86_64'
[arm64v8]='aarch64'
)
fetch_rpm_versions() {
local repo="$1"; shift
local arch="$1"; shift
local oracleVersion="$1"; shift
local package="$1"; shift
curl -fsSL "$repo/$arch/" 2>/dev/null \
| grep -oE '"'"$package"'-[0-9][^"]+[.]el'"$oracleVersion"'[.]'"$arch"'[.]rpm"' \
| sed -r 's/^"'"$package-|[.]$arch[.]rpm"'"$//g' \
| sort -rV
}
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( *.*/ )
json='{}'
else
json="$(< versions.json)"
fi
versions=( "${versions[@]%/}" )
for version in "${versions[@]}"; do
export version
doc='{}'
if [[ "$version" == 5.* ]] || [ "$version" = '8.0' ]; then
debianSuite="${debianSuites[$version]:-$defaultDebianSuite}"
debianVersion="$(
curl -fsSL "https://repo.mysql.com/apt/debian/dists/$debianSuite/mysql-$version/binary-amd64/Packages.gz" \
| gunzip \
| awk -F ': ' '
$1 == "Package" {
pkg = $2
next
}
pkg == "mysql-server" && $1 == "Version" {
print $2
}
'
)"
# example 8.0.22-1debian10 => 8.0.22
baseVersion="${debianVersion%-*}"
export baseVersion debianSuite debianVersion
doc="$(
jq <<<"$doc" -c '
. += {
version: env.baseVersion,
debian: {
architectures: [ "amd64" ],
suite: env.debianSuite,
version: env.debianVersion,
},
}
'
)"
fi
oracleVariant="${oracleVariants[$version]:-$defaultOracleVariant}"
oracleVersion="${oracleVariant%%-*}" # "7", etc
rpmVersion=
shellVersion=
doc="$(jq <<<"$doc" -c '. += { oracle: { architectures: [] } }')"
for bashbrewArch in $(xargs -n1 <<<"${!bashbrewArchToRpmArch[*]}" | sort | xargs); do
rpmArch="${bashbrewArchToRpmArch[$bashbrewArch]}"
rpmRepo="https://repo.mysql.com/yum/mysql-$version-community/docker/el/$oracleVersion"
archVersions="$(
fetch_rpm_versions "$rpmRepo" "$rpmArch" "$oracleVersion" 'mysql-community-server-minimal' \
| grep -E "^$version[.]" \
|| :
)"
archVersion="$(head -1 <<<"$archVersions")"
[ -n "$archVersion" ] || continue
if [ -z "$rpmVersion" ]; then
rpmVersion="$archVersion"
elif [ "$rpmVersion" != "$archVersion" ]; then
echo >&2 "error: $version architecture version mismatch! ('$rpmVersion' vs '$archVersion' on '$rpmArch'/'$bashbrewArch')"
exit 1
fi
shellArchVersions="$(fetch_rpm_versions "https://repo.mysql.com/yum/mysql-tools-community/el/$oracleVersion" "$rpmArch" "$oracleVersion" 'mysql-shell')"
shellArchVersion="$(head -1 <<<"$shellArchVersions")"
if [ -z "$shellVersion" ]; then
shellVersion="$shellArchVersion"
elif [ "$shellVersion" != "$shellArchVersion" ]; then
echo >&2 "error: shell version mismatch! ('$shellVersion' vs '$shellArchVersion' on '$rpmArch'/'$bashbrewArch')"
exit 1
fi
export bashbrewArch
doc="$(jq <<<"$doc" -c '.oracle.architectures = (.oracle.architectures + [ env.bashbrewArch ] | sort)')"
done
baseVersion="$(jq <<<"$doc" -r '.version // ""')"
# example 8.0.22-1.el7 => 8.0.22
oracleBaseVersion="${rpmVersion%-*}"
: "${baseVersion:=$oracleBaseVersion}"
if [ "$baseVersion" != "$oracleBaseVersion" ]; then
echo >&2 "error: Oracle and Debian version mismatch! ('$oracleBaseVersion' vs '$baseVersion')"
exit 1
fi
export baseVersion rpmVersion shellVersion oracleVariant
doc="$(jq <<<"$doc" -c '
. += {
version: env.baseVersion,
oracle: (.oracle + {
version: env.rpmVersion,
variant: env.oracleVariant,
}),
"mysql-shell": {
version: env.shellVersion,
},
}
')"
echo "$version: $baseVersion"
json="$(jq <<<"$json" -c --argjson doc "$doc" '.[env.version] = $doc')"
done
jq <<<"$json" -S . > versions.json