~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
#! /bin/bash

# This script will setup a brand new Ubuntu machine as a LP developer
# workstation, from scratch. The script lives in the LP codebase itself,
# as utilities/rocketfuel-setup

if [ ! -e "$HOME/.rocketfuel-env.sh" ]; then
  echo "# Common environment variables for the rocketfuel-* scripts.
#
# The ones you can set are:
#
# LP_PROJECT_ROOT - The root directory of all your Canonical stuff.  Your
#                   Launchpad shared repository will live in a child directory
#                   of this directory.
# LP_SHARED_REPO  - Your Launchpad shared repository directory.  All of your
#                   Launchpad development branches will live under here.
# LP_TRUNK_NAME   - The directory name (not path!) to your rocketfuel trunk
#                   mirror directory.  This is relative to your shared repo.
# LP_SOURCEDEPS_DIR - The name of the directory (not path!) where your
#                   trunk sourcecode will be placed.  This is relative to your
#                   LP_PROJECT_ROOT and should /not/ have the 'sourcecode'
#                   path appended to it, since this is automatically added by
#                   the scripts.

LP_PROJECT_ROOT=\${LP_PROJECT_ROOT:=~/canonical}
LP_SHARED_REPO=\${LP_SHARED_REPO:=lp-branches}
LP_PROJECT_PATH=\$LP_PROJECT_ROOT/\$LP_SHARED_REPO
LP_TRUNK_NAME=\${LP_TRUNK_NAME:=trunk}
LP_TRUNK_PATH=\$LP_PROJECT_PATH/\$LP_TRUNK_NAME

LP_SOURCEDEPS_DIR=\${LP_SOURCEDEPS_DIR:=lp-sourcedeps}
LP_SOURCEDEPS_PATH=\$LP_PROJECT_ROOT/\$LP_SOURCEDEPS_DIR/sourcecode

# Force tilde expansion
LP_SOURCEDEPS_PATH=\$(eval echo \${LP_SOURCEDEPS_PATH})
" > "$HOME/.rocketfuel-env.sh"
fi

source "$HOME/.rocketfuel-env.sh"
if [ "$?" != 0 ]; then
    echo "Something went wrong with rocketfuel-setup!"
    exit 1
fi

# load up Ubuntu release details so we know which repos to enable
source /etc/lsb-release

# Establish Canonical username
whoami=`whoami`
printf "What is your username on Canonical servers? [$whoami] "
read canusrname
if [ ! -z ${canusrname} ]; then
  whoami=${canusrname};
fi

# Test that we can access Canonical servers
ssh ${whoami}@chinstrap.canonical.com pwd > /dev/null
if [ $? -ne 0 ]; then
  echo "
ERROR: Unable to login to chinstrap, please check your Canonical account
details.
"
  exit 1
fi

# Make sure you have all the needed virtual hosts

dev_host() {
  grep -q "^127.0.0.88.* ${hostname}" /etc/hosts
  if [ $? -ne 0 ]; then
    sudo sed -i "s/^127.0.0.88.*$/&\ ${hostname}/" /etc/hosts
    echo "${hostname} added to /etc/hosts"
  fi
  }

grep -q "^127.0.0.88" /etc/hosts
if [ $? -ne 0 ]; then
  echo "Adding development hosts on local machine"
  echo "
# Launchpad virtual domains. This should be on one line.
127.0.0.88      launchpad.dev
" | sudo tee -a /etc/hosts > /dev/null
  echo "launchpad.dev added to /etc/hosts"
fi

declare -a hostnames
hostnames=$(cat <<EOF
    answers.launchpad.dev
    api.launchpad.dev
    bazaar.launchpad.dev
    beta.launchpad.dev
    blueprints.launchpad.dev
    bugs.launchpad.dev
    code.launchpad.dev
    feeds.launchpad.dev
    id.launchpad.dev
    openid.launchpad.dev
    shipit.edubuntu.dev
    shipit.kubuntu.dev
    shipit.ubuntu.dev
    translations.launchpad.dev
    xmlrpc-private.launchpad.dev
    xmlrpc.launchpad.dev
EOF
    )

for hostname in $hostnames; do
  dev_host;
done

# Enable relevant Ubuntu package repositories
grep -q "^deb http:.* ${DISTRIB_CODENAME} .*universe" /etc/apt/sources.list
if [ $? -ne 0 ]; then
    echo "Please enable the 'universe' component in /etc/apt/source.list'"
    exit 1
fi
grep -q "^deb http:.* ${DISTRIB_CODENAME} .*multiverse" /etc/apt/sources.list
if [ $? -ne 0 ]; then
    echo "Please enable the 'multiverse' component in /etc/apt/source.list'"
    exit 1
fi

if [ ! -e ~/.ssh/config ]; then
    touch ~/.ssh/config
fi

grep -q "^GSSAPIAuthentication" ~/.ssh/config
if [ $? -ne 0 ]; then
  echo "Please add the following directive to your ~/.ssh/config:
------------------------------------------------------------
GSSAPIAuthentication no
------------------------------------------------------------
"
  read
fi

grep -q "^Host .*chinstrap" ~/.ssh/config
if [ $? -ne 0 ]; then
  echo "Please add the following directives to your ~/.ssh/config:
------------------------------------------------------------
Host chinstrap chinstrap.canonical.com chinstrap.ubuntu.com
    ForwardAgent yes
    Hostname chinstrap.canonical.com
    ProxyCommand none
    User ${whoami}
------------------------------------------------------------
"
  read
fi

grep -q "^Host.*\*\.canonical.com" ~/.ssh/config
if [ $? -ne 0 ]; then
  echo "Please add the following directives to your ~/.ssh/config:
------------------------------------------------------------
Host *.canonical.com *.ubuntu.com
    ForwardAgent yes
    ProxyCommand ssh chinstrap.canonical.com nc -q0 %h %p
    User ${whoami}
------------------------------------------------------------
"
  read
fi

grep -q "^Host .*devpad" ~/.ssh/config
if [ $? -ne 0 ]; then
  echo "Please add the following directives to your ~/.ssh/config:
------------------------------------------------------------
Host devpad devpad.canonical.com
    ForwardAgent yes
    Hostname devpad.canonical.com
    ProxyCommand ssh chinstrap.canonical.com nc -q0 %h %p
    User ${whoami}
------------------------------------------------------------
"
  read
fi

grep -q "^Host .*bazaar.launchpad.dev" ~/.ssh/config
if [ $? -ne 0 ]; then
  echo "Please add the following directives to your ~/.ssh/config:
------------------------------------------------------------
Host bazaar.launchpad.dev
    Hostname launchpad.dev
    HostKeyAlias bazaar.launchpad.dev
    User sabdfl
    Port 5022
    IdentityFile ~/.ssh/launchpad_id_dsa
------------------------------------------------------------
"
  read
fi

echo "Testing ssh to devpad..."
ssh devpad.canonical.com pwd > /dev/null
if [ $? -ne 0 ]; then
  echo "
ERROR: Unable to verify capability to ssh to devpad. Please check
~/.ssh/config and check the User configuration item.  ['${whoami}']"
  exit 1
fi

sudo apt-key list | grep -q "2048g/CA6E8A17"
if [ $? -ne 0 ]; then
  echo "Retrieving signing-key for LP package repository."
  scp devpad.canonical.com:/code/lp-maintainers.pub /tmp/
  if [ $? -ne 0 ]; then
    echo "Unable to fetch key for LP package repository"
    exit 1
  fi
  [ `sha1sum /tmp/lp-maintainers.pub | cut -d " " -f 1` = \
     f1714a57bd8c481f45b2a64e2eb9131176c8922e ] \
  && sudo apt-key add /tmp/lp-maintainers.pub
  if [ $? -ne 0 ]; then
    echo "Unable to add key for LP package repository"
    exit 1
  fi
fi


grep -q "^deb http://lpdebs.canonical.com/" /etc/apt/sources.list
if [ $? -ne 0 ]; then
  echo "Adding LP package respository to package source list."
  echo "deb http://lpdebs.canonical.com/${DISTRIB_CODENAME} ./" | sudo tee -a /etc/apt/sources.list > /dev/null
  sudo aptitude update
fi


dpkg -s launchpad-developer-dependencies | grep -q "^Status:.*installed"
if [ $? -ne 0 ]; then
  echo "Installing launchpad-developer-dependencies package..."
  sudo aptitude install launchpad-developer-dependencies
  if [ $? -ne 0 ]; then
    echo "Unable to install LP developer dependencies"
    exit 1
  fi
fi

