~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
#! /bin/bash
#
# Copyright 2009, 2010 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
#
# This script will set up a brand new Ubuntu machine as a LP developer
# workstation, from scratch. The script lives in the LP codebase itself,
# as utilities/rocketfuel-setup

# load up Ubuntu release details so we know which repos to enable
source /etc/lsb-release
DO_WORKSPACE=1
for arg in "$@"; do
  if [ "$arg" == "--no-workspace" ]; then
    DO_WORKSPACE=0
  else
    echo Unrecognized argument: $arg >& 2
    exit 1;
  fi
done

# Establish LP username
whoami=`whoami`
printf "What is your Launchpad username? [$whoami] "
read lpusername
if [ -z ${lpusername} ]; then
  lpusername=${whoami}
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
    archive.launchpad.dev
    api.launchpad.dev
    bazaar-internal.launchpad.dev
    beta.launchpad.dev
    blueprints.launchpad.dev
    bugs.launchpad.dev
    code.launchpad.dev
    feeds.launchpad.dev
    id.launchpad.dev
    keyserver.launchpad.dev
    lists.launchpad.dev
    openid.launchpad.dev
    ubuntu-openid.launchpad.dev
    ppa.launchpad.dev
    private-ppa.launchpad.dev
    testopenid.dev
    translations.launchpad.dev
    xmlrpc-private.launchpad.dev
    xmlrpc.launchpad.dev
EOF
    )

for hostname in $hostnames; do
  dev_host;
done

grep -q "^127.0.0.99" /etc/hosts
if [ $? -ne 0 ]; then
  echo "
127.0.0.99      bazaar.launchpad.dev
" | sudo tee -a /etc/hosts > /dev/null
  echo "bazaar.launchpad.dev added to /etc/hosts"
fi

# 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/sources.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/sources.list'"
    exit 1
fi

LPDEV_SOURCES="/etc/apt/sources.list.d/launchpad-dev.list"
if [ ! -e $LPDEV_SOURCES ]; then
  sudo touch $LPDEV_SOURCES
fi

LP_PPA="deb http://ppa.launchpad.net/launchpad/ppa/ubuntu ${DISTRIB_CODENAME} main"
grep -q "^${LP_PPA}" $LPDEV_SOURCES
if [ $? -ne 0 ]; then
  echo "Adding ~launchpad PPA repository to package source list."
  echo "$LP_PPA"  | sudo tee -a $LPDEV_SOURCES
fi

BZR_PPA="deb http://ppa.launchpad.net/bzr/ppa/ubuntu ${DISTRIB_CODENAME} main"
grep -q "^${BZR_PPA}" $LPDEV_SOURCES
if [ $? -ne 0 ]; then
  echo "Adding ~bzr PPA repository to package source list."
  echo "$BZR_PPA" | sudo tee -a $LPDEV_SOURCES
fi

# Get the key used to sign the launchpad-developer-dependencies in the PPA.
REQUIRED_PPA_KEYS="0A5174AF 8C6C1EFD"
for key in $REQUIRED_PPA_KEYS; do
   sudo apt-key list | grep -q $key
   if [ $? -ne 0 ]; then
     echo "Retrieving key $key."
     gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys $key
     if [ $? -ne 0 ]; then
       echo "Could not retrieve key $key."
       exit 1
     fi
     gpg --export -a $key | sudo apt-key add -
     if [ $? -ne 0 ]; then
       echo "Could not install key $key."
       exit 1
     fi
   fi
done

do_install() {
  dpkg -s $pkg | grep -q "^Status: install ok installed"
  if [ $? -ne 0 ]; then
    echo "Installing $pkg package..."
    sudo apt-get install $pkg
    if [ $? -ne 0 ]; then
      echo "Unable to install $pkg."
      exit 1
    fi
  fi
  }

sudo apt-get update
REQUIRED_PACKAGES="launchpad-developer-dependencies apache2 apache2-mpm-worker"
for pkg in $REQUIRED_PACKAGES; do
  do_install;
done

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

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

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

if [ $DO_WORKSPACE == 0 ]; then
  cat <<EOT
Branches have not been created, as requested.  You will need to do some or all
of the following steps:
$ bzr branch lp:launchpad devel
$ cd devel
$ bzr branch lp:~launchpad/lp-source-dependencies/trunk/ download-cache
$ utilities/update-sourcecode
$ utilities/launchpad-database-setup
$ make schema
$ sudo make install
EOT
  exit 0
fi

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 Launchpad 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:=~/launchpad}
LP_SHARED_REPO=\${LP_SHARED_REPO:=lp-branches}
LP_PROJECT_PATH=\$LP_PROJECT_ROOT/\$LP_SHARED_REPO
LP_TRUNK_NAME=\${LP_TRUNK_NAME:=devel}
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


# 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
  # 2a format (a.k.a. "brisbane-core") needed for stacking on Launchpad.
  bzr init-repo --2a $LP_SHARED_REPO
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to set up 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

echo "Logging bzr into Launchpad (it's okay if this errors)..."
bzr launchpad-login $lpusername
if [ $? -ne 0 ]; then
  echo ""
  echo "You can ignore any error above about not registering an SSH key"
  echo "with Launchpad.  Registering an SSH key is only important if you"
  echo "are writing data to Launchpad, or trying to access private data."
  echo ""
fi

cd $LP_SHARED_REPO
if [ ! -d $LP_TRUNK_NAME ]; then
  echo "Making local branch of Launchpad trunk, this may take a while..."
  bzr branch lp:~launchpad-pqm/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
bzr st -q
if [ $? -ne 0 ]; then
  echo "ERROR: Your trunk branch in $LP_TRUNK_PATH is corrupted.
       Please delete $LP_TRUNK_PATH and run rocketfuel-setup again."
       exit 1
fi
if [ ! `bzr info | grep -i "parent branch" | cut -d: -f3` = \
  "//bazaar.launchpad.net/~launchpad-pqm/launchpad/devel/" ]; then
  echo "ERROR: Your trunk branch in $LP_TRUNK_PATH has an
       incorrect pull location, correcting now..."
  bzr pull --remember bzr+ssh://bazaar.launchpad.net/~launchpad-pqm/launchpad/devel/
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to set trunk pull location to lp:~launchpad-pqm/launchpad/devel/"
    exit 1
  fi
fi

# Call the newly minted Launchpad branch's 'make install' target to do some
# more apache setup.
sudo make install > /dev/null
if [ $? -ne 0 ]; then
  echo "ERROR: Unable to install apache config appropriately"
  exit 1
fi


# Set up 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
  cat >> ~/.bazaar/locations.conf << EOF
[$LP_PROJECT_PATH]
submit_branch = ${LP_TRUNK_PATH}
public_branch = bzr+ssh://bazaar.launchpad.net/~${lpusername}/launchpad
public_branch:policy = appendpath
push_location = lp:~${lpusername}/launchpad
push_location:policy = appendpath
merge_target = ${LP_TRUNK_PATH}
submit_to = merge@code.launchpad.net
EOF

grep -q "\[$LP_TRUNK_PATH\]" ~/.bazaar/locations.conf
if [ $? -ne 0 ]; then
  echo "
[$LP_TRUNK_PATH]
public_branch = bzr+ssh://bazaar.launchpad.net/~launchpad-pqm/launchpad/devel\
" | tee -a ~/.bazaar/locations.conf > /dev/null
fi

echo "Bazaar branch configuration updated."

fi

# Set up 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 Launchpad in utilities/rocketfuel-setup.

Please see http://dev.launchpad.net/ for more information on
developing and testing Launchpad, and on submitting changes.

You can use the following commands to manage your Launchpad
development environment:

 rocketfuel-get
    Update your copy of $LP_TRUNK_NAME 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 Launchpad, so that you have a server-side
    backup of everything.

Happy hacking!
"