| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 if [ -n "$1" ]; then | 6 set -e |
| 7 rundir="$1" | 7 |
| 8 else | 8 while test $# -ne 0; do |
| 9 case "$1" in |
| 10 -v) |
| 11 version="$2" |
| 12 shift |
| 13 ;; |
| 14 -d) |
| 15 rundir="$2" |
| 16 shift |
| 17 ;; |
| 18 *) |
| 19 rundir="$1" |
| 20 ;; |
| 21 esac |
| 22 shift |
| 23 done |
| 24 |
| 25 if [ -z "$rundir" ]; then |
| 9 rundir=$(mktemp -d) | 26 rundir=$(mktemp -d) |
| 10 fi | 27 fi |
| 11 | 28 |
| 12 this_dir=$(dirname $0) | 29 this_dir=$(dirname $0) |
| 13 gerrit_exe="$this_dir/gerrit.war" | 30 gerrit_exe="$this_dir/gerrit.war" |
| 14 | 31 |
| 15 account_id=101 | 32 account_id=101 |
| 16 full_name='Test Account' | 33 full_name='Test Account' |
| 17 maximum_page_size='25' | 34 maximum_page_size='25' |
| 18 password='test-password' | 35 password='test-password' |
| 19 preferred_email="test-username@test.org" | 36 preferred_email="test-username@test.org" |
| 20 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z') | 37 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z') |
| 21 username='test-username' | 38 username='test-username' |
| 22 | 39 |
| 23 # The python code below for picking the "latest" gerrit release is cribbed and | 40 # The python code below for picking the "latest" gerrit release is cribbed and |
| 24 # ported from the javascript at: | 41 # ported from the javascript at: |
| 25 # | 42 # |
| 26 # http://gerrit-releases.storage.googleapis.com/index.html | 43 # http://gerrit-releases.storage.googleapis.com/index.html |
| 27 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n
oAcl' | 44 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n
oAcl' |
| 28 curl --ssl-reqd -s $url | python <(cat <<EOF | 45 curl --ssl-reqd -s $url | python <(cat <<EOF |
| 29 # Reads json-encoded text from stdin in the format: | 46 # Receives Gerrit version via command line and reads json-encoded |
| 47 # text from stdin in the format: |
| 30 # | 48 # |
| 31 # { | 49 # { |
| 32 # "items": [ | 50 # "items": [ |
| 33 # { | 51 # { |
| 34 # "name": "gerrit-<version>.war", | 52 # "name": "gerrit-<version>.war", |
| 35 # "md5Hash": "<base64 encoded md5sum>", | 53 # "md5Hash": "<base64 encoded md5sum>", |
| 36 # }, | 54 # }, |
| 37 # { | 55 # { |
| 38 # "name": "gerrit-<version>.war", | 56 # "name": "gerrit-<version>.war", |
| 39 # "md5Hash": "<base64 encoded md5sum>", | 57 # "md5Hash": "<base64 encoded md5sum>", |
| 40 # }, | 58 # }, |
| 41 # ... | 59 # ... |
| 42 # } | 60 # } |
| 43 # | 61 # |
| 44 # ...and prints the name and md5sum of the latest non-release-candidate version. | 62 # ...and prints the name and md5sum of the corresponding *.war file. |
| 45 | 63 |
| 46 import json | 64 import json |
| 47 import re | 65 import re |
| 48 import sys | 66 import sys |
| 49 | 67 |
| 68 requested_version = sys.argv[1] if len(sys.argv) > 1 else None |
| 50 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') | 69 gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') |
| 51 j = json.load(sys.stdin) | 70 j = json.load(sys.stdin) |
| 52 items = [(x, gerrit_re.match(x['name'])) for x in j['items']] | 71 items = [(x, gerrit_re.match(x['name'])) for x in j['items']] |
| 53 items = [(x, m.group(1)) for x, m in items if m] | 72 items = [(x, m.group(1)) for x, m in items if m] |
| 54 def _cmp(a, b): | 73 def _cmp(a, b): |
| 55 an = a[1].replace('-rc', '.rc').split('.') | 74 an = a[1].replace('-rc', '.rc').split('.') |
| 56 bn = b[1].replace('-rc', '.rc').split('.') | 75 bn = b[1].replace('-rc', '.rc').split('.') |
| 57 while len(an) < len(bn): | 76 while len(an) < len(bn): |
| 58 an.append('0') | 77 an.append('0') |
| 59 while len(bn) < len(an): | 78 while len(bn) < len(an): |
| 60 bn.append('0') | 79 bn.append('0') |
| 61 for i in range(len(an)): | 80 for i in range(len(an)): |
| 62 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i]) | 81 ai = int(an[i][2:]) if 'rc' in an[i] else 1000 + int(an[i]) |
| 63 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i]) | 82 bi = int(bn[i][2:]) if 'rc' in bn[i] else 1000 + int(bn[i]) |
| 64 if ai != bi: | 83 if ai != bi: |
| 65 return -1 if ai > bi else 1 | 84 return -1 if ai > bi else 1 |
| 66 return 0 | 85 return 0 |
| 86 |
| 87 if requested_version: |
| 88 for info, version in items: |
| 89 if version == requested_version: |
| 90 print '"%s" "%s"' % (info['name'], info['md5Hash']) |
| 91 sys.exit(0) |
| 92 print >> sys.stderr, 'No such Gerrit version: %s' % requested_version |
| 93 sys.exit(1) |
| 94 |
| 67 items.sort(cmp=_cmp) | 95 items.sort(cmp=_cmp) |
| 68 for x in items: | 96 for x in items: |
| 69 if 'rc' not in x[0]['name']: | 97 if 'rc' not in x[0]['name']: |
| 70 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) | 98 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) |
| 71 sys.exit(0) | 99 sys.exit(0) |
| 72 EOF | 100 EOF |
| 73 ) | xargs | while read name md5; do | 101 ) "$version" | xargs | while read name md5; do |
| 74 # Download the latest gerrit version if necessary, and verify the md5sum. | 102 # Download the requested gerrit version if necessary, and verify the md5sum. |
| 75 target="$this_dir/$name" | 103 target="$this_dir/$name" |
| 76 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | | 104 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | |
| 77 sed 's/ //g') | 105 sed 's/ //g') |
| 78 if [ -f "$target" ]; then | 106 if [ -f "$target" ]; then |
| 79 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) | 107 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) |
| 80 if [ "$file_sum" = "$net_sum" ]; then | 108 if [ "$file_sum" = "$net_sum" ]; then |
| 81 ln -sf "$name" "$gerrit_exe" | 109 ln -sf "$name" "$gerrit_exe" |
| 82 break | 110 break |
| 83 else | 111 else |
| 84 rm -rf "$target" | 112 rm -rf "$target" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 107 mkdir -p "${rundir}/etc" | 135 mkdir -p "${rundir}/etc" |
| 108 cat <<EOF > "${rundir}/etc/gerrit.config" | 136 cat <<EOF > "${rundir}/etc/gerrit.config" |
| 109 [auth] | 137 [auth] |
| 110 type = http | 138 type = http |
| 111 gitBasicAuth = true | 139 gitBasicAuth = true |
| 112 EOF | 140 EOF |
| 113 | 141 |
| 114 # Initialize the gerrit instance. | 142 # Initialize the gerrit instance. |
| 115 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" | 143 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" |
| 116 | 144 |
| 145 # Create SSH key pair for the first user. |
| 146 mkdir -p "${rundir}/tmp" |
| 147 ssh-keygen -t rsa -q -f "${rundir}/tmp/id_rsa" -N "" |
| 148 ssh_public_key="$(cat ${rundir}/tmp/id_rsa.pub)" |
| 149 |
| 117 # Set up the first user, with admin priveleges. | 150 # Set up the first user, with admin priveleges. |
| 118 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null | 151 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null |
| 119 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}); | 152 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}); |
| 120 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); | 153 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); |
| 121 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'username:${username}'); | 154 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'username:${username}'); |
| 122 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($
{account_id}, '${preferred_email}', '${password}'); | 155 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($
{account_id}, '${preferred_email}', '${password}'); |
| 123 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id},
1); | 156 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id},
1); |
| 157 INSERT INTO ACCOUNT_SSH_KEYS (ACCOUNT_ID, SSH_PUBLIC_KEY, VALID, SEQ) VALUES (${
account_id}, '${ssh_public_key}', 'Y', 0); |
| 124 EOF | 158 EOF |
| 125 | 159 |
| 126 # Create a netrc file to authenticate as the first user. | 160 # Create a netrc file to authenticate as the first user. |
| 127 mkdir -p "${rundir}/tmp" | |
| 128 cat <<EOF > "${rundir}/tmp/.netrc" | 161 cat <<EOF > "${rundir}/tmp/.netrc" |
| 129 machine localhost login ${username} password ${password} | 162 machine localhost login ${username} password ${password} |
| 130 EOF | 163 EOF |
| 131 | 164 |
| 132 # Create a .git-credentials file, to enable password-less push. | 165 # Create a .git-credentials file, to enable password-less push. |
| 133 cat <<EOF > "${rundir}/tmp/.git-credentials" | 166 cat <<EOF > "${rundir}/tmp/.git-credentials" |
| 134 http://${username}:${password}@localhost:8080 | 167 http://${username}:${password}@localhost:8080 |
| 135 EOF | 168 EOF |
| 136 | 169 |
| 137 echo | 170 echo |
| 138 echo "To start gerrit server:" | 171 echo "To start gerrit server:" |
| 139 echo " ${rundir}/bin/gerrit.sh start" | 172 echo " ${rundir}/bin/gerrit.sh start" |
| 140 echo | 173 echo |
| 141 echo "To use the REST API:" | 174 echo "To use the REST API:" |
| 142 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" | 175 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" |
| 143 echo | 176 echo |
| 177 echo "To use SSH API:" |
| 178 echo " ssh ${username}@localhost -p 29418 -i ${rundir}/tmp/id_rsa gerrit" |
| 179 echo |
| 144 echo "To enable 'git push' without a password prompt:" | 180 echo "To enable 'git push' without a password prompt:" |
| 145 echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credential
s'" | 181 echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credential
s'" |
| 146 echo | 182 echo |
| 147 echo "To stop the server:" | 183 echo "To stop the server:" |
| 148 echo " ${rundir}/bin/gerrit.sh stop" | 184 echo " ${rundir}/bin/gerrit.sh stop" |
| 149 echo | 185 echo |
| OLD | NEW |