-
-
Notifications
You must be signed in to change notification settings - Fork 267
/
Copy pathgenerate-htaccess.sh
executable file
·138 lines (101 loc) · 4.66 KB
/
generate-htaccess.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
#!/bin/bash
USAGE="Usage: $0 [<release> ...]
"
[[ $# -gt 0 ]] || { echo "${USAGE}Expected at least one argument." >&2 ; exit 1 ; }
set -o pipefail
set -o errexit
set -o nounset
cat <<EOF
# THIS FILE IS GENERATED
#
# See: <https://github.com/jenkins-infra/update-center2/blob/master/site/generate-htaccess.sh>
RewriteEngine on
# https://github.com/jenkinsci/jenkins/blob/56b6623915c50b4a2ef994a143a8fe0829587f3c/core/src/main/java/hudson/model/UpdateCenter.java#L1182-L1207
RewriteCond %{QUERY_STRING} ^.*uctest$
RewriteRule ^(|.+/)(update\-center.*\.(json|html)+) /uctest.json [NC,L]
EOF
echo "# Version-specific rulesets generated by generate.sh"
n=$#
versions=( "$@" )
newestStable=
oldestStable=
oldestWeekly=
for (( i = n-1 ; i >= 0 ; i-- )) ; do
version="${versions[i]}"
IFS=. read -ra versionPieces <<< "$version"
major=${versionPieces[0]}
minor=${versionPieces[1]}
patch=
if [[ ${#versionPieces[@]} -gt 2 ]] ; then
patch=${versionPieces[2]}
fi
if [[ "$version" =~ ^2[.][0-9]+[.][0-9]$ ]] ; then
# This is an LTS version
if [[ -z "$newestStable" ]] ; then
newestStable="$version"
fi
cat <<EOF
# If major > ${major} or major = ${major} and minor > ${minor} or major = ${major} and minor = ${minor} and patch >= ${patch}, use this LTS update site
RewriteCond %{QUERY_STRING} ^.*version=(\d)\.(\d+)\.(\d+)(|[-].*)$ [NC]
RewriteCond %1 >${major}
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-stable-${major}\.${minor}\.${patch}%{REQUEST_URI}? [NC,L,R]
RewriteCond %{QUERY_STRING} ^.*version=(\d)\.(\d+)\.(\d+)(|[-].*)$ [NC]
RewriteCond %1 =${major}
RewriteCond %2 >${minor}
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-stable-${major}\.${minor}\.${patch}%{REQUEST_URI}? [NC,L,R]
RewriteCond %{QUERY_STRING} ^.*version=(\d)\.(\d+)\.(\d+)(|[-].*)$ [NC]
RewriteCond %1 =${major}
RewriteCond %2 =${minor}
RewriteCond %3 >=${patch}
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-stable-${major}\.${minor}\.${patch}%{REQUEST_URI}? [NC,L,R]
EOF
oldestStable="$version"
else
# This is a weekly version
# Split our version up into an array for rewriting
# 1.651 becomes (1 651)
oldestWeekly="$version"
cat <<EOF
# If major > ${major} or major = ${major} and minor >= ${minor}, use this weekly update site
RewriteCond %{QUERY_STRING} ^.*version=(\d)\.(\d+)(|[-].*)$ [NC]
RewriteCond %1 >${major}
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-${major}\.${minor}%{REQUEST_URI}? [NC,L,R]
RewriteCond %{QUERY_STRING} ^.*version=(\d)\.(\d+)(|[-].*)$ [NC]
RewriteCond %1 =${major}
RewriteCond %2 >=${minor}
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-${major}\.${minor}%{REQUEST_URI}? [NC,L,R]
EOF
fi
done
cat <<EOF
# First LTS update site (stable-$oldestStable) gets all older LTS releases
RewriteCond %{QUERY_STRING} ^.*version=\d\.(\d+)\.\d+(|[-].*)$ [NC]
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-stable-${oldestStable}%{REQUEST_URI}? [NC,L,R]
RewriteCond %{QUERY_STRING} ^.*version=\d\.(\d+)+(|[-].*)$ [NC]
RewriteRule ^(update\-center.*\.(json|html)+) /dynamic-${oldestWeekly}%{REQUEST_URI}? [NC,L,R]
EOF
echo "# Add a RewriteRule for /stable which will always rewrite to the last LTS site we have"
cat <<EOF
RewriteRule ^stable/(.+) "/dynamic-stable-${newestStable}/\$1" [NC,L,R]
EOF
# Further static rules
cat <<EOF
# These are static rules
# If that all failed, but we have an update center, let's go to current
RewriteRule ^update\-center.*\.(json|html)+ /current%{REQUEST_URI}? [NC,L,R=301]
RewriteRule ^latestCore\.txt /current%{REQUEST_URI}? [NC,L,R=301]
# Ensure /release-history.json goes to the right place
RewriteRule ^release\-history\.json$ /current%{REQUEST_URI}? [NC,L,R=301]
# Ensure /plugin-documentation-urls.json goes to the right place
RewriteRule ^plugin\-documentation\-urls\.json$ /current%{REQUEST_URI}? [NC,L,R=301]
# Ensure /plugin-versions.json goes to the right place
RewriteRule ^plugin\-versions\.json$ /current%{REQUEST_URI}? [NC,L,R=301]
DirectoryIndex index.html
# download/* directories contain virtual URL spaces for redirecting download traffic to mirrors.
# 'latest' need special handling here since they're not getting mirrored properly to get.jenkins.io
RewriteRule ^download/war/latest/jenkins[.]war$ https://updates.jenkins.io/latest/jenkins.war [NC,L,R=302]
RewriteRule ^download/plugins/(.*)/latest/(.+)[.]hpi$ https://updates.jenkins.io/latest/\$2.hpi [NC,L,R=302]
RewriteRule ^download/war/([0-9]+[.][0-9]+[.][0-9]+/jenkins)[.]war$ https://get.jenkins.io/war-stable/\$1.war [NC,L,R=302]
RewriteRule ^download/war/(.+)[.]war$ https://get.jenkins.io/war/\$1.war [NC,L,R=302]
RewriteRule ^download/plugins/(.+)[.]hpi$ https://get.jenkins.io/plugins/\$1.hpi [NC,L,R=302]
EOF