Commit f6916488 authored by vadimsh@chromium.org's avatar vadimsh@chromium.org

Ability to install custom Gerrit version.

Also generate SSH keypair for default account to enable SSH access.

R=szager@chromium.org

Review URL: https://codereview.chromium.org/20441002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@216009 0039d316-1c4b-4281-b951-d872f2087c98
parent a5c5b1b3
...@@ -3,9 +3,26 @@ ...@@ -3,9 +3,26 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
if [ -n "$1" ]; then set -e
rundir="$1"
else while test $# -ne 0; do
case "$1" in
-v)
version="$2"
shift
;;
-d)
rundir="$2"
shift
;;
*)
rundir="$1"
;;
esac
shift
done
if [ -z "$rundir" ]; then
rundir=$(mktemp -d) rundir=$(mktemp -d)
fi fi
...@@ -26,7 +43,8 @@ username='test-username' ...@@ -26,7 +43,8 @@ username='test-username'
# http://gerrit-releases.storage.googleapis.com/index.html # http://gerrit-releases.storage.googleapis.com/index.html
url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=noAcl' url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=noAcl'
curl --ssl-reqd -s $url | python <(cat <<EOF 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": [ # "items": [
...@@ -41,12 +59,13 @@ curl --ssl-reqd -s $url | python <(cat <<EOF ...@@ -41,12 +59,13 @@ 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 json
import re import re
import sys import sys
requested_version = sys.argv[1] if len(sys.argv) > 1 else None
gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war') gerrit_re = re.compile('gerrit(?:-full)?-([0-9.]+(?:-rc[0-9]+)?)[.]war')
j = json.load(sys.stdin) j = json.load(sys.stdin)
items = [(x, gerrit_re.match(x['name'])) for x in j['items']] items = [(x, gerrit_re.match(x['name'])) for x in j['items']]
...@@ -64,14 +83,23 @@ def _cmp(a, b): ...@@ -64,14 +83,23 @@ def _cmp(a, b):
if ai != bi: if ai != bi:
return -1 if ai > bi else 1 return -1 if ai > bi else 1
return 0 return 0
if requested_version:
for info, version in items:
if version == requested_version:
print '"%s" "%s"' % (info['name'], info['md5Hash'])
sys.exit(0)
print >> sys.stderr, 'No such Gerrit version: %s' % requested_version
sys.exit(1)
items.sort(cmp=_cmp) items.sort(cmp=_cmp)
for x in items: for x in items:
if 'rc' not in x[0]['name']: if 'rc' not in x[0]['name']:
print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash'])
sys.exit(0) sys.exit(0)
EOF EOF
) | xargs | while read name md5; do ) "$version" | xargs | while read name md5; do
# Download the latest gerrit version if necessary, and verify the md5sum. # Download the requested gerrit version if necessary, and verify the md5sum.
target="$this_dir/$name" target="$this_dir/$name"
net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- |
sed 's/ //g') sed 's/ //g')
...@@ -114,6 +142,11 @@ EOF ...@@ -114,6 +142,11 @@ EOF
# Initialize the gerrit instance. # Initialize the gerrit instance.
java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}"
# Create SSH key pair for the first user.
mkdir -p "${rundir}/tmp"
ssh-keygen -t rsa -q -f "${rundir}/tmp/id_rsa" -N ""
ssh_public_key="$(cat ${rundir}/tmp/id_rsa.pub)"
# Set up the first user, with admin priveleges. # Set up the first user, with admin priveleges.
cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null 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}); 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,10 +154,10 @@ INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id} ...@@ -121,10 +154,10 @@ 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, 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_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_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 EOF
# Create a netrc file to authenticate as the first user. # Create a netrc file to authenticate as the first user.
mkdir -p "${rundir}/tmp"
cat <<EOF > "${rundir}/tmp/.netrc" cat <<EOF > "${rundir}/tmp/.netrc"
machine localhost login ${username} password ${password} machine localhost login ${username} password ${password}
EOF EOF
...@@ -141,6 +174,9 @@ echo ...@@ -141,6 +174,9 @@ echo
echo "To use the REST API:" echo "To use the REST API:"
echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>"
echo echo
echo "To use SSH API:"
echo " ssh ${username}@localhost -p 29418 -i ${rundir}/tmp/id_rsa gerrit"
echo
echo "To enable 'git push' without a password prompt:" echo "To enable 'git push' without a password prompt:"
echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credentials'" echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credentials'"
echo echo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment