Merge lp:~jaywink/diaspora-ppa/diaspora-develop-setup into lp:~diaspora-ppa/diaspora-ppa/diaspora-metapackage-trunk
- diaspora-develop-setup
- Merge into diaspora-metapackage-trunk
Proposed by
Jason Robinson
Status: | Merged |
---|---|
Merged at revision: | 7 |
Proposed branch: | lp:~jaywink/diaspora-ppa/diaspora-develop-setup |
Merge into: | lp:~diaspora-ppa/diaspora-ppa/diaspora-metapackage-trunk |
Diff against target: |
483 lines (+403/-15) 2 files modified
debian/changelog (+7/-0) scripts/diasporactrl (+396/-15) |
To merge this branch: | bzr merge lp:~jaywink/diaspora-ppa/diaspora-develop-setup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
diaspora* Team | Pending | ||
Review via email: mp+129963@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2012-10-13 21:10:34 +0000 |
3 | +++ debian/changelog 2012-10-16 19:20:29 +0000 |
4 | @@ -1,3 +1,10 @@ |
5 | +diaspora (0.0.1.1) precise; urgency=low |
6 | + |
7 | + * Development environment setup and control implemented |
8 | + * Bump version to match latest upstream |
9 | + |
10 | + -- Jason Robinson <jaywink@basshero.org> Tue, 16 Oct 2012 22:14:40 +0300 |
11 | + |
12 | diaspora (0.0.1ubuntu6) precise; urgency=low |
13 | |
14 | * Added bundler gem installation to diasporactrl install rvm |
15 | |
16 | === modified file 'scripts/diasporactrl' |
17 | --- scripts/diasporactrl 2012-10-13 21:10:34 +0000 |
18 | +++ scripts/diasporactrl 2012-10-16 19:20:29 +0000 |
19 | @@ -1,7 +1,61 @@ |
20 | #!/bin/bash |
21 | -# Control script for Diaspora* |
22 | -# |
23 | -# |
24 | +# Control script for Diaspora* social network |
25 | +# |
26 | +# Launchpad: https://launchpad.net/diaspora-ppa |
27 | +# Diaspora* project: http://diasporaproject.org |
28 | +# |
29 | +# Licensed under AGPLv3 |
30 | +# |
31 | +# TODO's: |
32 | +# - Prod env setup (using diaspora master source from PPA) |
33 | +# - Remove environments on remove script |
34 | +# - Remove environment command |
35 | +# |
36 | + |
37 | +# Usage information |
38 | +print_usage() { |
39 | + echo "" |
40 | + echo "Diaspora* control script for Ubuntu" |
41 | + echo "-----------------------------------" |
42 | + echo "" |
43 | + echo "Usage: diasporactrl command [options]" |
44 | + echo "" |
45 | + echo "Commands:" |
46 | + echo " install rvm" |
47 | + echo " Installs Ruby RVM under current user or if" |
48 | + echo " run with sudo, user can be chosen." |
49 | + echo " remove rvm" |
50 | + echo " Removes RVM and all installed gems under it." |
51 | + echo " setup develop <name>" |
52 | + echo " Set up a development environment <name>. Name must be" |
53 | + echo " a valid folder name as environment will be created under" |
54 | + echo " current path in a sub-directory." |
55 | + echo " Development environment is based on Diaspora* Github" |
56 | + echo " development branch head." |
57 | + echo " setup stable <name>" |
58 | + echo " Not implemented yet. This command will in future be used" |
59 | + echo " to set up a stable production environment." |
60 | + echo " setup database" |
61 | + echo " Set up database for environment in current folder." |
62 | + echo " Used to finish an environment installation if database" |
63 | + echo " credentials were not given during environment setup." |
64 | + echo " start" |
65 | + echo " Start Diaspora* environment in current folder (development" |
66 | + echo " environments)." |
67 | + echo " stop" |
68 | + echo " Stop Diaspora* environment that was previously started in" |
69 | + echo " this folder." |
70 | + echo "" |
71 | + echo "Author: Jason Robinson <jaywink@basshero.org>" |
72 | + echo "Find me on Diaspora* at jaywink@joindiaspora.com" |
73 | + echo "" |
74 | + echo "Code for this script is maintained at Launchpad:" |
75 | + echo "https://code.launchpad.net/diaspora-ppa" |
76 | + echo "" |
77 | + echo "Please file bugs on Launchpad. Discussion on Diaspora* packaging" |
78 | + echo "efforts happens at http://loom.io/groups/282" |
79 | + echo "" |
80 | +} |
81 | |
82 | # RVM installation |
83 | install_rvm() { |
84 | @@ -18,7 +72,14 @@ |
85 | # Activate RVM for user |
86 | activate_rvm() { |
87 | if [ -n "$1" ]; then |
88 | - su - $1 -c "source /home/$1/.rvm/scripts/rvm" |
89 | + if [ `whoami` = "root" ]; then |
90 | + su - $1 -c "source /home/$1/.rvm/scripts/rvm" |
91 | + elif [ `whoami` = $1 ]; then |
92 | + source /home/$1/.rvm/scripts/rvm |
93 | + else |
94 | + echo "Cannot activate RVM for another user without being root!" |
95 | + exit 1 |
96 | + fi |
97 | else |
98 | echo "Cannot activate RVM for null username!" |
99 | exit 1 |
100 | @@ -120,6 +181,211 @@ |
101 | fi |
102 | } |
103 | |
104 | +# Get Diaspora system user |
105 | +get_diaspora_user() { |
106 | + username="" |
107 | + if [ `whoami` != "root" ]; then |
108 | + # we are a user |
109 | + if [ -d "$HOME/.diaspora" ]; then |
110 | + username=`whoami` |
111 | + else |
112 | + # also check if installed with sudo for another user |
113 | + if [ -e "/etc/diaspora/.diaspora_user" ]; then |
114 | + username=`cat /etc/diaspora/.diaspora_user` |
115 | + fi |
116 | + fi |
117 | + else |
118 | + # we are root |
119 | + # See if D* user has been set |
120 | + if [ -e "/etc/diaspora/.diaspora_user" ]; then |
121 | + username=`cat /etc/diaspora/.diaspora_user` |
122 | + fi |
123 | + fi |
124 | +} |
125 | + |
126 | +# Set configuration variables for environment in current directory |
127 | +set_config() { |
128 | + key="ENVIRONMENT_$1" |
129 | + if [ ! -e ".diasporactrlrc" ]; then |
130 | + # Are we in a Diaspora* environment folder? |
131 | + if [ ! -e ".rvmrc" ]; then |
132 | + echo "set_config(): We are not in a Diaspora* environment folder!" |
133 | + echo "Error in script?" |
134 | + exit 1 |
135 | + fi |
136 | + touch ".diasporactrlrc" |
137 | + fi |
138 | + |
139 | + if [ $(grep -c "export $key=$2" .diasporactrlrc) -ne 0 ]; then |
140 | + # conf item exists, replace it |
141 | + sed -i "s/$key/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" .diasporactrlrc |
142 | + else |
143 | + # new conf item |
144 | + echo "export $key=$2" >> .diasporactrlrc |
145 | + fi |
146 | +} |
147 | + |
148 | +# Skip database setup |
149 | +skip_database_setup() { |
150 | + echo "" |
151 | + echo "You have chosen to skip database credential setup or one" |
152 | + echo "or more values were null. Please do this step later by editing" |
153 | + echo "the following file:" |
154 | + echo "`pwd`/config/database.yml" |
155 | + echo "" |
156 | + echo "Press enter to continue" |
157 | + read enterkey |
158 | +} |
159 | + |
160 | +# Run DB init actions |
161 | +run_db_init() { |
162 | + if [ "$1" = "development" ]; then |
163 | + echo "" |
164 | + echo "Setting up database in development mode.." |
165 | + echo "" |
166 | + bundle exec rake db:create |
167 | + bundle exec rake db:schema:load |
168 | + echo "" |
169 | + echo "DB setup complete!" |
170 | + echo "" |
171 | + fi |
172 | +} |
173 | + |
174 | +# Print startup instructions |
175 | +print_startup_instructions() { |
176 | + echo "" |
177 | + echo "To run the environment, change to the environment folder and" |
178 | + echo "execute the following command:" |
179 | + echo "diasporactrl start" |
180 | + echo "" |
181 | + echo "This will start a background server process which you can then" |
182 | + echo "stop with the command:" |
183 | + echo "diasporactrl stop" |
184 | + echo "" |
185 | +} |
186 | + |
187 | +# Create dev environment logic |
188 | +create_dev_environment() { |
189 | + echo "" |
190 | + echo "Beginning installation of development environment" |
191 | + echo "" |
192 | + |
193 | + if [ -d $1 ]; then |
194 | + echo "Directory $1 exists! We need to create a directory for the environment," |
195 | + echo "please choose another name or run in another location." |
196 | + exit 1 |
197 | + fi |
198 | + |
199 | + git clone git://github.com/diaspora/diaspora.git $1 |
200 | + |
201 | + if [ $? -ne 0 ]; then |
202 | + echo "Something wrong in git clone command, please check the error output and retry." |
203 | + exit 1 |
204 | + fi |
205 | + |
206 | + # save environment name to ~/.diaspora folder |
207 | + echo `pwd`/$1 >> $HOME/.diaspora/envs_development |
208 | + |
209 | + echo "" |
210 | + echo "I will now move to the dev environment directory. This will trigger a question" |
211 | + echo "from Ruby RVM about trusting the .rvmrc file provided by Diaspora*. You must answer" |
212 | + echo "yes to this question in order to have all the required Ruby gems set up properly." |
213 | + echo "" |
214 | + echo -n "Please press enter to continue" |
215 | + read key |
216 | + |
217 | + cd $1 |
218 | + |
219 | + # user accepts .rvmrc, rvm does stuff |
220 | + |
221 | + # continue with installation, mysql supported only at the moment, it has been |
222 | + # pulled via dependencies |
223 | + |
224 | + # install gems |
225 | + DB="mysql" bundle install |
226 | + |
227 | + if [ $? -ne 0 ]; then |
228 | + echo "Something wrong from bundler, please check the error output and retry." |
229 | + exit 1 |
230 | + fi |
231 | + |
232 | + # configure |
233 | + # set a localhost url (this also creates the config file for this env) |
234 | + set_config "ENVIRONMENT_URL" "https://127.0.0.1:3000/" |
235 | + |
236 | + # copy script_server config // will be changed soon in 0.0.2 |
237 | + cp config/script_server.yml.example config/script_server.yml |
238 | + |
239 | + # database config |
240 | + cp config/database.yml.example config/database.yml |
241 | + echo "" |
242 | + echo "Database (MySQL) username/password needs to be set up. The database user" |
243 | + echo "needs rights to create a new database for this environment. You either" |
244 | + echo "set this information up later or do it now." |
245 | + echo "" |
246 | + echo -n "Would you like to set up the database information now? (Y/n) " |
247 | + read yesorno |
248 | + if [ "$yesorno" != "Y" ]; then |
249 | + # get database info |
250 | + echo -n "DB: Please type database username? " |
251 | + read dbusername |
252 | + echo -n "DB: Please type database password? " |
253 | + read dbpassword |
254 | + if [ -z "$dbusername" ] || [ -z "$dbpassword" ]; then |
255 | + # one or both values empty - skip |
256 | + skip_database_setup |
257 | + dbconfigured=false |
258 | + else |
259 | + # save values |
260 | + replacestr="username: \"$dbusername\"" |
261 | + sed -i "s/username: \"root\"/$(echo $replacestr | sed -e 's/[\/&]/\\&/g')/g" config/database.yml |
262 | + replacestr="password: \"$dbpassword\"" |
263 | + sed -i "s/password: \"\"/$(echo $replacestr | sed -e 's/[\/&]/\\&/g')/g" config/database.yml |
264 | + |
265 | + # TODO: ask if user would like these to be saved in .diaspora folder for later use |
266 | + |
267 | + # set db name to unique, so we can set up multiple envs |
268 | + # TODO: add random number |
269 | + sed -i "s/diaspora_development/diaspora_$1/g" config/database.yml |
270 | + dbconfigured=true |
271 | + fi |
272 | + else |
273 | + skip_database_setup |
274 | + dbconfigured=false |
275 | + fi |
276 | + |
277 | + # Some generic conf variables |
278 | + set_config "SETTINGS_POD_NAME" "Diaspora* $1" |
279 | + set_config "SETTINGS_ENABLE_REGISTRATIONS" "true" |
280 | + |
281 | + # some fixes to get D* running without a config file, can be removed after this is fixed: |
282 | + # https://github.com/diaspora/diaspora/issues/3661 |
283 | + # we don't do these via set_config because it would append ENVIRONMENT_ |
284 | + echo "export HEROKU=true" >> .diasporactrlrc |
285 | + echo "export SECRET_TOKEN=58c7770115469e64ce3ff1f802cefc5e77d41694e8f64cd5408ab6b1a764babe0f9b8ae6e0a81d6b" >> .diasporactrlrc |
286 | + cp config/diaspora.yml.example config/diaspora.yml |
287 | + |
288 | + # Run DB stuff if DB config was done |
289 | + if [ "$dbconfigured" = "true" ]; then |
290 | + source .diasporactrlrc |
291 | + run_db_init "development" |
292 | + else |
293 | + echo "" |
294 | + echo "DB has not been set up since we do not have credentials." |
295 | + echo "Please edit config/database.yml and once done run the following:" |
296 | + echo "diasporactrl setup database development" |
297 | + echo "" |
298 | + fi |
299 | + |
300 | + echo "" |
301 | + echo "Environment $1 in `pwd` has been created!" |
302 | + echo "For developer guidelines, please make sure to read:" |
303 | + echo "https://github.com/diaspora/diaspora/wiki/Git-Workflow" |
304 | + echo "" |
305 | + |
306 | + print_startup_instructions |
307 | +} |
308 | + |
309 | case "$1" in |
310 | install) |
311 | case "$2" in |
312 | @@ -133,6 +399,12 @@ |
313 | echo "" |
314 | read oktocontinue |
315 | username=`whoami` |
316 | + |
317 | + # create home .diaspora dir |
318 | + if [ ! -d "$HOME/.diaspora" ]; then |
319 | + mkdir $HOME/.diaspora |
320 | + fi |
321 | + |
322 | else |
323 | # we are root, let's take a guess or ask user |
324 | echo "Guessing which user to install RVM to.." |
325 | @@ -142,6 +414,12 @@ |
326 | if [ -d "/etc/diaspora" ] && [ ! -e "/etc/diaspora/.diaspora_user" ]; then |
327 | echo $username > /etc/diaspora/.diaspora_user |
328 | fi |
329 | + |
330 | + # also create home .diaspora dir |
331 | + if [ ! -d "/home/$username/.diaspora" ]; then |
332 | + mkdir /home/$username/.diaspora |
333 | + chown $username /home/$username/.diaspora |
334 | + fi |
335 | fi |
336 | |
337 | if [ -n "$username" ]; then |
338 | @@ -159,13 +437,9 @@ |
339 | ;; |
340 | |
341 | *) |
342 | - echo "Unknown install argument" |
343 | - exit 1 |
344 | - |
345 | + print_usage |
346 | ;; |
347 | - |
348 | esac |
349 | - |
350 | ;; |
351 | |
352 | remove) |
353 | @@ -198,18 +472,125 @@ |
354 | ;; |
355 | |
356 | *) |
357 | - echo "Unknown remove argument" |
358 | + print_usage |
359 | + ;; |
360 | + esac |
361 | + ;; |
362 | + |
363 | + setup) |
364 | + case "$2" in |
365 | + develop) |
366 | + |
367 | + if [ -z $3 ]; then |
368 | + echo "Please supply a name for development environment, for example:" |
369 | + echo "diasporactrl setup develop mydevenv" |
370 | + exit 1 |
371 | + fi |
372 | + |
373 | + echo "Checking for Diaspora* system user information..." |
374 | + get_diaspora_user |
375 | + |
376 | + if [ -n "$username" ]; then |
377 | + echo "Diaspora* system user is: $username" |
378 | + else |
379 | + echo "No Diaspora* system user found!" |
380 | + echo "Did RVM and dependency installation go ok? Try this:" |
381 | + echo "diasporactrl install rvm" |
382 | + exit 1 |
383 | + fi |
384 | + |
385 | + # no point in supporting creation of dev environments for other users |
386 | + if [ `whoami` != "$username" ]; then |
387 | + echo "Please set up development environment by running as the Diaspora* system user" |
388 | + echo "If you want to set one up for this username (`whoami`), run:" |
389 | + echo "diasporactrl install rvm" |
390 | + exit 1 |
391 | + fi |
392 | + |
393 | + activate_rvm $username |
394 | + create_dev_environment $3 |
395 | + ;; |
396 | + |
397 | + stable) |
398 | + echo "Not supported yet! Please do manual setup using these instructions:" |
399 | + echo "https://github.com/diaspora/diaspora/wiki/Notes-on-Installing-and-Running-Diaspora" |
400 | exit 1 |
401 | + ;; |
402 | + |
403 | + database) |
404 | + get_diaspora_user |
405 | |
406 | - ;; |
407 | - |
408 | + if [ -n "$username" ]; then |
409 | + echo "Diaspora* system user is: $username" |
410 | + else |
411 | + echo "No Diaspora* system user found!" |
412 | + exit 1 |
413 | + fi |
414 | + activate_rvm $username |
415 | + source .diasporactrlrc |
416 | + run_db_init $3 |
417 | + print_startup_instructions |
418 | + ;; |
419 | + |
420 | + *) |
421 | + print_usage |
422 | + ;; |
423 | esac |
424 | - |
425 | + ;; |
426 | + |
427 | + start) |
428 | + if [ ! -e .diasporactrlrc ]; then |
429 | + echo "" |
430 | + echo "Not in a Diaspora* environment folder!" |
431 | + echo "tip: .diasporactrlrc missing, it is created by setting an" |
432 | + echo "environment using the command:" |
433 | + echo "diasporactrl setup develop mydevenv" |
434 | + echo "" |
435 | + exit 1 |
436 | + fi |
437 | + |
438 | + # load env variables |
439 | + source .diasporactrlrc |
440 | + |
441 | + # start in background |
442 | + script/server >> diasporactrl.log 2>&1 & |
443 | + echo $! >> "diasporactrl.pid" |
444 | + |
445 | + echo "" |
446 | + echo "Started server!" |
447 | + echo "You can check the log file 'diasporactrl.log' and after approx" |
448 | + echo "30 seconds access the environment at http://127.0.0.1:3000" |
449 | + echo "" |
450 | + echo "To stop the server, type:" |
451 | + echo "diasporactrl stop" |
452 | + echo "" |
453 | + ;; |
454 | + |
455 | + stop) |
456 | + if [ ! -e diasporactrl.pid ]; then |
457 | + echo "" |
458 | + echo "Can not find diasporactrl.pid file. Has an environment" |
459 | + echo "been started in this folder?" |
460 | + echo "" |
461 | + exit 1 |
462 | + fi |
463 | + |
464 | + # start in background |
465 | + pid2kill=`cat diasporactrl.pid` |
466 | + kill $pid2kill |
467 | + #TODO fix below - currently kills all running instances :) |
468 | + #but then currently only one can be started since port is always 3000 |
469 | + kill $(ps aux | grep '[d]iaspora' | awk '{print $2}') |
470 | + |
471 | + rm diasporactrl.pid |
472 | + |
473 | + echo "" |
474 | + echo "Server has been stopped!" |
475 | + echo "" |
476 | ;; |
477 | |
478 | *) |
479 | - echo "Unknown argument" |
480 | - exit 1 |
481 | + print_usage |
482 | ;; |
483 | esac |
484 |