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 if [ -n "$1" ]; then |
7 rundir="$1" | 7 rundir="$1" |
8 else | 8 else |
9 rundir=$(mktemp -d) | 9 rundir=$(mktemp -d) |
10 fi | 10 fi |
11 | 11 |
| 12 this_dir=$(dirname $0) |
| 13 gerrit_exe="$this_dir/gerrit.war" |
| 14 |
12 account_id=101 | 15 account_id=101 |
13 full_name='Test Account' | 16 full_name='Test Account' |
14 maximum_page_size='25' | 17 maximum_page_size='25' |
15 password='test-password' | 18 password='test-password' |
16 preferred_email="${username}@test.org" | 19 preferred_email="test-username@test.org" |
17 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z') | 20 registered_on=$(date '+%Y-%m-%d %H:%M:%S.000%:::z') |
18 username='test-username' | 21 username='test-username' |
19 | 22 |
20 # The python code below for picking the "latest" gerrit release is cribbed and | 23 # The python code below for picking the "latest" gerrit release is cribbed and |
21 # ported from the javascript at: | 24 # ported from the javascript at: |
22 # | 25 # |
23 # http://gerrit-releases.storage.googleapis.com/index.html | 26 # http://gerrit-releases.storage.googleapis.com/index.html |
24 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n
oAcl' | 27 url='https://www.googleapis.com/storage/v1beta2/b/gerrit-releases/o?projection=n
oAcl' |
25 curl --ssl-reqd -s $url | python <(cat <<EOF | 28 curl --ssl-reqd -s $url | python <(cat <<EOF |
26 # Reads json-encoded text from stdin in the format: | 29 # Reads json-encoded text from stdin in the format: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return -1 if ai > bi else 1 | 65 return -1 if ai > bi else 1 |
63 return 0 | 66 return 0 |
64 items.sort(cmp=_cmp) | 67 items.sort(cmp=_cmp) |
65 for x in items: | 68 for x in items: |
66 if 'rc' not in x[0]['name']: | 69 if 'rc' not in x[0]['name']: |
67 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) | 70 print '"%s" "%s"' % (x[0]['name'], x[0]['md5Hash']) |
68 sys.exit(0) | 71 sys.exit(0) |
69 EOF | 72 EOF |
70 ) | xargs | while read name md5; do | 73 ) | xargs | while read name md5; do |
71 # Download the latest gerrit version if necessary, and verify the md5sum. | 74 # Download the latest gerrit version if necessary, and verify the md5sum. |
| 75 target="$this_dir/$name" |
72 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | | 76 net_sum=$(echo -n $md5 | base64 -d | od -tx1 | head -1 | cut -d ' ' -f 2- | |
73 sed 's/ //g') | 77 sed 's/ //g') |
74 if [ -f "./$name" ]; then | 78 if [ -f "$target" ]; then |
75 file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) | 79 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) |
76 if [ "$file_sum" = "$net_sum" ]; then | 80 if [ "$file_sum" = "$net_sum" ]; then |
77 ln -sf "./$name" gerrit.war | 81 ln -sf "$name" "$gerrit_exe" |
78 break | 82 break |
79 else | 83 else |
80 rm -rf "./$name" | 84 rm -rf "$target" |
81 fi | 85 fi |
82 fi | 86 fi |
83 curl --ssl-reqd -s -o "./$name" \ | 87 curl --ssl-reqd -s -o "$target" \ |
84 "https://gerrit-releases.storage.googleapis.com/$name" | 88 "https://gerrit-releases.storage.googleapis.com/$name" |
85 file_sum=$(md5sum "./$name" | awk '{print $1}' | xargs) | 89 file_sum=$(md5sum "$target" | awk '{print $1}' | xargs) |
86 if [ "$file_sum" != "$net_sum" ]; then | 90 if [ "$file_sum" != "$net_sum" ]; then |
87 echo "ERROR: md5sum mismatch when downloading $name" 1>&2 | 91 echo "ERROR: md5sum mismatch when downloading $name" 1>&2 |
88 rm -rf "./$name" | 92 rm -rf "$target" |
89 exit 1 | 93 exit 1 |
90 else | 94 else |
91 ln -sf "./$name" gerrit.war | 95 ln -sf "$name" "$gerrit_exe" |
92 fi | 96 fi |
93 done | 97 done |
94 | 98 |
95 if [ ! -e "./gerrit.war" ]; then | 99 if [ ! -e "$gerrit_exe" ]; then |
96 echo "ERROR: No gerrit.war file or link present, and unable " 1>&2 | 100 echo "ERROR: No $gerrit_exe file or link present, and unable " 1>&2 |
97 echo " to download the latest version." 1>&2 | 101 echo " to download the latest version." 1>&2 |
98 exit 1 | 102 exit 1 |
99 fi | 103 fi |
100 | 104 |
101 # By default, gerrit only accepts https connections, which is a good thing. But | 105 # By default, gerrit only accepts https connections, which is a good thing. But |
102 # for testing, it's convenient to enable plain http. | 106 # for testing, it's convenient to enable plain http. |
103 mkdir -p "${rundir}/etc" | 107 mkdir -p "${rundir}/etc" |
104 cat <<EOF > "${rundir}/etc/gerrit.config" | 108 cat <<EOF > "${rundir}/etc/gerrit.config" |
105 [auth] | 109 [auth] |
106 type = http | 110 type = http |
107 gitBasicAuth = true | 111 gitBasicAuth = true |
108 EOF | 112 EOF |
109 | 113 |
110 # Initialize the gerrit instance. | 114 # Initialize the gerrit instance. |
111 java -jar "./gerrit.war" init --no-auto-start --batch -d "${rundir}" | 115 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" |
112 | 116 |
113 # Set up the first user, with admin priveleges. | 117 # Set up the first user, with admin priveleges. |
114 cat <<EOF | java -jar "./gerrit.war" gsql -d "${rundir}" > /dev/null | 118 cat <<EOF | java -jar "$gerrit_exe" 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}); | 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}); |
116 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); | 120 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}'); | 121 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}'); | 122 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); | 123 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id},
1); |
120 EOF | 124 EOF |
121 | 125 |
122 # Create a netrc file to authenticate as the first user. | 126 # Create a netrc file to authenticate as the first user. |
123 mkdir -p "${rundir}/tmp" | 127 mkdir -p "${rundir}/tmp" |
124 cat <<EOF > "${rundir}/tmp/.netrc" | 128 cat <<EOF > "${rundir}/tmp/.netrc" |
125 machine localhost login ${username} password ${password} | 129 machine localhost login ${username} password ${password} |
126 EOF | 130 EOF |
127 | 131 |
128 echo | 132 echo |
129 echo "To start gerrit server:" | 133 echo "To start gerrit server:" |
130 echo " ${rundir}/bin/gerrit.sh start" | 134 echo " ${rundir}/bin/gerrit.sh start" |
131 echo | 135 echo |
132 echo "To use the REST API:" | 136 echo "To use the REST API:" |
133 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" | 137 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" |
134 echo | 138 echo |
135 echo "To stop the server:" | 139 echo "To stop the server:" |
136 echo " ${rundir}/bin/gerrit.sh stop" | 140 echo " ${rundir}/bin/gerrit.sh stop" |
137 echo | 141 echo |
OLD | NEW |