source: branches/locker-dev/locker/deploy/bin/rails @ 1295

Last change on this file since 1295 was 1295, checked in by mitchb, 15 years ago
Ruby on Rails autoinstaller! (but I...)
  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[1295]1#!/usr/bin/perl
2use strict;
3use FindBin qw($Bin);
4use lib $Bin;
5use onserver;
6use Tie::File;
7
8setup();
9
10sub make_db {
11    my($type) = @_;
12    print "\nCreating $type SQL database for $sname...\n";
13    open GETPWD, '-|', "/mit/scripts/sql/bin$scriptsdev/get-password";
14    ($sqlhost, $sqluser, $sqlpass) = split(/\s/, <GETPWD>);
15    close GETPWD;
16    open SQLDB, '-|', "/mit/scripts/sql/bin$scriptsdev/get-next-database", "${addrlast}_${type}";
17    $sqldb = <SQLDB>;
18    close SQLDB;
19    open SQLDB, '-|', "/mit/scripts/sql/bin$scriptsdev/create-database", $sqldb;
20    $sqldb = <SQLDB>;
21    close SQLDB;
22    if($sqldb eq "") {
23        print "\nERROR:\n";
24        print "Your SQL account failed to create a SQL database.\n";
25        print "You should log in at http://sql.mit.edu to check whether\n";
26        print "your SQL account is at its database limit or its storage limit.\n";
27        print "If you cannot determine the cause of the problem, please\n";
28        print "feel free to contact sql\@mit.edu for assistance.\n";
29        open FAILED, ">.failed";
30        close FAILED;
31        exit 1;
32    }
33    return $sqldb;
34}
35
36my $dev_db = make_db("development");
37my $test_db = make_db("test");
38my $prod_db = make_db("production");
39
40system qw{rails -D -d mysql .};
41
42open PUBLIC_HTACCESS, ">public/.htaccess";
43print PUBLIC_HTACCESS <<EOF;
44# General Apache options
45Options +FollowSymLinks +ExecCGI
46
47# If you don't want Rails to look in certain directories,
48# use the following rewrite rules so that Apache won't rewrite certain requests
49#
50# Example:
51#   RewriteCond %{REQUEST_URI} ^/notrails.*
52#   RewriteRule .* - [L]
53
54# Redirect all requests not available on the filesystem to Rails
55# By default the cgi dispatcher is used which is very slow
56#
57# For better performance replace the dispatcher with the fastcgi one
58#
59# Example:
60#   RewriteRule ^(.*)\$ dispatch.fcgi [QSA,L]
61RewriteEngine On
62
63# If your Rails application is accessed via an Alias directive,
64# then you MUST also set the RewriteBase in this htaccess file.
65#
66# Example:
67#   Alias /myrailsapp /path/to/myrailsapp/public
68#   RewriteBase /myrailsapp
69
70RewriteRule ^\$ index.html [QSA]
71RewriteRule ^([^.]+)\$ \$1.html [QSA]
72RewriteCond %{REQUEST_FILENAME} !-f
73RewriteRule ^(.*)\$ dispatch.fcgi [QSA,L]
74
75# In case Rails experiences terminal errors
76# Instead of displaying this message you can supply a file here which will be rendered instead
77#
78# Example:
79#   ErrorDocument 500 /500.html
80
81ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
82
83RewriteBase /$addrend/public/
84EOF
85
86open HTACCESS, ">.htaccess";
87print HTACCESS <<EOF;
88RewriteEngine On
89RewriteRule ^(.*)\$ public/\$1 [QSA,L]
90RewriteBase /$addrend/
91EOF
92
93tie my @railsenv, 'Tie::File', 'config/environment.rb';
94unshift @railsenv, "ENV['RAILS_RELATIVE_URL_ROOT'] = \"/$addrend\"";
95untie @railsenv;
96
97tie my @railsdb, 'Tie::File', 'config/database.yml';
98for (@railsdb) {
99    s/username:.*$/username: $sqluser/;
100    s/password:.*$/password: $sqlpass/;
101    s/host:.*$/host: $sqlhost/;
102    s/database:.*_development.*/database: $dev_db/;
103    s/database:.*_test.*/database: $test_db/;
104    s/database:.*_production.*/database: $prod_db/;
105}
106untie @railsdb;
107
108exit 0;
Note: See TracBrowser for help on using the repository browser.