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", "--no-install-recommends",
44
"apache2", "libapache2-mod-python",
45
"libapache2-svn", "python2.6", "python-configobj",
46
"python-docutils", "python-epydoc", "python-formencode",
47
"python-genshi", "python-psycopg2", "python-svn", "python-storm",
48
"libjs-jquery", "libjs-codemirror", "postgresql", "subversion",
49
"debootstrap", "rsync", "build-essential"])
51
logging.info("Building.")
52
subprocess.check_call(["./setup.py", "build"])
53
subprocess.check_call(["sudo", "./setup.py", "install"])
56
# Set up the database.
58
logging.info("Creating %s as PostgreSQL superuser." % user)
59
subprocess.check_call(["sudo", "-u", "postgres", "createuser", "-s", user])
61
# We installed psycopg2 above, so we can import it now.
63
import psycopg2.extensions
65
logging.info("Connecting to PostgreSQL.")
66
conn = psycopg2.connect(database='postgres')
67
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
68
cursor = conn.cursor()
70
logging.info("Creating ivle as normal PostgreSQL user.")
71
ivle_password = hashlib.md5(uuid.uuid4().bytes).hexdigest()
72
cursor.execute("CREATE ROLE ivle PASSWORD '%s' LOGIN" % ivle_password)
74
logging.info("Creating IVLE database.")
75
cursor.execute("CREATE DATABASE ivle OWNER ivle")
77
logging.info("Connecting to IVLE database.")
78
ivlesuconn = psycopg2.connect(database='ivle')
79
ivlesuconn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
80
ivlesucursor = ivlesuconn.cursor()
82
logging.info("Creating language plpgsql.")
83
ivlesucursor.execute("CREATE LANGUAGE plpgsql")
85
logging.info("Connecting to IVLE database as new user.")
86
ivleconn = psycopg2.connect(
87
host='localhost', database='ivle', user='ivle', password=ivle_password)
88
ivleconn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
89
ivlecursor = ivleconn.cursor()
90
logging.info("Populating database with schema.")
91
schemafile = open("userdb/users.sql")
92
ivlecursor.execute(schemafile.read())
94
suite = subprocess.Popen(
95
["lsb_release", "-c", "-s"], stdout=subprocess.PIPE).communicate()[0][:-1]
97
# Set the filesystem and config up.
98
logging.info("Configuring IVLE.")
99
subprocess.check_call([
100
"sudo", "ivle-config",
101
"--database/username", "ivle",
102
"--database/password", ivle_password,
103
"--jail/devmode", "True",
104
"--jail/suite", suite,
107
logging.info("Creating data hierarchy.")
108
subprocess.check_call(["sudo", "ivle-createdatadirs"])
112
logging.info("Configuring Apache.")
113
subprocess.check_call(
114
["sudo", "cp", "examples/config/apache.conf",
115
"/etc/apache2/sites-available/ivle"])
116
subprocess.check_call(
117
["sudo", "a2ensite", "ivle"])
119
subprocess.check_call(
120
["sudo", "cp", "examples/config/apache-svn.conf",
121
"/etc/apache2/sites-available/ivle-svn"])
122
subprocess.check_call(
123
["sudo", "a2ensite", "ivle-svn"])
125
subprocess.check_call(
126
["sudo", "/etc/init.d/apache2", "reload"])
129
# Configure name resolution
130
logging.info("Configuring /etc/hosts.")
131
hosts_tee = subprocess.Popen(
132
["sudo", "tee", "-a", "/etc/hosts"], stdin=subprocess.PIPE)
133
hosts_tee.communicate(
134
"127.0.1.1 ivle.localhost public.ivle.localhost svn.ivle.localhost")
137
# Configure usrmgt-server init script.
138
logging.info("Installing usrmgt-server.")
139
subprocess.check_call(
140
["sudo", "cp", "examples/config/usrmgt-server.init",
141
"/etc/init.d/ivle-usrmgt-server"])
142
subprocess.check_call(["sudo", "/etc/init.d/ivle-usrmgt-server", "start"])
143
subprocess.check_call(
144
["sudo", "update-rc.d", "ivle-usrmgt-server", "defaults", "99"])