Merge lp:~jaywink/diaspora-ppa/diaspora-develop-setup into lp:~diaspora-ppa/diaspora-ppa/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
Reviewer Review Type Date Requested Status
diaspora* Team Pending
Review via email: mp+129963@code.launchpad.net
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
=== modified file 'debian/changelog'
--- debian/changelog 2012-10-13 21:10:34 +0000
+++ debian/changelog 2012-10-16 19:20:29 +0000
@@ -1,3 +1,10 @@
1diaspora (0.0.1.1) precise; urgency=low
2
3 * Development environment setup and control implemented
4 * Bump version to match latest upstream
5
6 -- Jason Robinson <jaywink@basshero.org> Tue, 16 Oct 2012 22:14:40 +0300
7
1diaspora (0.0.1ubuntu6) precise; urgency=low8diaspora (0.0.1ubuntu6) precise; urgency=low
29
3 * Added bundler gem installation to diasporactrl install rvm10 * Added bundler gem installation to diasporactrl install rvm
411
=== modified file 'scripts/diasporactrl'
--- scripts/diasporactrl 2012-10-13 21:10:34 +0000
+++ scripts/diasporactrl 2012-10-16 19:20:29 +0000
@@ -1,7 +1,61 @@
1#!/bin/bash1#!/bin/bash
2# Control script for Diaspora*2# Control script for Diaspora* social network
3#3#
4#4# Launchpad: https://launchpad.net/diaspora-ppa
5# Diaspora* project: http://diasporaproject.org
6#
7# Licensed under AGPLv3
8#
9# TODO's:
10# - Prod env setup (using diaspora master source from PPA)
11# - Remove environments on remove script
12# - Remove environment command
13#
14
15# Usage information
16print_usage() {
17 echo ""
18 echo "Diaspora* control script for Ubuntu"
19 echo "-----------------------------------"
20 echo ""
21 echo "Usage: diasporactrl command [options]"
22 echo ""
23 echo "Commands:"
24 echo " install rvm"
25 echo " Installs Ruby RVM under current user or if"
26 echo " run with sudo, user can be chosen."
27 echo " remove rvm"
28 echo " Removes RVM and all installed gems under it."
29 echo " setup develop <name>"
30 echo " Set up a development environment <name>. Name must be"
31 echo " a valid folder name as environment will be created under"
32 echo " current path in a sub-directory."
33 echo " Development environment is based on Diaspora* Github"
34 echo " development branch head."
35 echo " setup stable <name>"
36 echo " Not implemented yet. This command will in future be used"
37 echo " to set up a stable production environment."
38 echo " setup database"
39 echo " Set up database for environment in current folder."
40 echo " Used to finish an environment installation if database"
41 echo " credentials were not given during environment setup."
42 echo " start"
43 echo " Start Diaspora* environment in current folder (development"
44 echo " environments)."
45 echo " stop"
46 echo " Stop Diaspora* environment that was previously started in"
47 echo " this folder."
48 echo ""
49 echo "Author: Jason Robinson <jaywink@basshero.org>"
50 echo "Find me on Diaspora* at jaywink@joindiaspora.com"
51 echo ""
52 echo "Code for this script is maintained at Launchpad:"
53 echo "https://code.launchpad.net/diaspora-ppa"
54 echo ""
55 echo "Please file bugs on Launchpad. Discussion on Diaspora* packaging"
56 echo "efforts happens at http://loom.io/groups/282"
57 echo ""
58}
559
6# RVM installation60# RVM installation
7install_rvm() {61install_rvm() {
@@ -18,7 +72,14 @@
18# Activate RVM for user72# Activate RVM for user
19activate_rvm() {73activate_rvm() {
20 if [ -n "$1" ]; then74 if [ -n "$1" ]; then
21 su - $1 -c "source /home/$1/.rvm/scripts/rvm"75 if [ `whoami` = "root" ]; then
76 su - $1 -c "source /home/$1/.rvm/scripts/rvm"
77 elif [ `whoami` = $1 ]; then
78 source /home/$1/.rvm/scripts/rvm
79 else
80 echo "Cannot activate RVM for another user without being root!"
81 exit 1
82 fi
22 else83 else
23 echo "Cannot activate RVM for null username!"84 echo "Cannot activate RVM for null username!"
24 exit 185 exit 1
@@ -120,6 +181,211 @@
120 fi181 fi
121}182}
122183
184# Get Diaspora system user
185get_diaspora_user() {
186 username=""
187 if [ `whoami` != "root" ]; then
188 # we are a user
189 if [ -d "$HOME/.diaspora" ]; then
190 username=`whoami`
191 else
192 # also check if installed with sudo for another user
193 if [ -e "/etc/diaspora/.diaspora_user" ]; then
194 username=`cat /etc/diaspora/.diaspora_user`
195 fi
196 fi
197 else
198 # we are root
199 # See if D* user has been set
200 if [ -e "/etc/diaspora/.diaspora_user" ]; then
201 username=`cat /etc/diaspora/.diaspora_user`
202 fi
203 fi
204}
205
206# Set configuration variables for environment in current directory
207set_config() {
208 key="ENVIRONMENT_$1"
209 if [ ! -e ".diasporactrlrc" ]; then
210 # Are we in a Diaspora* environment folder?
211 if [ ! -e ".rvmrc" ]; then
212 echo "set_config(): We are not in a Diaspora* environment folder!"
213 echo "Error in script?"
214 exit 1
215 fi
216 touch ".diasporactrlrc"
217 fi
218
219 if [ $(grep -c "export $key=$2" .diasporactrlrc) -ne 0 ]; then
220 # conf item exists, replace it
221 sed -i "s/$key/$(echo $2 | sed -e 's/[\/&]/\\&/g')/g" .diasporactrlrc
222 else
223 # new conf item
224 echo "export $key=$2" >> .diasporactrlrc
225 fi
226}
227
228# Skip database setup
229skip_database_setup() {
230 echo ""
231 echo "You have chosen to skip database credential setup or one"
232 echo "or more values were null. Please do this step later by editing"
233 echo "the following file:"
234 echo "`pwd`/config/database.yml"
235 echo ""
236 echo "Press enter to continue"
237 read enterkey
238}
239
240# Run DB init actions
241run_db_init() {
242 if [ "$1" = "development" ]; then
243 echo ""
244 echo "Setting up database in development mode.."
245 echo ""
246 bundle exec rake db:create
247 bundle exec rake db:schema:load
248 echo ""
249 echo "DB setup complete!"
250 echo ""
251 fi
252}
253
254# Print startup instructions
255print_startup_instructions() {
256 echo ""
257 echo "To run the environment, change to the environment folder and"
258 echo "execute the following command:"
259 echo "diasporactrl start"
260 echo ""
261 echo "This will start a background server process which you can then"
262 echo "stop with the command:"
263 echo "diasporactrl stop"
264 echo ""
265}
266
267# Create dev environment logic
268create_dev_environment() {
269 echo ""
270 echo "Beginning installation of development environment"
271 echo ""
272
273 if [ -d $1 ]; then
274 echo "Directory $1 exists! We need to create a directory for the environment,"
275 echo "please choose another name or run in another location."
276 exit 1
277 fi
278
279 git clone git://github.com/diaspora/diaspora.git $1
280
281 if [ $? -ne 0 ]; then
282 echo "Something wrong in git clone command, please check the error output and retry."
283 exit 1
284 fi
285
286 # save environment name to ~/.diaspora folder
287 echo `pwd`/$1 >> $HOME/.diaspora/envs_development
288
289 echo ""
290 echo "I will now move to the dev environment directory. This will trigger a question"
291 echo "from Ruby RVM about trusting the .rvmrc file provided by Diaspora*. You must answer"
292 echo "yes to this question in order to have all the required Ruby gems set up properly."
293 echo ""
294 echo -n "Please press enter to continue"
295 read key
296
297 cd $1
298
299 # user accepts .rvmrc, rvm does stuff
300
301 # continue with installation, mysql supported only at the moment, it has been
302 # pulled via dependencies
303
304 # install gems
305 DB="mysql" bundle install
306
307 if [ $? -ne 0 ]; then
308 echo "Something wrong from bundler, please check the error output and retry."
309 exit 1
310 fi
311
312 # configure
313 # set a localhost url (this also creates the config file for this env)
314 set_config "ENVIRONMENT_URL" "https://127.0.0.1:3000/"
315
316 # copy script_server config // will be changed soon in 0.0.2
317 cp config/script_server.yml.example config/script_server.yml
318
319 # database config
320 cp config/database.yml.example config/database.yml
321 echo ""
322 echo "Database (MySQL) username/password needs to be set up. The database user"
323 echo "needs rights to create a new database for this environment. You either"
324 echo "set this information up later or do it now."
325 echo ""
326 echo -n "Would you like to set up the database information now? (Y/n) "
327 read yesorno
328 if [ "$yesorno" != "Y" ]; then
329 # get database info
330 echo -n "DB: Please type database username? "
331 read dbusername
332 echo -n "DB: Please type database password? "
333 read dbpassword
334 if [ -z "$dbusername" ] || [ -z "$dbpassword" ]; then
335 # one or both values empty - skip
336 skip_database_setup
337 dbconfigured=false
338 else
339 # save values
340 replacestr="username: \"$dbusername\""
341 sed -i "s/username: \"root\"/$(echo $replacestr | sed -e 's/[\/&]/\\&/g')/g" config/database.yml
342 replacestr="password: \"$dbpassword\""
343 sed -i "s/password: \"\"/$(echo $replacestr | sed -e 's/[\/&]/\\&/g')/g" config/database.yml
344
345 # TODO: ask if user would like these to be saved in .diaspora folder for later use
346
347 # set db name to unique, so we can set up multiple envs
348 # TODO: add random number
349 sed -i "s/diaspora_development/diaspora_$1/g" config/database.yml
350 dbconfigured=true
351 fi
352 else
353 skip_database_setup
354 dbconfigured=false
355 fi
356
357 # Some generic conf variables
358 set_config "SETTINGS_POD_NAME" "Diaspora* $1"
359 set_config "SETTINGS_ENABLE_REGISTRATIONS" "true"
360
361 # some fixes to get D* running without a config file, can be removed after this is fixed:
362 # https://github.com/diaspora/diaspora/issues/3661
363 # we don't do these via set_config because it would append ENVIRONMENT_
364 echo "export HEROKU=true" >> .diasporactrlrc
365 echo "export SECRET_TOKEN=58c7770115469e64ce3ff1f802cefc5e77d41694e8f64cd5408ab6b1a764babe0f9b8ae6e0a81d6b" >> .diasporactrlrc
366 cp config/diaspora.yml.example config/diaspora.yml
367
368 # Run DB stuff if DB config was done
369 if [ "$dbconfigured" = "true" ]; then
370 source .diasporactrlrc
371 run_db_init "development"
372 else
373 echo ""
374 echo "DB has not been set up since we do not have credentials."
375 echo "Please edit config/database.yml and once done run the following:"
376 echo "diasporactrl setup database development"
377 echo ""
378 fi
379
380 echo ""
381 echo "Environment $1 in `pwd` has been created!"
382 echo "For developer guidelines, please make sure to read:"
383 echo "https://github.com/diaspora/diaspora/wiki/Git-Workflow"
384 echo ""
385
386 print_startup_instructions
387}
388
123case "$1" in389case "$1" in
124 install)390 install)
125 case "$2" in391 case "$2" in
@@ -133,6 +399,12 @@
133 echo ""399 echo ""
134 read oktocontinue400 read oktocontinue
135 username=`whoami`401 username=`whoami`
402
403 # create home .diaspora dir
404 if [ ! -d "$HOME/.diaspora" ]; then
405 mkdir $HOME/.diaspora
406 fi
407
136 else408 else
137 # we are root, let's take a guess or ask user409 # we are root, let's take a guess or ask user
138 echo "Guessing which user to install RVM to.."410 echo "Guessing which user to install RVM to.."
@@ -142,6 +414,12 @@
142 if [ -d "/etc/diaspora" ] && [ ! -e "/etc/diaspora/.diaspora_user" ]; then414 if [ -d "/etc/diaspora" ] && [ ! -e "/etc/diaspora/.diaspora_user" ]; then
143 echo $username > /etc/diaspora/.diaspora_user415 echo $username > /etc/diaspora/.diaspora_user
144 fi416 fi
417
418 # also create home .diaspora dir
419 if [ ! -d "/home/$username/.diaspora" ]; then
420 mkdir /home/$username/.diaspora
421 chown $username /home/$username/.diaspora
422 fi
145 fi423 fi
146 424
147 if [ -n "$username" ]; then425 if [ -n "$username" ]; then
@@ -159,13 +437,9 @@
159 ;;437 ;;
160 438
161 *)439 *)
162 echo "Unknown install argument"440 print_usage
163 exit 1
164
165 ;;441 ;;
166
167 esac442 esac
168
169 ;;443 ;;
170444
171 remove)445 remove)
@@ -198,18 +472,125 @@
198 ;;472 ;;
199 473
200 *)474 *)
201 echo "Unknown remove argument"475 print_usage
476 ;;
477 esac
478 ;;
479
480 setup)
481 case "$2" in
482 develop)
483
484 if [ -z $3 ]; then
485 echo "Please supply a name for development environment, for example:"
486 echo "diasporactrl setup develop mydevenv"
487 exit 1
488 fi
489
490 echo "Checking for Diaspora* system user information..."
491 get_diaspora_user
492
493 if [ -n "$username" ]; then
494 echo "Diaspora* system user is: $username"
495 else
496 echo "No Diaspora* system user found!"
497 echo "Did RVM and dependency installation go ok? Try this:"
498 echo "diasporactrl install rvm"
499 exit 1
500 fi
501
502 # no point in supporting creation of dev environments for other users
503 if [ `whoami` != "$username" ]; then
504 echo "Please set up development environment by running as the Diaspora* system user"
505 echo "If you want to set one up for this username (`whoami`), run:"
506 echo "diasporactrl install rvm"
507 exit 1
508 fi
509
510 activate_rvm $username
511 create_dev_environment $3
512 ;;
513
514 stable)
515 echo "Not supported yet! Please do manual setup using these instructions:"
516 echo "https://github.com/diaspora/diaspora/wiki/Notes-on-Installing-and-Running-Diaspora"
202 exit 1517 exit 1
518 ;;
519
520 database)
521 get_diaspora_user
203 522
204 ;;523 if [ -n "$username" ]; then
205524 echo "Diaspora* system user is: $username"
525 else
526 echo "No Diaspora* system user found!"
527 exit 1
528 fi
529 activate_rvm $username
530 source .diasporactrlrc
531 run_db_init $3
532 print_startup_instructions
533 ;;
534
535 *)
536 print_usage
537 ;;
206 esac538 esac
207 539 ;;
540
541 start)
542 if [ ! -e .diasporactrlrc ]; then
543 echo ""
544 echo "Not in a Diaspora* environment folder!"
545 echo "tip: .diasporactrlrc missing, it is created by setting an"
546 echo "environment using the command:"
547 echo "diasporactrl setup develop mydevenv"
548 echo ""
549 exit 1
550 fi
551
552 # load env variables
553 source .diasporactrlrc
554
555 # start in background
556 script/server >> diasporactrl.log 2>&1 &
557 echo $! >> "diasporactrl.pid"
558
559 echo ""
560 echo "Started server!"
561 echo "You can check the log file 'diasporactrl.log' and after approx"
562 echo "30 seconds access the environment at http://127.0.0.1:3000"
563 echo ""
564 echo "To stop the server, type:"
565 echo "diasporactrl stop"
566 echo ""
567 ;;
568
569 stop)
570 if [ ! -e diasporactrl.pid ]; then
571 echo ""
572 echo "Can not find diasporactrl.pid file. Has an environment"
573 echo "been started in this folder?"
574 echo ""
575 exit 1
576 fi
577
578 # start in background
579 pid2kill=`cat diasporactrl.pid`
580 kill $pid2kill
581 #TODO fix below - currently kills all running instances :)
582 #but then currently only one can be started since port is always 3000
583 kill $(ps aux | grep '[d]iaspora' | awk '{print $2}')
584
585 rm diasporactrl.pid
586
587 echo ""
588 echo "Server has been stopped!"
589 echo ""
208 ;;590 ;;
209591
210 *)592 *)
211 echo "Unknown argument"593 print_usage
212 exit 1
213 ;;594 ;;
214esac595esac
215596

Subscribers

People subscribed via source and target branches

to all changes: