OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 set -e | 6 set -e |
7 | 7 |
8 http_port=8080 | 8 http_port=8080 |
9 ssh_port=29418 | 9 ssh_port=29418 |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 # ... | 70 # ... |
71 # } | 71 # } |
72 # | 72 # |
73 # ...and prints the name and md5sum of the corresponding *.war file. | 73 # ...and prints the name and md5sum of the corresponding *.war file. |
74 | 74 |
75 import json | 75 import json |
76 import re | 76 import re |
77 import sys | 77 import sys |
78 | 78 |
79 requested_version = sys.argv[1] if len(sys.argv) > 1 else None | 79 requested_version = sys.argv[1] if len(sys.argv) > 1 else None |
80 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') | 80 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+)(-rc[0-9]+)?[.]war') |
81 j = json.load(sys.stdin) | 81 j = json.load(sys.stdin) |
82 items = [(x, gerrit_re.match(x['name'])) for x in j['items']] | 82 items = [(x, gerrit_re.match(x['name'])) for x in j['items']] |
83 items = [(x, m.group(1)) for x, m in items if m] | 83 items = [(x, m.group(1), m.group(2)) for x, m in items if m] |
84 def _cmp(a, b): | 84 def _cmp(a, b): |
85 an = a[1].replace('-rc', '.rc').split('.') | 85 an = a[1].split('.') |
86 bn = b[1].replace('-rc', '.rc').split('.') | 86 bn = b[1].split('.') |
87 while len(an) < len(bn): | 87 while len(an) < len(bn): |
88 an.append('0') | 88 an.append('0') |
89 while len(bn) < len(an): | 89 while len(bn) < len(an): |
90 bn.append('0') | 90 bn.append('0') |
| 91 an.append(a[2][3:] if a[2] else '1000') |
| 92 bn.append(b[2][3:] if b[2] else '1000') |
91 for i in range(len(an)): | 93 for i in range(len(an)): |
92 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i]) | 94 if an[i] != bn[i]: |
93 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i]) | 95 return -1 if int(an[i]) > int(bn[i]) else 1 |
94 if ai != bi: | |
95 return -1 if ai > bi else 1 | |
96 return 0 | 96 return 0 |
97 | 97 |
98 if requested_version: | 98 if requested_version: |
99 for info, version in items: | 99 for info, version in items: |
100 if version == requested_version: | 100 if version == requested_version: |
101 print '"%s" "%s"' % (info['name'], info['md5Hash']) | 101 print '"%s" "%s"' % (info['name'], info['md5Hash']) |
102 sys.exit(0) | 102 sys.exit(0) |
103 print >> sys.stderr, 'No such Gerrit version: %s' % requested_version | 103 print >> sys.stderr, 'No such Gerrit version: %s' % requested_version |
104 sys.exit(1) | 104 sys.exit(1) |
105 | 105 |
106 items.sort(cmp=_cmp) | 106 items.sort(cmp=_cmp) |
107 for x in items: | 107 for x in items: |
108 if 'rc' not in x[0]['name']: | 108 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) |
109 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) | 109 sys.exit(0) |
110 sys.exit(0) | |
111 EOF | 110 EOF |
112 ) "$version" | xargs | while read name md5; do | 111 ) "$version" | xargs | while read name md5; do |
113 # Download the requested gerrit version if necessary, and verify the md5sum. | 112 # Download the requested gerrit version if necessary, and verify the md5sum. |
114 target="$this_dir/$name" | 113 target="$this_dir/$name" |
115 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | | 114 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | |
116 sed 's/ //g') | 115 sed 's/ //g') |
117 if [ -f "$target" ]; then | 116 if [ -f "$target" ]; then |
118 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) | 117 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) |
119 if [ "$file_sum" = "$net_sum" ]; then | 118 if [ "$file_sum" = "$net_sum" ]; then |
120 ln -sf "$name" "$gerrit_exe" | 119 ln -sf "$name" "$gerrit_exe" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 listenUrl = http://*:${http_port}/ | 154 listenUrl = http://*:${http_port}/ |
156 [sshd] | 155 [sshd] |
157 listenAddress = *:${ssh_port} | 156 listenAddress = *:${ssh_port} |
158 [sendemail] | 157 [sendemail] |
159 enable = false | 158 enable = false |
160 [container] | 159 [container] |
161 javaOptions = -Duser.home=${rundir}/tmp | 160 javaOptions = -Duser.home=${rundir}/tmp |
162 EOF | 161 EOF |
163 | 162 |
164 # Initialize the gerrit instance. | 163 # Initialize the gerrit instance. |
165 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" | 164 java -jar "$gerrit_exe" init --no-auto-start --batch --install-plugin=download-c
ommands -d "${rundir}" |
166 | 165 |
167 # Create SSH key pair for the first user. | 166 # Create SSH key pair for the first user. |
168 mkdir -p "${rundir}/tmp" | 167 mkdir -p "${rundir}/tmp" |
169 ssh-keygen -t rsa -q -f "${rundir}/tmp/id_rsa" -N "" | 168 ssh-keygen -t rsa -q -f "${rundir}/tmp/id_rsa" -N "" |
170 ssh_public_key="$(cat ${rundir}/tmp/id_rsa.pub)" | 169 ssh_public_key="$(cat ${rundir}/tmp/id_rsa.pub)" |
171 | 170 |
172 # Set up the first user, with admin priveleges. | 171 # Set up the first user, with admin priveleges. |
173 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null | 172 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null |
174 INSERT INTO ACCOUNTS (FULL_NAME, MAXIMUM_PAGE_SIZE, PREFERRED_EMAIL, REGISTERED_
ON, ACCOUNT_ID) VALUES ('${full_name}', ${maximum_page_size}, '${preferred_email
}', '${registered_on}', ${account_id}); | 173 INSERT INTO ACCOUNTS (FULL_NAME, MAXIMUM_PAGE_SIZE, PREFERRED_EMAIL, REGISTERED_
ON, ACCOUNT_ID) VALUES ('${full_name}', ${maximum_page_size}, '${preferred_email
}', '${registered_on}', ${account_id}); |
175 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); | 174 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); |
(...skipping 24 matching lines...) Expand all Loading... |
200 To use SSH API: | 199 To use SSH API: |
201 ssh ${username}@localhost -p ${ssh_port} -i ${rundir}/tmp/id_rsa gerrit | 200 ssh ${username}@localhost -p ${ssh_port} -i ${rundir}/tmp/id_rsa gerrit |
202 | 201 |
203 To enable 'git push' without a password prompt: | 202 To enable 'git push' without a password prompt: |
204 git config credential.helper 'store --file=${rundir}/tmp/.git-credentials' | 203 git config credential.helper 'store --file=${rundir}/tmp/.git-credentials' |
205 | 204 |
206 To stop the server: | 205 To stop the server: |
207 ${rundir}/bin/gerrit.sh stop | 206 ${rundir}/bin/gerrit.sh stop |
208 | 207 |
209 EOF | 208 EOF |
OLD | NEW |