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

« back to all changes in this revision

Viewing changes to bin/ivle-dev-setup

  • Committer: William Grant
  • Date: 2009-06-24 10:47:38 UTC
  • mfrom: (1288 trunk)
  • mto: (1281.1.8 aufsless)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: grantw@unimelb.edu.au-20090624104738-ezgfy17mjzwz09i3
MergeĀ fromĀ trunk.

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", "--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"])
50
 
 
51
 
logging.info("Building.")
52
 
subprocess.check_call(["./setup.py", "build"])
53
 
subprocess.check_call(["sudo", "./setup.py", "install"])
54
 
 
55
 
 
56
 
# Set up the database.
57
 
 
58
 
logging.info("Creating %s as PostgreSQL superuser." % user)
59
 
subprocess.check_call(["sudo", "-u", "postgres", "createuser", "-s", user])
60
 
 
61
 
# We installed psycopg2 above, so we can import it now.
62
 
import psycopg2
63
 
import psycopg2.extensions
64
 
 
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()
69
 
 
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)
73
 
 
74
 
logging.info("Creating IVLE database.")
75
 
cursor.execute("CREATE DATABASE ivle OWNER ivle")
76
 
 
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()
81
 
 
82
 
logging.info("Creating language plpgsql.")
83
 
ivlesucursor.execute("CREATE LANGUAGE plpgsql")
84
 
 
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())
93
 
 
94
 
suite = subprocess.Popen(
95
 
    ["lsb_release", "-c", "-s"], stdout=subprocess.PIPE).communicate()[0][:-1]
96
 
 
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,
105
 
    ])
106
 
 
107
 
logging.info("Creating data hierarchy.")
108
 
subprocess.check_call(["sudo", "ivle-createdatadirs"])
109
 
 
110
 
 
111
 
# Configure Apache
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"])
118
 
 
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"])
124
 
 
125
 
subprocess.check_call(
126
 
    ["sudo", "/etc/init.d/apache2", "reload"])
127
 
 
128
 
 
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")
135
 
 
136
 
 
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"])