Chromium Code Reviews| Index: testing_support/gerrit-init.sh |
| diff --git a/testing_support/gerrit-init.sh b/testing_support/gerrit-init.sh |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..2a28c32da10b36e065512a24230af124a0aa0588 |
| --- /dev/null |
| +++ b/testing_support/gerrit-init.sh |
| @@ -0,0 +1,110 @@ |
| +#!/bin/bash |
| + |
|
cmp
2013/07/16 21:54:22
remove this empty line
szager1
2013/07/16 22:23:31
Done.
|
| +# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +if [ -n "$1" ]; then |
| + rundir="$1" |
| +else |
| + rundir="$(mktemp -d)" |
| +fi |
| + |
| +account_id=101 |
| +full_name='Test Account' |
| +maximum_page_size='25' |
| +password='test-password' |
| +username='test-username' |
| +preferred_email="${username}@test.org" |
| +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.
|
| + |
| +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.
|
| + |
| +url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=noAcl' |
|
cmp
2013/07/16 21:54:22
before line 23, insert a comment that says somethi
szager1
2013/07/16 22:23:31
Done.
|
| +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
|
| +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.
|
| +import re |
| +import sys |
| + |
| +gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') |
| +j = json.load(sys.stdin) |
| +items = [(x, gerrit_re.match(x['name'])) for x in j['items']] |
| +items = [(x, m.group(1)) for x, m in items if m] |
| +def _cmp(a, b): |
| + an = a[1].replace('-rc', '.rc').split('.') |
| + bn = b[1].replace('-rc', '.rc').split('.') |
| + while len(an) < len(bn): |
| + an.append('0') |
| + while len(bn) < len(an): |
| + bn.append('0') |
| + for i in range(len(an)): |
| + ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i]) |
| + bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i]) |
| + if ai != bi: |
| + return -1 if ai > bi else 1 |
| + return 0 |
| +items.sort(cmp=_cmp) |
| +for x in items: |
| + if 'rc' not in x[0]['name']: |
| + print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) |
| + sys.exit(0) |
| +EOF |
| +) | xargs | while read name md5; do |
| + net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | sed 's/ //g') |
|
cmp
2013/07/16 21:54:22
wrap to be less than 80 chars
szager1
2013/07/16 22:23:31
Done.
|
| + if [ -f "./$name" ]; then |
| + file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) |
| + if [ "$file_sum" = "$net_sum" ]; then |
| + ln -sf "./$name" gerrit.war |
| + break |
| + else |
| + rm -rf "./$name" |
| + fi |
| + fi |
| + curl -s -o "./$name" "https://gerrit-releases.storage.googleapis.com/$name" |
| + file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) |
| + if [ "$file_sum" != "$net_sum" ]; then |
| + echo "ERROR: md5sum mismatch when downloading $name" 1>&2 |
| + rm -rf "./$name" |
| + exit 1 |
| + else |
| + ln -sf "./$name" gerrit.war |
| + fi |
| +done |
| + |
| +if [ ! -e "./gerrit.war" ]; then |
| + echo "ERROR: No gerrit.war file or link present, and unable " 1>&2 |
| + echo " to download the latest version." 1>&2 |
| + exit 1 |
| +fi |
| + |
| +mkdir -p "${rundir}/etc" |
| +cat <<EOF > "${rundir}/etc/gerrit.config" |
| +[auth] |
| + type = http |
| + gitBasicAuth = true |
| +EOF |
| +java -jar "./gerrit.war" init --no-auto-start --batch -d "${rundir}" |
| + |
| +cat <<EOF | java -jar "./gerrit.war" gsql -d "${rundir}" > /dev/null |
| +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}); |
| +INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}, 'gerrit:${username}'); |
| +INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}, 'username:${username}'); |
| +INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES (${account_id}, '${preferred_email}', '${password}'); |
| +INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id}, 1); |
| +EOF |
| + |
| +mkdir -p "${rundir}/tmp" |
| +cat <<EOF > "${rundir}/tmp/.netrc" |
| +machine localhost login ${username} password ${password} |
| +EOF |
| + |
| +echo |
| +echo "To start gerrit server:" |
| +echo " ${rundir}/bin/gerrit.sh start" |
| +echo |
| +echo "To use the REST API:" |
| +echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" |
| +echo |
| +echo "To stop the server:" |
| +echo " ${rundir}/bin/gerrit.sh stop" |
| +echo |