~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
#! /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
#

# 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

for hostname in code.launchpad.dev answers.launchpad.dev blueprints.launchpad.dev bugs.launchpad.dev translations.launchpad.dev xmlrpc.launchpad.dev bazaar.launchpad.dev shipit.ubuntu.dev shipit.kubuntu.dev shipit.edubuntu.dev feeds.launchpad.dev openid.launchpad.dev; 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


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 ~/canonical
cd ~/canonical
if [ ! -d lp-branches ]; then
  bzr init-repo --trees lp-branches
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to setup local LP repository"
    exit 1
  fi
fi
if [ ! -d lp-branches/.bzr -a -d lp-branches/.bzr/repository ]; then
  echo "ERROR: LP repository not found in ~/canonical/lp-branches/"
  exit 1
fi

cd lp-branches
if [ ! -d trunk ]; then
  echo "Making local branch of Launchpad trunk, this will take a while..."
  bzr branch bzr+ssh://devpad.canonical.com/code/rocketfuel/launchpad/devel trunk
  if [ $? -ne 0 ]; then
    echo "ERROR: Unable to create local copy of Rocketfuel trunk"
    exit 1
  fi
fi

cd trunk
if [ ! `bzr info | grep -i "parent branch" | cut -d: -f3` = \
  "//devpad.canonical.com/code/rocketfuel/launchpad/devel/" ]; then
  echo "ERROR: Your trunk branch in ~/canonical/lp-branches/trunk 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 "canonical\/lp-branches" ~/.bazaar/locations.conf
if [ $? -ne 0 ]; then
  branchloc=$(eval echo "~/canonical/lp-branches")
  echo "
[${branchloc}]
pqm_email = Launchpad PQM <launchpad@pqm.canonical.com>
pqm_branch = sftp://devpad.canonical.com/code/rocketfuel/launchpad/devel
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
" | 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

# Setup access to the local supermirror
if [ ! -e ~/.ssh/launchpad_id_dsa ]; then
  cp ~/canonical/lp-branches/trunk/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 scripts in /usr/local/bin
cd /usr/local/bin
if [ ! -e rocketfuel-get ]; then
  sudo ln -s ~/canonical/lp-branches/trunk/utilities/rocketfuel-get
fi
ls -l rocketfuel-get | cut -d">" -f2 | grep -q "trunk\/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 ~/canonical/lp-branches/trunk/utilities/rocketfuel-flakes
fi
ls -l rocketfuel-flakes | cut -d">" -f2 | grep -q "trunk\/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 ~/canonical/lp-branches/trunk/utilities/rocketfuel-branch
fi
ls -l rocketfuel-branch | cut -d">" -f2 | grep -q "trunk\/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 ~/canonical/lp-branches/trunk/utilities/rocketfuel-setup
fi
ls -l rocketfuel-setup | cut -d">" -f2 | grep -q "trunk\/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 ~/canonical/lp-branches/trunk/utilities/rocketfuel-status
fi
ls -l rocketfuel-status | cut -d">" -f2 | grep -q "trunk\/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 ~/canonical/lp-branches/trunk/utilities/rocketfuel-push
fi
ls -l rocketfuel-push | cut -d">" -f2 | grep -q "trunk\/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-branch foo
    Create a new branch of LP called "foo" in ~/canonical/lp-branches/foo,
    with all the source dependencies properly linked in.

 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-status
    Check each of the branches in ~/canonical/lp-branches/ 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!
"