| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 #!/bin/bash | 
|  | 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 | 
|  | 4 # found in the LICENSE file. | 
|  | 5 | 
|  | 6 if [ -n "$1" ]; then | 
|  | 7   rundir="$1" | 
|  | 8 else | 
|  | 9   rundir=$(mktemp -d) | 
|  | 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" \ | 
|  | 84       "https://gerrit-releases.storage.googleapis.com/$name" | 
|  | 85   file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) | 
|  | 86   if [ "$file_sum" != "$net_sum" ]; then | 
|  | 87     echo "ERROR: md5sum mismatch when downloading $name" 1>&2 | 
|  | 88     rm -rf "./$name" | 
|  | 89     exit 1 | 
|  | 90   else | 
|  | 91     ln -sf "./$name" gerrit.war | 
|  | 92   fi | 
|  | 93 done | 
|  | 94 | 
|  | 95 if [ ! -e "./gerrit.war" ]; then | 
|  | 96   echo "ERROR: No gerrit.war file or link present, and unable " 1>&2 | 
|  | 97   echo "       to download the latest version." 1>&2 | 
|  | 98   exit 1 | 
|  | 99 fi | 
|  | 100 | 
|  | 101 # By default, gerrit only accepts https connections, which is a good thing.  But | 
|  | 102 # for testing, it's convenient to enable plain http. | 
|  | 103 mkdir -p "${rundir}/etc" | 
|  | 104 cat <<EOF > "${rundir}/etc/gerrit.config" | 
|  | 105 [auth] | 
|  | 106         type = http | 
|  | 107         gitBasicAuth = true | 
|  | 108 EOF | 
|  | 109 | 
|  | 110 # Initialize the gerrit instance. | 
|  | 111 java -jar "./gerrit.war" init --no-auto-start --batch -d "${rundir}" | 
|  | 112 | 
|  | 113 # Set up the first user, with admin priveleges. | 
|  | 114 cat <<EOF | java -jar "./gerrit.war" gsql -d "${rundir}" > /dev/null | 
|  | 115 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}); | 
|  | 116 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
     , 'gerrit:${username}'); | 
|  | 117 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
     , 'username:${username}'); | 
|  | 118 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($
     {account_id}, '${preferred_email}', '${password}'); | 
|  | 119 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id}, 
     1); | 
|  | 120 EOF | 
|  | 121 | 
|  | 122 # Create a netrc file to authenticate as the first user. | 
|  | 123 mkdir -p "${rundir}/tmp" | 
|  | 124 cat <<EOF > "${rundir}/tmp/.netrc" | 
|  | 125 machine localhost login ${username} password ${password} | 
|  | 126 EOF | 
|  | 127 | 
|  | 128 echo | 
|  | 129 echo "To start gerrit server:" | 
|  | 130 echo "  ${rundir}/bin/gerrit.sh start" | 
|  | 131 echo | 
|  | 132 echo "To use the REST API:" | 
|  | 133 echo "  curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" | 
|  | 134 echo | 
|  | 135 echo "To stop the server:" | 
|  | 136 echo "  ${rundir}/bin/gerrit.sh stop" | 
|  | 137 echo | 
| OLD | NEW | 
|---|