2
# IVLE - Informatics Virtual Learning Environment
3
# Copyright (C) 2007-2009 The University of Melbourne
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.
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.
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
19
"""Script to install an IVLE development environment."""
27
if len(sys.argv) == 2:
29
logging.info("Installing IVLE development environment for %s" % user)
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.
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",
50
logging.info("Building.")
51
subprocess.check_call(["./setup.py", "build"])
52
subprocess.check_call(["sudo", "./setup.py", "install"])
55
# Set up the database.
57
logging.info("Creating %s as PostgreSQL superuser." % user)
58
subprocess.check_call(["sudo", "-u", "postgres", "createuser", "-s", user])
60
# We installed psycopg2 above, so we can import it now.
62
import psycopg2.extensions
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()
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)
73
logging.info("Creating IVLE database.")
74
cursor.execute("CREATE DATABASE ivle OWNER ivle")
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()
81
logging.info("Creating language plpgsql.")
82
ivlesucursor.execute("CREATE LANGUAGE plpgsql")
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())
93
suite = subprocess.Popen(
94
["lsb_release", "-c", "-s"], stdout=subprocess.PIPE).communicate()[0][:-1]
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,
106
logging.info("Creating data hierarchy.")
107
subprocess.check_call(["sudo", "ivle-createdatadirs"])
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"])
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"])
124
subprocess.check_call(
125
["sudo", "/etc/init.d/apache2", "reload"])
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")
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"])