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

Last change on this file since 1477 was 1477, checked in by mitchb, 12 years ago
* Initial commit of TG autoinstaller, for some reason. (from trunk@1476, 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.3 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
135system(qw(sed -ri),'s/^sql(alchemy|object)\.dburi(.*)$/#sql\1.dburi\2\nsqlalchemy.dburi="mysql:\/\/' . uri_escape($sqluser) . ":" . uri_escape($sqlpass) . "\@$sqlhost\\/$sqldb\"/","$name/dev.cfg", "$name/sample-prod.cfg") == 0 or die "sed db failed!";
136system(qw(sed -ri),'s/^#? *autoreload\.on.*$/autoreload.on = False # breaks the scripts flup setup/',"$name/dev.cfg") == 0 or die "sed autoreload failed!";
137my $addrendescsl = $addrend;
138$addrendescsl =~ s|/|\\/|g;
139# Obviated by a TurboGears upgrade
140#system(qw(sed -ri),'s/^(\[global\] *)$/\1\nserver.webpath = "\/'."$addrendescsl".'"/',"$name/dev.cfg") == 0 or die "sed webpath failed!";
141if ($orm eq "elixir" or $orm eq "sqlalchemy") {
142    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!";
143}
144
145# Make logdir
146system('mkdir','-p',"$name/log");
147
148# Cert patch
149if ($certpatch) {
150    # comment out the password = line in model
151    system(qw(sed -ri),
152           's/^(.*password.*)$/#\1 -- we use certs, not passwords/',
153           "$name/$pack/model.py") == 0 or die "sed model for certs failed!";
154   
155    # Stick cert.py in
156    system('cp',"/mit/scripts/deploy$scriptsdev/turbogears-certs/certs.py",
157           "$name/$pack/") == 0 or die "cp certs.py failed!";
158   
159    # Add the certness to controllers.py
160    system(qw(sed -ri),
161           's/^(from cherrypy.*)$/\1\nfrom '."$pack".'.certs import with_mit_certs/',
162           "$name/$pack/controllers.py") == 0 or die "sed controllers import for certs failed!";
163    system(qw(sed -ri),
164           's/^(\s+)(def login.*)$/\1@with_mit_certs\n\1\2',
165           "$name/$pack/model.py") == 0 or die "sed model for certs failed!";
166    #-! replace login body
167    #-! replace logout body
168    #-! replace login.kid
169}
170
171exit 0;
Note: See TracBrowser for help on using the repository browser.