~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-dev-setup

  • Committer: William Grant
  • Date: 2010-02-11 05:27:24 UTC
  • Revision ID: grantw@unimelb.edu.au-20100211052724-171m0779yqzn1y1x
Add a setup.cfg with nose settings. You can now run the suite with 'IVLECONF=. nosetests'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# IVLE - Informatics Virtual Learning Environment
 
3
# Copyright (C) 2007-2009 The University of Melbourne
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
"""Script to install an IVLE development environment."""
 
20
 
 
21
import hashlib
 
22
import logging
 
23
import subprocess
 
24
import sys
 
25
import uuid
 
26
 
 
27
if len(sys.argv) == 2:
 
28
    user = sys.argv[1]
 
29
    logging.info("Installing IVLE development environment for %s" % user)
 
30
else:
 
31
    print >> sys.stderr, \
 
32
"""This script will install an IVLE development environment on a system
 
33
running Ubuntu 9.04 or later. It will fiddle with /etc/hosts, create
 
34
PostgreSQL users and databases, add some Apache virtual hosts, create
 
35
directories in /var/lib/ivle, copy a Python package into your PYTHONPATH,
 
36
and possibly other things too. If you really want all that to happen,
 
37
rerun this script with your username as an argument.
 
38
"""
 
39
    sys.exit(1)
 
40
 
 
41
logging.info("Installing dependencies.")
 
42
subprocess.check_call([
 
43
    "sudo", "apt-get", "install", "apache2", "libapache2-mod-python",
 
44
    "libapache2-svn", "python2.6", "python-cjson", "python-configobj",
 
45
    "python-docutils", "python-epydoc", "python-formencode",
 
46
    "python-genshi", "python-psycopg2", "python-svn", "python-storm",
 
47
    "libjs-jquery", "postgresql", "subversion", "debootstrap", "rsync",
 
48
    "build-essential"])
 
49
 
 
50
logging.info("Building.")
 
51
subprocess.check_call(["./setup.py", "build"])
 
52
subprocess.check_call(["sudo", "./setup.py", "install"])
 
53
 
 
54
 
 
55
# Set up the database.
 
56
 
 
57
logging.info("Creating %s as PostgreSQL superuser." % user)
 
58
subprocess.check_call(["sudo", "-u", "postgres", "createuser", "-s", user])
 
59
 
 
60
# We installed psycopg2 above, so we can import it now.
 
61
import psycopg2
 
62
import psycopg2.extensions
 
63
 
 
64
logging.info("Connecting to PostgreSQL.")
 
65
conn = psycopg2.connect(database='postgres')
 
66
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
 
67
cursor = conn.cursor()
 
68
 
 
69
logging.info("Creating ivle as normal PostgreSQL user.")
 
70
ivle_password = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
71
cursor.execute("CREATE ROLE ivle PASSWORD '%s' LOGIN" % ivle_password)
 
72
 
 
73
logging.info("Creating IVLE database.")
 
74
cursor.execute("CREATE DATABASE ivle OWNER ivle")
 
75
 
 
76
logging.info("Connecting to IVLE database.")
 
77
ivlesuconn = psycopg2.connect(database='ivle')
 
78
ivlesuconn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
 
79
ivlesucursor = ivlesuconn.cursor()
 
80
 
 
81
logging.info("Creating language plpgsql.")
 
82
ivlesucursor.execute("CREATE LANGUAGE plpgsql")
 
83
 
 
84
logging.info("Connecting to IVLE database as new user.")
 
85
ivleconn = psycopg2.connect(
 
86
    host='localhost', database='ivle', user='ivle', password=ivle_password)
 
87
ivleconn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
 
88
ivlecursor = ivleconn.cursor()
 
89
logging.info("Populating database with schema.")
 
90
schemafile = open("userdb/users.sql")
 
91
ivlecursor.execute(schemafile.read())
 
92
 
 
93
suite = subprocess.Popen(
 
94
    ["lsb_release", "-c", "-s"], stdout=subprocess.PIPE).communicate()[0][:-1]
 
95
 
 
96
# Set the filesystem and config up.
 
97
logging.info("Configuring IVLE.")
 
98
subprocess.check_call([
 
99
    "sudo", "ivle-config",
 
100
    "--database/username", "ivle",
 
101
    "--database/password", ivle_password,
 
102
    "--jail/devmode", "True",
 
103
    "--jail/suite", suite,
 
104
    ])
 
105
 
 
106
logging.info("Creating data hierarchy.")
 
107
subprocess.check_call(["sudo", "ivle-createdatadirs"])
 
108
 
 
109
 
 
110
# Configure Apache
 
111
logging.info("Configuring Apache.")
 
112
subprocess.check_call(
 
113
    ["sudo", "cp", "examples/config/apache.conf",
 
114
     "/etc/apache2/sites-available/ivle"])
 
115
subprocess.check_call(
 
116
    ["sudo", "a2ensite", "ivle"])
 
117
 
 
118
subprocess.check_call(
 
119
    ["sudo", "cp", "examples/config/apache-svn.conf",
 
120
     "/etc/apache2/sites-available/ivle-svn"])
 
121
subprocess.check_call(
 
122
    ["sudo", "a2ensite", "ivle-svn"])
 
123
 
 
124
subprocess.check_call(
 
125
    ["sudo", "/etc/init.d/apache2", "reload"])
 
126
 
 
127
 
 
128
# Configure name resolution
 
129
logging.info("Configuring /etc/hosts.")
 
130
hosts_tee = subprocess.Popen(
 
131
    ["sudo", "tee", "-a", "/etc/hosts"], stdin=subprocess.PIPE)
 
132
hosts_tee.communicate(
 
133
    "127.0.1.1 ivle.localhost public.ivle.localhost svn.ivle.localhost")
 
134
 
 
135
 
 
136
# Configure usrmgt-server init script.
 
137
logging.info("Installing usrmgt-server.")
 
138
subprocess.check_call(
 
139
    ["sudo", "cp", "examples/config/usrmgt-server.init",
 
140
     "/etc/init.d/ivle-usrmgt-server"])
 
141
subprocess.check_call(["sudo", "/etc/init.d/ivle-usrmgt-server", "start"])
 
142
subprocess.check_call(
 
143
    ["sudo", "update-rc.d", "ivle-usrmgt-server", "defaults", "99"])