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