forked from docker-library/ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·69 lines (59 loc) · 2.16 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
#!/bin/bash
set -eo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
releasePage="$(curl -fsSL 'https://www.ruby-lang.org/en/downloads/releases/')"
latest_gem_version() {
curl -fsSL "https://rubygems.org/api/v1/gems/$1.json" | sed -r 's/^.*"version":"([^"]+)".*$/\1/'
}
rubygems="$(latest_gem_version rubygems-update)"
bundler="$(latest_gem_version bundler)"
travisEnv=
for version in "${versions[@]}"; do
rcGrepV='-v'
rcVersion="${version%-rc}"
if [ "$rcVersion" != "$version" ]; then
rcGrepV=
fi
IFS=$'\n'; allVersions=(
$(curl -fsSL --compressed "https://cache.ruby-lang.org/pub/ruby/$rcVersion/" \
| grep -E '<a href="ruby-'"$rcVersion"'.[^"]+\.tar\.xz' \
| grep $rcGrepV -E 'preview|rc' \
| sed -r 's!.*<a href="ruby-([^"]+)\.tar\.xz.*!\1!' \
| sort -rV)
); unset IFS
fullVersion=
for tryVersion in "${allVersions[@]}"; do
if echo "$releasePage" | grep -q "Ruby ${tryVersion}<"; then
fullVersion="$tryVersion"
break
fi
done
if [ -z "$fullVersion" ]; then
echo >&2 "warning: cannot determine sha for $version (tried all of ${allVersions[*]}); skipping"
continue
fi
versionReleasePage="$(echo "$releasePage" | grep "<td>Ruby $fullVersion</td>" -A 2 | awk -F '"' '$1 == "<td><a href=" { print $2; exit }')"
shaVal="$(curl -fsSL "https://www.ruby-lang.org/$versionReleasePage" |tac|tac| grep "ruby-$fullVersion.tar.xz" -A 5 | awk '/^SHA256:/ { print $2; exit }')"
sedStr="
s!%%VERSION%%!$version!g;
s!%%FULL_VERSION%%!$fullVersion!g;
s!%%SHA256%%!$shaVal!g;
s!%%RUBYGEMS%%!$rubygems!g;
s!%%BUNDLER%%!$bundler!g;
"
echo "$version: $fullVersion; rubygems $rubygems, bundler $bundler; $shaVal"
for variant in alpine slim onbuild ''; do
[ -d "$version/$variant" ] || continue
sed -r "$sedStr" "Dockerfile${variant:+-$variant}.template" > "$version/$variant/Dockerfile"
if [ "$variant" != 'onbuild' ]; then
travisEnv='\n - VERSION='"$version VARIANT=$variant$travisEnv"
fi
done
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml