OLD | NEW |
---|---|
(Empty) | |
1 #!/bin/bash | |
2 | |
cmp
2013/07/16 21:54:22
remove this empty line
szager1
2013/07/16 22:23:31
Done.
| |
3 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 if [ -n "$1" ]; then | |
8 rundir="$1" | |
9 else | |
10 rundir="$(mktemp -d)" | |
11 fi | |
12 | |
13 account_id=101 | |
14 full_name='Test Account' | |
15 maximum_page_size='25' | |
16 password='test-password' | |
17 username='test-username' | |
18 preferred_email="${username}@test.org" | |
19 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z') | |
cmp
2013/07/16 21:54:22
alphabetically order lines 13-19
szager1
2013/07/16 22:23:31
Done.
| |
20 | |
21 root=$(dirname "$0") | |
cmp
2013/07/16 21:54:22
this variable is not used, delete it?
szager1
2013/07/16 22:23:31
Done.
| |
22 | |
23 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n oAcl' | |
cmp
2013/07/16 21:54:22
before line 23, insert a comment that says somethi
szager1
2013/07/16 22:23:31
Done.
| |
24 curl -s $url | python <(cat <<EOF | |
cmp
2013/07/16 21:54:22
can you add some flags here that cause curl to be
szager1
2013/07/16 22:23:31
Added --ssl-reqd. Is there something else you had
cmp
2013/07/16 22:34:18
Good enough for me for now. I assume that all of
| |
25 import json | |
cmp
2013/07/16 21:54:22
before line 25, insert a comment that says "Take a
szager1
2013/07/16 22:23:31
Done.
| |
26 import re | |
27 import sys | |
28 | |
29 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') | |
30 j = json.load(sys.stdin) | |
31 items = [(x, gerrit_re.match(x['name'])) for x in j['items']] | |
32 items = [(x, m.group(1)) for x, m in items if m] | |
33 def _cmp(a, b): | |
34 an = a[1].replace('-rc', '.rc').split('.') | |
35 bn = b[1].replace('-rc', '.rc').split('.') | |
36 while len(an) < len(bn): | |
37 an.append('0') | |
38 while len(bn) < len(an): | |
39 bn.append('0') | |
40 for i in range(len(an)): | |
41 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i]) | |
42 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i]) | |
43 if ai != bi: | |
44 return -1 if ai > bi else 1 | |
45 return 0 | |
46 items.sort(cmp=_cmp) | |
47 for x in items: | |
48 if 'rc' not in x[0]['name']: | |
49 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) | |
50 sys.exit(0) | |
51 EOF | |
52 ) | xargs | while read name md5; do | |
53 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | se d 's/ //g') | |
cmp
2013/07/16 21:54:22
wrap to be less than 80 chars
szager1
2013/07/16 22:23:31
Done.
| |
54 if [ -f "./$name" ]; then | |
55 file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) | |
56 if [ "$file_sum" = "$net_sum" ]; then | |
57 ln -sf "./$name" gerrit.war | |
58 break | |
59 else | |
60 rm -rf "./$name" | |
61 fi | |
62 fi | |
63 curl -s -o "./$name" "https://gerrit-releases.storage.googleapis.com/$name" | |
64 file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) | |
65 if [ "$file_sum" != "$net_sum" ]; then | |
66 echo "ERROR: md5sum mismatch when downloading $name" 1>&2 | |
67 rm -rf "./$name" | |
68 exit 1 | |
69 else | |
70 ln -sf "./$name" gerrit.war | |
71 fi | |
72 done | |
73 | |
74 if [ ! -e "./gerrit.war" ]; then | |
75 echo "ERROR: No gerrit.war file or link present, and unable " 1>&2 | |
76 echo " to download the latest version." 1>&2 | |
77 exit 1 | |
78 fi | |
79 | |
80 mkdir -p "${rundir}/etc" | |
81 cat <<EOF > "${rundir}/etc/gerrit.config" | |
82 [auth] | |
83 type = http | |
84 gitBasicAuth = true | |
85 EOF | |
86 java -jar "./gerrit.war" init --no-auto-start --batch -d "${rundir}" | |
87 | |
88 cat <<EOF | java -jar "./gerrit.war" gsql -d "${rundir}" > /dev/null | |
89 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}); | |
90 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'gerrit:${username}'); | |
91 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} , 'username:${username}'); | |
92 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($ {account_id}, '${preferred_email}', '${password}'); | |
93 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id}, 1); | |
94 EOF | |
95 | |
96 mkdir -p "${rundir}/tmp" | |
97 cat <<EOF > "${rundir}/tmp/.netrc" | |
98 machine localhost login ${username} password ${password} | |
99 EOF | |
100 | |
101 echo | |
102 echo "To start gerrit server:" | |
103 echo " ${rundir}/bin/gerrit.sh start" | |
104 echo | |
105 echo "To use the REST API:" | |
106 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" | |
107 echo | |
108 echo "To stop the server:" | |
109 echo " ${rundir}/bin/gerrit.sh stop" | |
110 echo | |
OLD | NEW |