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

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

Issue 19406002: Utility for bootstrapping a local gerrit instance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
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 | Annotate | Revision Log
« 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
(Empty)
1 #!/bin/bash
2 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
cmp 2013/07/16 22:37:16 This line should be "The Chromium Authors", AFAIK.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 if [ -n "$1" ]; then
7 rundir="$1"
8 else
9 rundir="$(mktemp -d)"
cmp 2013/07/16 22:37:16 in other places in this file, $() is used without
10 fi
11
12 account_id=101
13 full_name='Test Account'
14 maximum_page_size='25'
15 password='test-password'
16 preferred_email="${username}@test.org"
17 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z')
18 username='test-username'
19
20 # The python code below for picking the "latest" gerrit release is cribbed and
21 # ported from the javascript at:
22 #
23 # http://gerrit-releases.storage.googleapis.com/index.html
24 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n oAcl'
25 curl --ssl-reqd -s $url | python <(cat <<EOF
26 # Reads json-encoded text from stdin in the format:
27 #
28 # {
29 # "items": [
30 # {
31 # "name": "gerrit-<version>.war",
32 # "md5Hash": "<base64 encoded md5sum>",
33 # },
34 # {
35 # "name": "gerrit-<version>.war",
36 # "md5Hash": "<base64 encoded md5sum>",
37 # },
38 # ...
39 # }
40 #
41 # ...and prints the name and md5sum of the latest non-release-candidate version.
42
43 import json
44 import re
45 import sys
46
47 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war')
48 j = json.load(sys.stdin)
49 items = [(x, gerrit_re.match(x['name'])) for x in j['items']]
50 items = [(x, m.group(1)) for x, m in items if m]
51 def _cmp(a, b):
52 an = a[1].replace('-rc', '.rc').split('.')
53 bn = b[1].replace('-rc', '.rc').split('.')
54 while len(an) < len(bn):
55 an.append('0')
56 while len(bn) < len(an):
57 bn.append('0')
58 for i in range(len(an)):
59 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i])
60 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i])
61 if ai != bi:
62 return -1 if ai > bi else 1
63 return 0
64 items.sort(cmp=_cmp)
65 for x in items:
66 if 'rc' not in x[0]['name']:
67 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash'])
68 sys.exit(0)
69 EOF
70 ) | xargs | while read name md5; do
71 # Download the latest gerrit version if necessary, and verify the md5sum.
72 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- |
73 sed 's/ //g')
74 if [ -f "./$name" ]; then
75 file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs)
76 if [ "$file_sum" = "$net_sum" ]; then
77 ln -sf "./$name" gerrit.war
78 break
79 else
80 rm -rf "./$name"
81 fi
82 fi
83 curl --ssl-reqd -s -o "./$name" "https://gerrit-releases.storage.googleapis.co m/$name"
cmp 2013/07/16 22:37:16 wrap at 80 chars (newline after "./$name" \)
84 file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs)
85 if [ "$file_sum" != "$net_sum" ]; then
86 echo "ERROR: md5sum mismatch when downloading $name" 1>&2
87 rm -rf "./$name"
88 exit 1
89 else
90 ln -sf "./$name" gerrit.war
91 fi
92 done
93
94 if [ ! -e "./gerrit.war" ]; then
95 echo "ERROR: No gerrit.war file or link present, and unable " 1>&2
96 echo " to download the latest version." 1>&2
97 exit 1
98 fi
99
100 # By default, gerrit only accepts https connections, which is a good thing. But
101 # for testing, it's convenient to enable plain http.
102 mkdir -p "${rundir}/etc"
103 cat <<EOF > "${rundir}/etc/gerrit.config"
104 [auth]
105 type = http
106 gitBasicAuth = true
107 EOF
108
109 # Initialize the gerrit instance.
110 java -jar "./gerrit.war" init --no-auto-start --batch -d "${rundir}"
111
112 # Set up the first user, with admin priveleges.
113 cat <<EOF | java -jar "./gerrit.war" gsql -d "${rundir}" > /dev/null
114 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});
115 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'gerrit:${username}');
116 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'username:${username}');
117 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($ {account_id}, '${preferred_email}', '${password}');
118 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id}, 1);
119 EOF
120
121 # Create a netrc file to authenticate as the first user.
122 mkdir -p "${rundir}/tmp"
123 cat <<EOF > "${rundir}/tmp/.netrc"
124 machine localhost login ${username} password ${password}
125 EOF
126
127 echo
128 echo "To start gerrit server:"
129 echo " ${rundir}/bin/gerrit.sh start"
130 echo
131 echo "To use the REST API:"
132 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>"
133 echo
134 echo "To stop the server:"
135 echo " ${rundir}/bin/gerrit.sh stop"
136 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