# Create the document root to avoid Apache warnings
mkdir -p /var/tmp/bazaar.launchpad.dev/mirrors

# Create an empty rewritemap file so that Apache will start.
mkdir -p /var/tmp/bazaar.launchpad.dev/config
touch /var/tmp/bazaar.launchpad.dev/config/launchpad-lookup.txt

sudo a2enmod proxy > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to enable proxy module in Apache2"
  exit 1
fi

sudo a2enmod proxy_http > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to enable proxy_http module in Apache2"
  exit 1
fi

sudo a2enmod rewrite > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to enable rewrite module in Apache2"
  exit 1
fi

sudo a2enmod ssl > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to enable ssl module in Apache2"
  exit 1
fi

sudo a2enmod deflate > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to enable deflate module in Apache2"
  exit 1
fi

echo "Setting up devpad repository..."
ssh devpad.canonical.com /code/rocketfuel-built/launchpad/utilities/devpad-setup


# Create the local branch structure we will use for managing Launchpad code
mkdir -p $LP_PROJECT_ROOT
cd $LP_PROJECT_ROOT
if [ ! -d $LP_SHARED_REPO ]; then
  bzr init-repo --trees $LP_SHARED_REPO
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to setup local LP repository"
    exit 1
  fi
fi
if [ ! -d $LP_SHARED_REPO/.bzr -a -d $LP_SHARED_REPO/.bzr/repository ]; then
  echo "ERROR: LP repository not found in $LP_PROJECT_PATH"
  exit 1
fi

cd $LP_SHARED_REPO
if [ ! -d $LP_TRUNK_NAME ]; then
  echo "Making local branch of Launchpad trunk, this may take a while..."
  # bzr up to 1.6b2 has a bug that causes this to oom.
  #bzr branch bzr+ssh://devpad.canonical.com/code/rocketfuel/launchpad/devel $LP_TRUNK_NAME
  bzr branch sftp://devpad.canonical.com/code/rocketfuel/launchpad/devel $LP_TRUNK_NAME
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to create local copy of Rocketfuel trunk"
    exit 1
  fi
fi

cd $LP_TRUNK_NAME
if [ ! `bzr info | grep -i "parent branch" | cut -d: -f3` = \
  "//devpad.canonical.com/code/rocketfuel/launchpad/devel/" ]; then
  echo "ERROR: Your trunk branch in $LP_TRUNK_PATH has an
       incorrect pull location, correcting now..."
  bzr pull --remember bzr+ssh://devpad.canonical.com/code/rocketfuel/launchpad/devel
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to set trunk pull location to
       bzr+ssh://devpad.canonical.com/code/rocketfuel/launchpad/devel"
    exit 1
  fi
fi

sudo make install > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to install apache config appropriately"
  exit 1
fi



# Setup Bazaar locations configuration
if [ ! -d ~/.bazaar ]; then
  mkdir ~/.bazaar
  if [ $? -ne 0 ]; then
    echo "Unable to create ~/.bazaar/ directory"
    exit 1
  fi
fi
if [ ! -e ~/.bazaar/locations.conf ]; then
  touch ~/.bazaar/locations.conf
fi
grep -q "\[${LP_PROJECT_PATH}\]" ~/.bazaar/locations.conf
if [ $? -ne 0 ]; then
  echo "
[$LP_PROJECT_PATH]
pqm_email = Launchpad PQM <launchpad@pqm.canonical.com>
submit_branch = ${LP_TRUNK_PATH}
public_branch = bzr+ssh://devpad.canonical.com/code/${whoami}/launchpad
public_branch:policy = appendpath
smtp_server = localhost
push_location = bzr+ssh://devpad.canonical.com/code/${whoami}/launchpad
push_location:policy = appendpath
review_list = Launchpad Reviews <launchpad-reviews@lists.canonical.com>
merge_target = ${LP_TRUNK_PATH}" | tee -a ~/.bazaar/locations.conf > /dev/null
  echo "Bazaar branch configuration updated. You may need to set smtp_server
in ~/.bazaar/locations.conf to something other than localhost"
fi

grep -q "\[$LP_TRUNK_PATH\]" ~/.bazaar/locations.conf
if [ $? -ne 0 ]; then
  echo "
[$LP_TRUNK_PATH]
public_branch = sftp://devpad.canonical.com/code/rocketfuel/launchpad/devel\
" | tee -a ~/.bazaar/locations.conf > /dev/null
fi

# Setup access to the local supermirror
if [ ! -e ~/.ssh/launchpad_id_dsa ]; then
  cp $LP_TRUNK_PATH/lib/canonical/codehosting/tests/id_dsa ~/.ssh/launchpad_id_dsa
  chmod 600 ~/.ssh/launchpad_id_dsa
  echo "Setup ssh key for local supermirror ssh access."
fi

# Setup environment variables in a ~ dot file
cd $HOME
if [ ! -e $HOME/.rocketfuel-env.sh ]; then
  ln -s $LP_TRUNK_PATH/utilities/rocketfuel-env.sh .rocketfuel-env.sh
fi

# Setup scripts in /usr/local/bin
cd /usr/local/bin
if [ ! -e rocketfuel-get ]; then
  sudo ln -s $LP_TRUNK_PATH/utilities/rocketfuel-get
fi
ls -l rocketfuel-get | cut -d">" -f2 | grep -q "$LP_TRUNK_NAME\/utilities\/rocketfuel"
if [ $? -ne 0 ]; then
  echo "WARNING: /usr/local/bin/rocketfuel-get should be deleted so I can
         recreate it."
fi
if [ ! -e rocketfuel-flakes ]; then
  sudo ln -s $LP_TRUNK_PATH/utilities/rocketfuel-flakes
fi
ls -l rocketfuel-flakes | cut -d">" -f2 | grep -q "$LP_TRUNK_NAME\/utilities\/rocketfuel"
if [ $? -ne 0 ]; then
  echo "WARNING: /usr/local/bin/rocketfuel-flakes should be deleted so I can
         recreate it."
fi
if [ ! -e rocketfuel-branch ]; then
  sudo ln -s $LP_TRUNK_PATH/utilities/rocketfuel-branch
fi
ls -l rocketfuel-branch | cut -d">" -f2 | grep -q "$LP_TRUNK_NAME\/utilities\/rocketfuel"
if [ $? -ne 0 ]; then
  echo "WARNING: /usr/local/bin/rocketfuel-branch should be deleted so I can
         recreate it."
fi
if [ ! -e rocketfuel-setup ]; then
  sudo ln -s $LP_TRUNK_PATH/utilities/rocketfuel-setup
fi
ls -l rocketfuel-setup | cut -d">" -f2 | grep -q "$LP_TRUNK_NAME\/utilities\/rocketfuel"
if [ $? -ne 0 ]; then
  echo "WARNING: /usr/local/bin/rocketfuel-setup should be deleted so I can
         recreate it."
fi
if [ ! -e rocketfuel-status ]; then
  sudo ln -s $LP_TRUNK_PATH/utilities/rocketfuel-status
fi
ls -l rocketfuel-status | cut -d">" -f2 | grep -q "$LP_TRUNK_NAME\/utilities\/rocketfuel"
if [ $? -ne 0 ]; then
  echo "WARNING: /usr/local/bin/rocketfuel-status should be deleted so I can
         recreate it."
fi
if [ ! -e rocketfuel-push ]; then
  sudo ln -s $LP_TRUNK_PATH/utilities/rocketfuel-push
fi
ls -l rocketfuel-push | cut -d">" -f2 | grep -q "$LP_TRUNK_NAME\/utilities\/rocketfuel"
if [ $? -ne 0 ]; then
  echo "WARNING: /usr/local/bin/rocketfuel-push should be deleted so I can
         recreate it."
fi


# Make sure we have all the right code in place for source dependencies
/usr/local/bin/rocketfuel-get

echo "
Thank you for using this script. You can improve it for everyone by
committing changes to LP in utilities/rocketfuel-setup.

You should use the following commands to manage your Rocketfuel:

 rocketfuel-get
    Update your copy of trunk and the necessary source dependencies, and
    make sure all source dependencies are properly linked in to all the
    branches you are working on.

 rocketfuel-branch foo
    Create a new branch of LP called "foo" in $LP_PROJECT_PATH/foo,
    with all the source dependencies properly linked in.

 rocketfuel-status
    Check each of the branches in $LP_PROJECT_PATH and show which of them have
    uncommitted changes, also check which ones have revisions that have not
    yet landed on trunk.

 rocketfuel-push
    Push all of your branches to devpad, so that you have a server-side
    backup of everything.

Happy hacking!
"