forked from redis/docker-library-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·69 lines (60 loc) · 1.96 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 -e
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
packagesUrl='https://raw.githubusercontent.com/antirez/redis-hashes/master/README'
packages="$(echo "$packagesUrl" | sed -r 's/[^a-zA-Z.-]+/-/g')"
curl -fsSL "$packagesUrl" > "$packages"
travisEnv=
for version in "${versions[@]}"; do
rcVersion="${version%-rc}"
line="$(
awk '
{ gsub(/^redis-|[.]tar[.]gz$/, "", $2) }
$1 == "hash" && $2 ~ /^'"$rcVersion"'([.]|$)/ { print }
' "$packages" \
| sort -rV \
| head -1
)"
if [ -n "$line" ]; then
fullVersion="$(cut -d' ' -f2 <<<"$line")"
downloadUrl="$(cut -d' ' -f5 <<<"$line")"
shaHash="$(cut -d' ' -f4 <<<"$line")"
shaType="$(cut -d' ' -f3 <<<"$line")"
elif [ "$version" != "$rcVersion" ] && fullVersion="$(
git ls-remote --tags https://github.com/antirez/redis.git "refs/tags/$rcVersion*" \
| cut -d/ -f3 \
| cut -d^ -f1 \
| sort -urV \
| head -1
)" && [ -n "$fullVersion" ]; then
downloadUrl="https://github.com/antirez/redis/archive/$fullVersion.tar.gz"
shaType='sha256'
shaHash="$(curl -fsSL "$downloadUrl" | "${shaType}sum" | cut -d' ' -f1)"
else
echo >&2 "error: full version for $version cannot be determined"
exit 1
fi
[ "$shaType" = 'sha256' ] || [ "$shaType" = 'sha1' ]
(
set -x
sed -ri \
-e 's/^(ENV REDIS_VERSION) .*/\1 '"$fullVersion"'/' \
-e 's!^(ENV REDIS_DOWNLOAD_URL) .*!\1 '"$downloadUrl"'!' \
-e 's/^(ENV REDIS_DOWNLOAD_SHA) .*/\1 '"$shaHash"'/' \
-e 's!sha[0-9]+sum!'"$shaType"'sum!g' \
"$version"/{,*/}Dockerfile
)
for variant in alpine 32bit; do
[ -d "$version/$variant" ] || continue
travisEnv='\n - VERSION='"$version VARIANT=$variant$travisEnv"
done
travisEnv='\n - VERSION='"$version VARIANT=$travisEnv"
done
travis="$(awk -v 'RS=\n\n' '$1 == "env:" { $0 = "env:'"$travisEnv"'" } { printf "%s%s", $0, RS }' .travis.yml)"
echo "$travis" > .travis.yml
rm "$packages"