Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Side by Side Diff: testing_support/gerrit-init.sh

Issue 20441002: Ability to install custom Gerrit version. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
7
6 if [ -n "$1" ]; then 8 if [ -n "$1" ]; then
7 rundir="$1" 9 rundir="$1"
8 else 10 else
9 rundir=$(mktemp -d) 11 rundir=$(mktemp -d)
10 fi 12 fi
11 13
14 if [ -n "$2" ]; then
szager1 2013/07/25 19:53:50 Once we have more than one positional parameter, w
Vadim Sh. 2013/07/25 21:42:32 Done.
15 version="$2"
16 else
17 version="latest"
18 fi
19
12 this_dir=$(dirname $0) 20 this_dir=$(dirname $0)
13 gerrit_exe="$this_dir/gerrit.war" 21 gerrit_exe="$this_dir/gerrit.war"
14 22
15 account_id=101 23 account_id=101
16 full_name='Test Account' 24 full_name='Test Account'
17 maximum_page_size='25' 25 maximum_page_size='25'
18 password='test-password' 26 password='test-password'
19 preferred_email="test-username@test.org" 27 preferred_email="test-username@test.org"
20 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z') 28 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z')
21 username='test-username' 29 username='test-username'
22 30
23 # The python code below for picking the "latest" gerrit release is cribbed and 31 # The python code below for picking the "latest" gerrit release is cribbed and
24 # ported from the javascript at: 32 # ported from the javascript at:
25 # 33 #
26 # http://gerrit-releases.storage.googleapis.com/index.html 34 # http://gerrit-releases.storage.googleapis.com/index.html
27 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n oAcl' 35 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n oAcl'
28 curl --ssl-reqd -s $url | python <(cat <<EOF 36 curl --ssl-reqd -s $url | python <(cat <<EOF
29 # Reads json-encoded text from stdin in the format: 37 # Receives Gerrit version via command line and reads json-encoded
38 # text from stdin in the format:
30 # 39 #
31 # { 40 # {
32 # "items": [ 41 # "items": [
33 # { 42 # {
34 # "name": "gerrit-<version>.war", 43 # "name": "gerrit-<version>.war",
35 # "md5Hash": "<base64 encoded md5sum>", 44 # "md5Hash": "<base64 encoded md5sum>",
36 # }, 45 # },
37 # { 46 # {
38 # "name": "gerrit-<version>.war", 47 # "name": "gerrit-<version>.war",
39 # "md5Hash": "<base64 encoded md5sum>", 48 # "md5Hash": "<base64 encoded md5sum>",
40 # }, 49 # },
41 # ... 50 # ...
42 # } 51 # }
43 # 52 #
44 # ...and prints the name and md5sum of the latest non-release-candidate version. 53 # ...and prints the name and md5sum of the corresponding *.war file.
45 54
46 import json 55 import json
47 import re 56 import re
48 import sys 57 import sys
49 58
59 requested_version = sys.argv[1]
szager1 2013/07/25 19:53:50 requested_version = sys.argv[1] if len(sys.argv) >
Vadim Sh. 2013/07/25 21:42:32 Done.
60
szager1 2013/07/25 19:53:50 Remove blank line.
Vadim Sh. 2013/07/25 21:42:32 Done.
50 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') 61 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war')
51 j = json.load(sys.stdin) 62 j = json.load(sys.stdin)
63
szager1 2013/07/25 19:53:50 Remove blank line.
Vadim Sh. 2013/07/25 21:42:32 Done.
52 items = [(x, gerrit_re.match(x['name'])) for x in j['items']] 64 items = [(x, gerrit_re.match(x['name'])) for x in j['items']]
53 items = [(x, m.group(1)) for x, m in items if m] 65 items = [(x, m.group(1)) for x, m in items if m]
66
szager1 2013/07/25 19:53:50 Remove blank line.
Vadim Sh. 2013/07/25 21:42:32 Done. Is there any particular reason you don't lik
szager1 2013/07/25 21:56:17 The blank lines don't improve the readability of t
54 def _cmp(a, b): 67 def _cmp(a, b):
55 an = a[1].replace('-rc', '.rc').split('.') 68 an = a[1].replace('-rc', '.rc').split('.')
56 bn = b[1].replace('-rc', '.rc').split('.') 69 bn = b[1].replace('-rc', '.rc').split('.')
57 while len(an) < len(bn): 70 while len(an) < len(bn):
58 an.append('0') 71 an.append('0')
59 while len(bn) < len(an): 72 while len(bn) < len(an):
60 bn.append('0') 73 bn.append('0')
61 for i in range(len(an)): 74 for i in range(len(an)):
62 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i]) 75 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i])
63 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i]) 76 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i])
64 if ai != bi: 77 if ai != bi:
65 return -1 if ai > bi else 1 78 return -1 if ai > bi else 1
66 return 0 79 return 0
67 items.sort(cmp=_cmp) 80
68 for x in items: 81 found = None
szager1 2013/07/25 19:53:50 The whole rest of the script should be: if reques
Vadim Sh. 2013/07/25 21:42:32 Done.
69 if 'rc' not in x[0]['name']: 82 if requested_version == 'latest':
70 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) 83 for info, version in sorted(items, cmp=_cmp):
71 sys.exit(0) 84 if 'rc' not in info['name']:
85 found = info
86 break
87 else:
88 for info, version in items:
89 if version == requested_version:
90 found = info
91 break
92
93 if not found:
94 print >> sys.stderr, 'No such Gerrit version: %s' % (version,)
szager1 2013/07/25 19:53:50 print >> sys.stderr, 'No such Gerrit version: %s'
Vadim Sh. 2013/07/25 21:42:32 Done.
95 sys.exit(1)
96 else:
97 print '"%s" "%s"' % (found['name'], found['md5Hash'])
98 sys.exit(0)
72 EOF 99 EOF
73 ) | xargs | while read name md5; do 100 ) "$version" | xargs | while read name md5; do
74 # Download the latest gerrit version if necessary, and verify the md5sum. 101 # Download the requested gerrit version if necessary, and verify the md5sum.
102 echo "Installing $name..."
75 target="$this_dir/$name" 103 target="$this_dir/$name"
76 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | 104 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- |
77 sed 's/ //g') 105 sed 's/ //g')
78 if [ -f "$target" ]; then 106 if [ -f "$target" ]; then
79 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) 107 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs)
80 if [ "$file_sum" = "$net_sum" ]; then 108 if [ "$file_sum" = "$net_sum" ]; then
81 ln -sf "$name" "$gerrit_exe" 109 ln -sf "$name" "$gerrit_exe"
82 break 110 break
83 else 111 else
84 rm -rf "$target" 112 rm -rf "$target"
(...skipping 22 matching lines...) Expand all
107 mkdir -p "${rundir}/etc" 135 mkdir -p "${rundir}/etc"
108 cat <<EOF > "${rundir}/etc/gerrit.config" 136 cat <<EOF > "${rundir}/etc/gerrit.config"
109 [auth] 137 [auth]
110 type = http 138 type = http
111 gitBasicAuth = true 139 gitBasicAuth = true
112 EOF 140 EOF
113 141
114 # Initialize the gerrit instance. 142 # Initialize the gerrit instance.
115 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" 143 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}"
116 144
145 # Create SSH key pair for the first user.
146 if [ ! -e "${rundir}/key/id_rsa" ]; then
szager1 2013/07/25 19:53:50 Put the key in $rundir/tmp, and don't check whethe
Vadim Sh. 2013/07/25 21:42:32 Do we support rerunning gerrit_init.sh on top of e
147 mkdir -p "${rundir}/key"
148 ssh-keygen -t rsa -q -f "${rundir}/key/id_rsa" -N ""
149 fi
150 ssh_public_key="$(cat ${rundir}/key/id_rsa.pub)"
151
117 # Set up the first user, with admin priveleges. 152 # Set up the first user, with admin priveleges.
118 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null 153 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null
119 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}); 154 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});
120 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'gerrit:${username}'); 155 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'gerrit:${username}');
121 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'username:${username}'); 156 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'username:${username}');
122 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($ {account_id}, '${preferred_email}', '${password}'); 157 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($ {account_id}, '${preferred_email}', '${password}');
123 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id}, 1); 158 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id}, 1);
159 INSERT INTO ACCOUNT_SSH_KEYS (ACCOUNT_ID, SSH_PUBLIC_KEY, VALID, SEQ) VALUES (${ account_id}, '${ssh_public_key}', 'Y', 0);
124 EOF 160 EOF
125 161
126 # Create a netrc file to authenticate as the first user. 162 # Create a netrc file to authenticate as the first user.
127 mkdir -p "${rundir}/tmp" 163 mkdir -p "${rundir}/tmp"
128 cat <<EOF > "${rundir}/tmp/.netrc" 164 cat <<EOF > "${rundir}/tmp/.netrc"
129 machine localhost login ${username} password ${password} 165 machine localhost login ${username} password ${password}
130 EOF 166 EOF
131 167
132 # Create a .git-credentials file, to enable password-less push. 168 # Create a .git-credentials file, to enable password-less push.
133 cat <<EOF > "${rundir}/tmp/.git-credentials" 169 cat <<EOF > "${rundir}/tmp/.git-credentials"
134 http://${username}:${password}@localhost:8080 170 http://${username}:${password}@localhost:8080
135 EOF 171 EOF
136 172
137 echo 173 echo
138 echo "To start gerrit server:" 174 echo "To start gerrit server:"
139 echo " ${rundir}/bin/gerrit.sh start" 175 echo " ${rundir}/bin/gerrit.sh start"
140 echo 176 echo
141 echo "To use the REST API:" 177 echo "To use the REST API:"
142 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" 178 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>"
143 echo 179 echo
180 echo "To use SSH API:"
181 echo " ssh ${username}@localhost -q -p 29418 -i ${rundir}/key/id_rsa gerrit"
szager1 2013/07/25 19:53:50 Don't put '-q' here. If there are ssh errors/warn
Vadim Sh. 2013/07/25 21:42:32 Done.
182 echo
144 echo "To enable 'git push' without a password prompt:" 183 echo "To enable 'git push' without a password prompt:"
145 echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credential s'" 184 echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credential s'"
146 echo 185 echo
147 echo "To stop the server:" 186 echo "To stop the server:"
148 echo " ${rundir}/bin/gerrit.sh stop" 187 echo " ${rundir}/bin/gerrit.sh stop"
149 echo 188 echo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698