source: locker/deploy/bin/django @ 1101

Last change on this file since 1101 was 1046, checked in by mitchb, 16 years ago
Dammit, Geoff, test things. Fix django autoinstaller again.
  • Property svn:executable set to *
File size: 3.6 KB
RevLine 
[995]1#!/usr/bin/perl
2use strict;
3use lib '/mit/scripts/deploy/bin';
4use onserver;
5
6setup();
7
8print "\nEnter the code name for your project (a valid Python package name).\n";
9print "Do not use 'django' or the name of any other Python library.\n";
10print "Project name: ";
11my $name = <STDIN>;
12chomp $name;
13
14open FASTCGI, ">index.fcgi";
15print FASTCGI <<EOF;
16#!/usr/bin/env python
17import sys, os
18sys.path.insert(0, "/mit/$USER/Scripts/django")
19os.chdir("/mit/$USER/Scripts/django/$name")
20os.environ['DJANGO_SETTINGS_MODULE'] = "$name.settings"
21
22from django.core.servers.fastcgi import runfastcgi
23runfastcgi(method="threaded", daemonize="false")
24EOF
25close FASTCGI;
26chmod 0755, "index.fcgi";
27
28open HTACCESS, ">.htaccess";
29print HTACCESS <<EOF;
30RewriteEngine On
31RewriteCond %{REQUEST_FILENAME} !-f
32RewriteCond %{REQUEST_FILENAME} !-d
[1036]33RewriteRule ^(.*)\$ index.fcgi/\$1 [QSA,L]
[995]34EOF
35close HTACCESS;
36chmod 0777, ".htaccess";
37
38chdir "/mit/$USER/Scripts/django/";
39system qw{django-admin.py startproject}, $name;
40chdir "$name";
41
42open SETTINGS, "settings.py";
[1038]43open NEWSETTINGS, ">settings.py.new";
[995]44while (<SETTINGS>) {
45  chomp;
46  if (/Your Name/) {
[1038]47    $_ = "    ('$USER', '$email'),";
[995]48  } elsif (/^DATABASE_ENGINE/) {
[1038]49    $_ = "DATABASE_ENGINE = 'mysql'";
[995]50  } elsif  (/^DATABASE_NAME/) {
[1038]51    $_ = "DATABASE_NAME = '$sqldb'";
[995]52  } elsif (/^DATABASE_USER/) {
[1038]53    $_ = "DATABASE_USER = '$sqluser'";
[995]54  } elsif (/^DATABASE_PASSWORD/) {
[1038]55    $_ = "DATABASE_PASSWORD = '$sqlpass'";
[995]56  } elsif (/^DATABASE_HOST/) {
[1038]57    $_ = "DATABASE_HOST = '$sqlhost'";
[995]58  } elsif (/Chicago/) {
59    $_ =~ s/Chicago/New_York/;
[1042]60  } elsif (/^ADMIN_MEDIA_PREFIX/) {
61    $_ = "ADMIN_MEDIA_PREFIX = '/__scripts/django/media/'";
62  } elsif (/^INSTALLED_APPS/) {
63    print NEWSETTINGS "$_\n";
64    while (<SETTINGS>) {
65      if (/^\)/) {
66        print NEWSETTINGS "    'django.contrib.admin',\n";
67        print NEWSETTINGS "    'django.contrib.admindocs',\n";
68      }
69      print NEWSETTINGS $_;
70    }
[995]71  }
[1038]72  print NEWSETTINGS "$_\n";
[995]73}
74close NEWSETTINGS;
75close SETTNGS;
76rename "settings.py.new", "settings.py";
77
[1042]78open URLS, "urls.py";
79open NEWURLS, ">urls.py.new";
80while (<URLS>) {
81  chomp;
82  if (/^#.*from django\.contrib import admin/) {
83    $_ =~ s/^# *//;
84  } elsif (/^#.*admin.autodiscover/) {
85    $_ =~ s/^# *//;
86  } elsif (/^ *# *\(r\'\^admin\//) {
87    $_ =~ s/# *//;
88  }
89  print NEWURLS "$_\n";
90}
91close NEWURLS;
92close URLS;
93rename "urls.py.new", "urls.py";
94
95print "Initializing your project's SQL database schema...\n";
96system qw{./manage.py syncdb --noinput};
97print "...done\n";
98
99print "Creating your superuser account... ";
100system qw{./manage.py createsuperuser --username}, $admin_username, "--email", $email, "--noinput";
101print "done\n";
102print "Setting your superuser password... ";
103system qw{mysql -D}, "$USER+$addrlast", "-e", "UPDATE auth_user SET password=MD5(\'$admin_password\') WHERE username=\'$admin_username\'";
104print "done\n";
105
[1046]106print "\nDjango has been installed. The setup is roughly what's described\n";
107print "in the shared-hosting section of\n";
108print "  http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/\n";
109print "We've also enabled the admin app. You can start from the 'Creating\n";
110print "models' step of the Django tutorial:\n";
111print "  http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3\n\n";
[1044]112print "Your project is located in:\n";
[995]113print "  /mit/$USER/Scripts/django/$name/\n";
114print "To access manage.py, run 'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
115print "When you edit your code, run the command\n";
116print "  touch /mit/$USER/web_scripts/$addrend/index.fcgi\n";
117print "before testing, to cause your site to reload the new code.\n";
118press_enter;
119
120exit 0;
Note: See TracBrowser for help on using the repository browser.