| 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 set -e | 6 set -e |
| 7 | 7 |
| 8 http_port=8080 |
| 9 ssh_port=29418 |
| 10 |
| 8 while test $# -ne 0; do | 11 while test $# -ne 0; do |
| 9 case "$1" in | 12 case "$1" in |
| 10 -v) | 13 -v) |
| 11 version="$2" | 14 version="$2" |
| 12 shift | 15 shift |
| 13 ;; | 16 ;; |
| 14 -d) | 17 -d) |
| 15 rundir="$2" | 18 rundir="$2" |
| 16 shift | 19 shift |
| 17 ;; | 20 ;; |
| 21 --http-port) |
| 22 http_port="$2" |
| 23 shift |
| 24 ;; |
| 25 --ssh-port) |
| 26 ssh_port="$2" |
| 27 shift |
| 28 ;; |
| 18 *) | 29 *) |
| 19 rundir="$1" | 30 rundir="$1" |
| 20 ;; | 31 ;; |
| 21 esac | 32 esac |
| 22 shift | 33 shift |
| 23 done | 34 done |
| 24 | 35 |
| 25 if [ -z "$rundir" ]; then | 36 if [ -z "$rundir" ]; then |
| 26 rundir=$(mktemp -d) | 37 rundir=$(mktemp -d) |
| 27 fi | 38 fi |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 exit 1 | 141 exit 1 |
| 131 fi | 142 fi |
| 132 | 143 |
| 133 # By default, gerrit only accepts https connections, which is a good thing. But | 144 # By default, gerrit only accepts https connections, which is a good thing. But |
| 134 # for testing, it's convenient to enable plain http. | 145 # for testing, it's convenient to enable plain http. |
| 135 mkdir -p "${rundir}/etc" | 146 mkdir -p "${rundir}/etc" |
| 136 cat <<EOF > "${rundir}/etc/gerrit.config" | 147 cat <<EOF > "${rundir}/etc/gerrit.config" |
| 137 [auth] | 148 [auth] |
| 138 type = http | 149 type = http |
| 139 gitBasicAuth = true | 150 gitBasicAuth = true |
| 151 [gerrit] |
| 152 canonicalWebUrl = http://$(hostname):${http_port}/ |
| 153 [httpd] |
| 154 listenUrl = http://*:${http_port}/ |
| 155 [sshd] |
| 156 listenAddress = *:${ssh_port} |
| 140 EOF | 157 EOF |
| 141 | 158 |
| 142 # Initialize the gerrit instance. | 159 # Initialize the gerrit instance. |
| 143 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" | 160 java -jar "$gerrit_exe" init --no-auto-start --batch -d "${rundir}" |
| 144 | 161 |
| 145 # Create SSH key pair for the first user. | 162 # Create SSH key pair for the first user. |
| 146 mkdir -p "${rundir}/tmp" | 163 mkdir -p "${rundir}/tmp" |
| 147 ssh-keygen -t rsa -q -f "${rundir}/tmp/id_rsa" -N "" | 164 ssh-keygen -t rsa -q -f "${rundir}/tmp/id_rsa" -N "" |
| 148 ssh_public_key="$(cat ${rundir}/tmp/id_rsa.pub)" | 165 ssh_public_key="$(cat ${rundir}/tmp/id_rsa.pub)" |
| 149 | 166 |
| 150 # Set up the first user, with admin priveleges. | 167 # Set up the first user, with admin priveleges. |
| 151 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null | 168 cat <<EOF | java -jar "$gerrit_exe" gsql -d "${rundir}" > /dev/null |
| 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}); | 169 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}); |
| 153 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); | 170 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'gerrit:${username}'); |
| 154 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'username:${username}'); | 171 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EXTERNAL_ID) VALUES (${account_id}
, 'username:${username}'); |
| 155 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($
{account_id}, '${preferred_email}', '${password}'); | 172 INSERT INTO ACCOUNT_EXTERNAL_IDS (ACCOUNT_ID, EMAIL_ADDRESS, PASSWORD) VALUES ($
{account_id}, '${preferred_email}', '${password}'); |
| 156 INSERT INTO ACCOUNT_GROUP_MEMBERS (ACCOUNT_ID, GROUP_ID) VALUES (${account_id},
1); | 173 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); | 174 INSERT INTO ACCOUNT_SSH_KEYS (ACCOUNT_ID, SSH_PUBLIC_KEY, VALID, SEQ) VALUES (${
account_id}, '${ssh_public_key}', 'Y', 0); |
| 158 EOF | 175 EOF |
| 159 | 176 |
| 160 # Create a netrc file to authenticate as the first user. | 177 # Create a netrc file to authenticate as the first user. |
| 161 cat <<EOF > "${rundir}/tmp/.netrc" | 178 cat <<EOF > "${rundir}/tmp/.netrc" |
| 162 machine localhost login ${username} password ${password} | 179 machine localhost login ${username} password ${password} |
| 163 EOF | 180 EOF |
| 164 | 181 |
| 165 # Create a .git-credentials file, to enable password-less push. | 182 # Create a .git-credentials file, to enable password-less push. |
| 166 cat <<EOF > "${rundir}/tmp/.git-credentials" | 183 cat <<EOF > "${rundir}/tmp/.git-credentials" |
| 167 http://${username}:${password}@localhost:8080 | 184 http://${username}:${password}@localhost:${http_port} |
| 168 EOF | 185 EOF |
| 169 | 186 |
| 170 echo | 187 cat <<EOF |
| 171 echo "To start gerrit server:" | 188 |
| 172 echo " ${rundir}/bin/gerrit.sh start" | 189 To start gerrit server: |
| 173 echo | 190 ${rundir}/bin/gerrit.sh start |
| 174 echo "To use the REST API:" | 191 |
| 175 echo " curl --netrc-file ${rundir}/tmp/.netrc http://localhost:8080/<endpoint>" | 192 To use the REST API: |
| 176 echo | 193 curl --netrc-file ${rundir}/tmp/.netrc http://localhost:${http_port}/<endpoint
> |
| 177 echo "To use SSH API:" | 194 |
| 178 echo " ssh ${username}@localhost -p 29418 -i ${rundir}/tmp/id_rsa gerrit" | 195 To use SSH API: |
| 179 echo | 196 ssh ${username}@localhost -p ${ssh_port} -i ${rundir}/tmp/id_rsa gerrit |
| 180 echo "To enable 'git push' without a password prompt:" | 197 |
| 181 echo " git config credential.helper 'store --file=${rundir}/tmp/.git-credential
s'" | 198 To enable 'git push' without a password prompt: |
| 182 echo | 199 git config credential.helper 'store --file=${rundir}/tmp/.git-credentials' |
| 183 echo "To stop the server:" | 200 |
| 184 echo " ${rundir}/bin/gerrit.sh stop" | 201 To stop the server: |
| 185 echo | 202 ${rundir}/bin/gerrit.sh stop |
| 203 |
| 204 EOF |
| OLD | NEW |