[995] | 1 | #!/usr/bin/perl |
---|
| 2 | use strict; |
---|
| 3 | use lib '/mit/scripts/deploy/bin'; |
---|
| 4 | use onserver; |
---|
| 5 | |
---|
| 6 | setup(); |
---|
| 7 | |
---|
| 8 | print "\nEnter the code name for your project (a valid Python package name).\n"; |
---|
| 9 | print "Do not use 'django' or the name of any other Python library.\n"; |
---|
| 10 | print "Project name: "; |
---|
| 11 | my $name = <STDIN>; |
---|
| 12 | chomp $name; |
---|
| 13 | |
---|
| 14 | open FASTCGI, ">index.fcgi"; |
---|
| 15 | print FASTCGI <<EOF; |
---|
| 16 | #!/usr/bin/env python |
---|
| 17 | import sys, os |
---|
| 18 | sys.path.insert(0, "/mit/$USER/Scripts/django") |
---|
| 19 | os.chdir("/mit/$USER/Scripts/django/$name") |
---|
| 20 | os.environ['DJANGO_SETTINGS_MODULE'] = "$name.settings" |
---|
| 21 | |
---|
| 22 | from django.core.servers.fastcgi import runfastcgi |
---|
| 23 | runfastcgi(method="threaded", daemonize="false") |
---|
| 24 | EOF |
---|
| 25 | close FASTCGI; |
---|
| 26 | chmod 0755, "index.fcgi"; |
---|
| 27 | |
---|
| 28 | open HTACCESS, ">.htaccess"; |
---|
| 29 | print HTACCESS <<EOF; |
---|
| 30 | RewriteEngine On |
---|
| 31 | RewriteCond %{REQUEST_FILENAME} !-f |
---|
| 32 | RewriteCond %{REQUEST_FILENAME} !-d |
---|
[1036] | 33 | RewriteRule ^(.*)\$ index.fcgi/\$1 [QSA,L] |
---|
[995] | 34 | EOF |
---|
| 35 | close HTACCESS; |
---|
| 36 | chmod 0777, ".htaccess"; |
---|
| 37 | |
---|
| 38 | chdir "/mit/$USER/Scripts/django/"; |
---|
| 39 | system qw{django-admin.py startproject}, $name; |
---|
| 40 | chdir "$name"; |
---|
| 41 | |
---|
| 42 | open SETTINGS, "settings.py"; |
---|
[1038] | 43 | open NEWSETTINGS, ">settings.py.new"; |
---|
[995] | 44 | while (<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 | } |
---|
| 74 | close NEWSETTINGS; |
---|
| 75 | close SETTNGS; |
---|
| 76 | rename "settings.py.new", "settings.py"; |
---|
| 77 | |
---|
[1042] | 78 | open URLS, "urls.py"; |
---|
| 79 | open NEWURLS, ">urls.py.new"; |
---|
| 80 | while (<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 | } |
---|
| 91 | close NEWURLS; |
---|
| 92 | close URLS; |
---|
| 93 | rename "urls.py.new", "urls.py"; |
---|
| 94 | |
---|
| 95 | print "Initializing your project's SQL database schema...\n"; |
---|
| 96 | system qw{./manage.py syncdb --noinput}; |
---|
| 97 | print "...done\n"; |
---|
| 98 | |
---|
| 99 | print "Creating your superuser account... "; |
---|
| 100 | system qw{./manage.py createsuperuser --username}, $admin_username, "--email", $email, "--noinput"; |
---|
| 101 | print "done\n"; |
---|
| 102 | print "Setting your superuser password... "; |
---|
| 103 | system qw{mysql -D}, "$USER+$addrlast", "-e", "UPDATE auth_user SET password=MD5(\'$admin_password\') WHERE username=\'$admin_username\'"; |
---|
| 104 | print "done\n"; |
---|
| 105 | |
---|
[1044] | 106 | print "\nDjango has been installed. The setup is roughly what's described\n" |
---|
| 107 | print "in the shared-hosting section of\n" |
---|
| 108 | print " http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/\n" |
---|
| 109 | print "We've also enabled the admin app. You can start from the 'Creating\n" |
---|
| 110 | print "models' step of the Django tutorial:\n" |
---|
| 111 | print " http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3\n\n" |
---|
| 112 | print "Your project is located in:\n"; |
---|
[995] | 113 | print " /mit/$USER/Scripts/django/$name/\n"; |
---|
| 114 | print "To access manage.py, run 'ssh -k $USER\@scripts' and cd to the above directory.\n\n"; |
---|
| 115 | print "When you edit your code, run the command\n"; |
---|
| 116 | print " touch /mit/$USER/web_scripts/$addrend/index.fcgi\n"; |
---|
| 117 | print "before testing, to cause your site to reload the new code.\n"; |
---|
| 118 | press_enter; |
---|
| 119 | |
---|
| 120 | exit 0; |
---|