source: branches/locker-dev/locker/deploy/bin/turbogears @ 1486

Last change on this file since 1486 was 1478, checked in by mitchb, 15 years ago
* Don't put SQL passwords in command-line arguments. * When using sqlalchemy, use ~/.my.cnf instead of hardcoding the SQL password. (originally from xavid)
  • Property svn:executable set to *
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/fc11-dev/locker/deploy/bin/turbogears1121-1258
File size: 5.8 KB
Line 
1#!/usr/bin/perl
2use strict;
3use FindBin qw($Bin);
4use lib $Bin;
5use onserver;
6use Cwd;
7use File::Path;
8use URI::Escape;
9use DBI;
10use Config::IniFiles;
11use FileHandle;
12
13setup();
14
15print "\nEnter the name of your project (the title of this TurboGears instance).\n";
16my $name;
17while (1) {
18    print "Project name: ";
19    $name=<STDIN>;
20    chomp($name);
21    if ($name =~ /^[a-zA-Z][a-zA-Z0-9_ -]+$/) {
22        last;
23    }
24    print "Invalid project name; it should start with a letter and not contain\npunctuation other than dashes or underscores.\n";
25}       
26
27# quickstart turns spaces or underscores into dashes...
28$name =~ s/[ _-]+/-/g;
29
30my $defpack=lc($name);
31$defpack =~ s/[ -]/_/g;
32$defpack =~ s/[^a-z0-9_]//g;
33if (! ($defpack =~ /^[a-zA-Z]/)) {
34    $defpack = "p$defpack";
35}
36print "\nEnter the name for your project's python package.\n";
37my $pack;
38while (1) {
39    print "Package name [${defpack}]: ";
40    $pack=<STDIN>;
41    chomp($pack);
42    if (!($pack)) {
43        $pack=$defpack;
44        last;
45    } elsif ($pack =~ /^[a-zA-Z][a-zA-Z0-9_]+$/) {
46        last;
47    }
48    print "Invalid package name; it should start with a letter and contain only letters,\nnumbers, and underscores.\n";
49}
50
51print "\nWhat ORM (Object-Relational Mapper) do you want to use with this TurboGears\ninstance?  Select from the following list:\n";
52print "1. SQLAlchemy Elixir\n";
53print "2. SQLAlchemy\n";
54print "3. SQLObject\n";
55my $orm;
56while (1) {
57    print "ORM [1]: ";
58    my $ormnum=<STDIN>;
59    chomp($ormnum);
60    if ((!$ormnum) || $ormnum == 1) {
61        $orm = "elixir";
62        last;
63    } elsif ($ormnum == 2) {
64        $orm = "sqlalchemy";
65        last;
66    } elsif ($ormnum == 3) {
67        $orm = "sqlobject";
68        last;
69    }
70    print "Please choose 1, 2, or 3.\n";
71}
72
73print "\nWhat template do you want to use with this TurboGears instance?  Select from\nthe following list:\n";
74print "1. turbogears: normal template, recommended for most projects\n";
75print "2. tgbig:  a more complex directory structure for big projects\n";
76my $templ;
77while (1) {
78    print "Template [1]: ";
79    my $templnum=<STDIN>;
80    chomp($templnum);
81    if ((!$templnum) || $templnum == 1) {
82        $templ = "turbogears";
83        last;
84    } elsif ($templnum == 2) {
85        $templ = "tgbig";
86        last;
87    }
88    print "Please choose 1, 2, or 3.\n";
89}
90
91print "\nDo you want to use Identity (usernames/passwords) in this project?\n(These would be separate from Athena usernames/passwords.)\n";
92print "1. no identity: no logins, everyone sees the same pages\n";
93print "2. standard identity: users log in with site-specific usernames and passwords\n";
94#print "3. certificates: users are identified by their MIT certificates\n";
95my $ident;
96my $certpatch=0;
97while (1) {
98    print "Identity [1]: ";
99    my $identnum=<STDIN>;
100    chomp($identnum);
101    if ((!$identnum) || $identnum == 1) {
102        $ident = "no";
103        last;
104    } elsif ($identnum == 2) {
105        $ident = "yes";
106        last;
107    } elsif ($identnum == 3) {
108        $ident = "yes";
109        $certpatch = 1;
110        last;
111    }
112}
113
114open (FLUPCONF, ">flupconfig.py");
115print FLUPCONF <<EOF;
116code_dir = "/mit/$USER/Scripts/turbogears/$name/"
117project_name = "$name"
118package_name = "$pack"
119EOF
120close (FLUPCONF);
121
122system("ln","-s","/mit/$USER/Scripts/turbogears/$name/$pack","./$pack");
123system("ln","-s","/mit/$USER/Scripts/turbogears/$name/$pack/static",
124    "./static");
125
126chdir("/mit/$USER/Scripts/turbogears/");
127print "\nRunning tg-admin quickstart...\n";
128open(QS, "|/usr/bin/tg-admin quickstart $name --package=$pack --$orm --templates=$templ")
129    or die("tg-admin quickstart failed open!");
130QS->autoflush(1);
131print QS "$ident\n" or die("tg-admin quickstart failed specify ident!");
132close(QS) or die("tg-admin quickstart failed close!");
133
134# Put in the sqldb
135if ($orm eq "sqlobject") {
136    my $uriuser = uri_escape($sqluser);
137    my $uripass = uri_escape($sqlpass);
138    foreach my $fil (("$name/dev.cfg", "$name/sample-prod.cfg"))
139    {
140        open my $in, '<', $fil or die "Can't read old file: $!";
141        open my $out, '>', "$fil.new" or die "Can't write new file: $!";
142
143        while (<$in>) {
144            s/^sqlobject\.dburi(.*)$/#sqlobject.dburi\2\nsqlobject.dburi="mysql:\/\/$uriuser:$uripass\@$sqlhost\/$sqldb"/;
145            print $out $_;
146        }
147        close $out;
148        rename "$fil.new", $fil
149            or die "Cannot rename: $!";
150    }
151} else {
152    system(qw(sed -ri),"s&^sql(alchemy|object)\.dburi(.*)\$&#sql\\1.dburi\\2\\nsql\\1.dburi=\"mysql://$sqlhost/$sqldb?read_default_file=~/.my.cnf\"&","$name/dev.cfg", "$name/sample-prod.cfg") == 0 or die "sed db failed!";
153}
154system(qw(sed -ri),'s/^#? *autoreload\.on.*$/autoreload.on = False # breaks the scripts flup setup/',"$name/dev.cfg") == 0 or die "sed autoreload failed!";
155my $addrendescsl = $addrend;
156$addrendescsl =~ s|/|\\/|g;
157# Obviated by a TurboGears upgrade
158#system(qw(sed -ri),'s/^(\[global\] *)$/\1\nserver.webpath = "\/'."$addrendescsl".'"/',"$name/dev.cfg") == 0 or die "sed webpath failed!";
159if ($orm eq "elixir" or $orm eq "sqlalchemy") {
160    system(qw(sed -ri),'s/^(\[global\] *)$/\1\nsqlalchemy.pool_recycle = 30 # Need a short timeout for sql.mit.edu/',"$name/$pack/config/app.cfg") == 0 or die "sed pool_recycle failed!";
161}
162
163# Make logdir
164system('mkdir','-p',"$name/log");
165
166# Cert patch
167if ($certpatch) {
168    # comment out the password = line in model
169    system(qw(sed -ri),
170           's/^(.*password.*)$/#\1 -- we use certs, not passwords/',
171           "$name/$pack/model.py") == 0 or die "sed model for certs failed!";
172   
173    # Stick cert.py in
174    system('cp',"/mit/scripts/deploy$scriptsdev/turbogears-certs/certs.py",
175           "$name/$pack/") == 0 or die "cp certs.py failed!";
176   
177    # Add the certness to controllers.py
178    system(qw(sed -ri),
179           's/^(from cherrypy.*)$/\1\nfrom '."$pack".'.certs import with_mit_certs/',
180           "$name/$pack/controllers.py") == 0 or die "sed controllers import for certs failed!";
181    system(qw(sed -ri),
182           's/^(\s+)(def login.*)$/\1@with_mit_certs\n\1\2',
183           "$name/$pack/model.py") == 0 or die "sed model for certs failed!";
184    #-! replace login body
185    #-! replace logout body
186    #-! replace login.kid
187}
188
189exit 0;
Note: See TracBrowser for help on using the repository browser.