Chromium Code Reviews| Index: testing_support/gerrit-init.sh |
| diff --git a/testing_support/gerrit-init.sh b/testing_support/gerrit-init.sh |
| index e19cf9bb6fd4b0a503388289ebf1e5ca93e345da..ad4172d276462d174a62bbc0cfbb7677e43ed1dc 100755 |
| --- a/testing_support/gerrit-init.sh |
| +++ b/testing_support/gerrit-init.sh |
| @@ -3,12 +3,20 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +set -e |
| + |
| if [ -n "$1" ]; then |
| rundir="$1" |
| else |
| rundir=$(mktemp -d) |
| fi |
| +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.
|
| + version="$2" |
| +else |
| + version="latest" |
| +fi |
| + |
| this_dir=$(dirname $0) |
| gerrit_exe="$this_dir/gerrit.war" |
| @@ -26,7 +34,8 @@ username='test-username' |
| # http://gerrit-releases.storage.googleapis.com/index.html |
| url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=noAcl' |
| curl --ssl-reqd -s $url | python <(cat <<EOF |
| -# Reads json-encoded text from stdin in the format: |
| +# Receives Gerrit version via command line and reads json-encoded |
| +# text from stdin in the format: |
| # |
| # { |
| # "items": [ |
| @@ -41,16 +50,20 @@ curl --ssl-reqd -s $url | python <(cat <<EOF |
| # ... |
| # } |
| # |
| -# ...and prints the name and md5sum of the latest non-release-candidate version. |
| +# ...and prints the name and md5sum of the corresponding *.war file. |
| import json |
| import re |
| import sys |
| +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.
|
| + |
|
szager1
2013/07/25 19:53:50
Remove blank line.
Vadim Sh.
2013/07/25 21:42:32
Done.
|
| gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') |
| j = json.load(sys.stdin) |
| + |
|
szager1
2013/07/25 19:53:50
Remove blank line.
Vadim Sh.
2013/07/25 21:42:32
Done.
|
| items = [(x, gerrit_re.match(x['name'])) for x in j['items']] |
| items = [(x, m.group(1)) for x, m in items if m] |
| + |
|
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
|
| def _cmp(a, b): |
| an = a[1].replace('-rc', '.rc').split('.') |
| bn = b[1].replace('-rc', '.rc').split('.') |
| @@ -64,14 +77,29 @@ def _cmp(a, b): |
| 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) |
| + |
| +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.
|
| +if requested_version == 'latest': |
| + for info, version in sorted(items, cmp=_cmp): |
| + if 'rc' not in info['name']: |
| + found = info |
| + break |
| +else: |
| + for info, version in items: |
| + if version == requested_version: |
| + found = info |
| + break |
| + |
| +if not found: |
| + 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.
|
| + sys.exit(1) |
| +else: |
| + print '"%s" "%s"' % (found['name'], found['md5Hash']) |
| + sys.exit(0) |
| EOF |
| -) | xargs | while read name md5; do |
| - # Download the latest gerrit version if necessary, and verify the md5sum. |
| +) "$version" | xargs | while read name md5; do |
| + # Download the requested gerrit version if necessary, and verify the md5sum. |
| + echo "Installing $name..." |
| target="$this_dir/$name" |
| net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | |
| sed 's/ //g') |
| @@ -114,6 +142,13 @@ EOF |
| # Initialize the gerrit instance. |
| java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" |
| +# Create SSH key pair for the first user. |
| +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
|
| + mkdir -p "${rundir}/key" |
| + ssh-keygen -t rsa -q -f "${rundir}/key/id_rsa" -N "" |
| +fi |
| +ssh_public_key="$(cat ${rundir}/key/id_rsa.pub)" |
| + |
| # Set up the first user, with admin priveleges. |
| cat <<EOF | java -jar "$gerrit_exe" 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}); |
| @@ -121,6 +156,7 @@ INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} |
| 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); |
| +INSERT INTO ACCOUNT_SSH_KEYS (ACCOUNT_ID, SSH_PUBLIC_KEY, VALID, SEQ) VALUES (${account_id}, '${ssh_public_key}', 'Y', 0); |
| EOF |
| # Create a netrc file to authenticate as the first user. |
| @@ -141,6 +177,9 @@ echo |
| echo "To use the REST API:" |
| echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" |
| echo |
| +echo "To use SSH API:" |
| +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.
|
| +echo |
| echo "To enable 'git push' without a password prompt:" |
| echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credentials'" |
| echo |