forked from docker-library/redmine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·86 lines (71 loc) · 2.63 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
#!/usr/bin/env bash
set -Eeuo pipefail
# see https://www.redmine.org/projects/redmine/wiki/redmineinstall
defaultRubyVersion='3.1'
declare -A rubyVersions=(
[4.2]='2.7'
)
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
versions=( */ )
fi
versions=( "${versions[@]%/}" )
# https://github.com/docker-library/redmine/issues/256
downloadsPage="$(curl -fsSL 'https://redmine.org/projects/redmine/wiki/Download')"
releasesUrl='https://www.redmine.org/releases'
versionsPage="$(curl -fsSL "$releasesUrl")"
allVersions="$(
sed <<<"$versionsPage"$'\n'"$downloadsPage" \
-rne 's/.*redmine-([0-9.]+)[.]tar[.]gz.*/\1/p' \
| sort -ruV
)"
passenger="$(curl -fsSL 'https://rubygems.org/api/v1/gems/passenger.json' | sed -r 's/^.*"version":"([^"]+)".*$/\1/')"
for version in "${versions[@]}"; do
ourVersions="$(grep -E "^$version[.]" <<<"$allVersions")"
fullVersion=
for tryVersion in $ourVersions; do
url="$releasesUrl/redmine-$tryVersion.tar.gz"
if sha256="$(curl -fsSL "$url.sha256" 2>/dev/null)" && sha256="$(cut -d' ' -f1 <<<"$sha256")" && [ -n "$sha256" ]; then
fullVersion="$tryVersion"
break
fi
if urlLine="$(grep -oEm1 'href="https?://[^"]+/'"redmine-$tryVersion.tar.gz"'".*sha256:.*' <<<"$downloadsPage")" && url="$(cut -d'"' -f2 <<<"$urlLine")" && [ -n "$url" ] && sha256="$(grep -oEm1 'sha256:[[:space:]]*[a-f0-9]{64}' <<<"$urlLine")" && [ -n "$sha256" ] && sha256="${sha256: -64}"; then
fullVersion="$tryVersion"
break
fi
done
if [ -z "$fullVersion" ]; then
echo >&2 "error: failed to find full version for '$version'"
exit 1
fi
rubyVersion="${rubyVersions[$version]:-$defaultRubyVersion}"
text="ruby $rubyVersion"
doPassenger=
if [ "$version" = '4.2' ]; then
text+="; passenger $passenger"
doPassenger=1
fi
echo "$version: $fullVersion ($text)"
commonSedArgs=(
-r
-e 's/%%REDMINE_VERSION%%/'"$fullVersion"'/'
-e 's/%%RUBY_VERSION%%/'"$rubyVersion"'/'
-e 's!%%REDMINE_DOWNLOAD_URL%%!'"$url"'!'
-e 's/%%REDMINE_DOWNLOAD_SHA256%%/'"$sha256"'/'
-e 's/%%REDMINE%%/redmine:'"$version"'/'
)
mkdir -p "$version"
cp docker-entrypoint.sh "$version/"
sed "${commonSedArgs[@]}" Dockerfile-debian.template > "$version/Dockerfile"
if [ -n "$doPassenger" ]; then
mkdir -p "$version/passenger"
sed "${commonSedArgs[@]}" \
-e 's/%%PASSENGER_VERSION%%/'"$passenger"'/' \
Dockerfile-passenger.template > "$version/passenger/Dockerfile"
fi
mkdir -p "$version/alpine"
cp docker-entrypoint.sh "$version/alpine/"
sed -i -e 's/gosu/su-exec/g' "$version/alpine/docker-entrypoint.sh"
sed "${commonSedArgs[@]}" Dockerfile-alpine.template > "$version/alpine/Dockerfile"
done