1092.1.46
by Matt Giuca
setup: Removed 'config' mode. It's now standalone. |
1 |
#!/usr/bin/python
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
2 |
# IVLE - Informatics Virtual Learning Environment
|
1092.1.1
by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.] |
3 |
# Copyright (C) 2007-2009 The University of Melbourne
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
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 |
# Author: Matt Giuca, Refactored by David Coles
|
|
20 |
||
1092.1.1
by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.] |
21 |
'''Configures IVLE with machine-specific details, most notably, various paths.
|
22 |
Either prompts the administrator for these details or accepts them as
|
|
23 |
command-line args.
|
|
24 |
||
25 |
Creates ivle/conf/conf.py and bin/trampoline/trampoline/conf.h.
|
|
26 |
'''
|
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
27 |
|
28 |
import optparse |
|
29 |
import getopt |
|
30 |
import os |
|
819
by mattgiuca
setup/configure.py: Added "import sys". |
31 |
import sys |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
32 |
import hashlib |
33 |
import uuid |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
34 |
|
1092.1.34
by Matt Giuca
setup.configure: Replaced use of legacy conf.py for loading existing values. |
35 |
import ivle.config |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
36 |
|
1092.1.11
by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using |
37 |
import configobj |
38 |
||
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
39 |
class ConfigOption: |
40 |
"""A configuration option; one of the things written to conf.py."""
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
41 |
def __init__(self, option_name, default, prompt, comment, ask=True): |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
42 |
"""Creates a configuration option.
|
43 |
option_name: Name of the variable in conf.py. Also name of the
|
|
44 |
command-line argument to setup.py conf.
|
|
45 |
default: Default value for this variable.
|
|
46 |
prompt: (Short) string presented during the interactive prompt in
|
|
47 |
setup.py conf.
|
|
48 |
comment: (Long) comment string stored in conf.py. Each line of this
|
|
49 |
string should begin with a '#'.
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
50 |
ask: Whether to ask the question in the default config run.
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
51 |
"""
|
52 |
self.option_name = option_name |
|
53 |
self.default = default |
|
54 |
self.prompt = prompt |
|
55 |
self.comment = comment |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
56 |
self.ask = ask |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
57 |
|
58 |
# Configuration options, defaults and descriptions
|
|
59 |
config_options = [] |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
60 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
61 |
config_options.append(ConfigOption("urls/root", "/", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
62 |
"""Root directory where IVLE is located (in URL space):""", |
63 |
"""
|
|
64 |
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
|
|
65 |
# with this).
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
66 |
# eg. "/" or "/ivle".""", ask=False)) |
67 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
68 |
config_options.append(ConfigOption("paths/prefix", "/usr/local", |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
69 |
"""In the local file system, the prefix to the system directory where IVLE
|
70 |
is installed. (This should either be /usr or /usr/local):""", |
|
71 |
"""
|
|
72 |
# In the local file system, the prefix to the system directory where IVLE is
|
|
73 |
# installed. This should either be '/usr' or '/usr/local'.
|
|
74 |
# ('/usr/local' for the usual install, '/usr' for distribution packages)""", |
|
75 |
ask=False)) |
|
76 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
77 |
config_options.append(ConfigOption("paths/site_packages", |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
78 |
None, |
79 |
"""site-packages directory in Python, where Python libraries are to be
|
|
80 |
installed. May be left as the default, in which case the value will be
|
|
81 |
computed from prefix and the current Python version:""", |
|
82 |
"""
|
|
83 |
# 'site-packages' directory in Python, where Python libraries are to be
|
|
1092.1.41
by Matt Giuca
setup.configure: Fixed "None" as the default - now writes nothing rather than |
84 |
# installed. May be omitted (recommended), in which case the value will be
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
85 |
# computed from prefix and the current Python version.""", ask=False)) |
86 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
87 |
config_options.append(ConfigOption("paths/data", |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
88 |
"/var/lib/ivle", |
89 |
"In the local file system, where user-modifiable data files should be "
|
|
90 |
"located:", |
|
91 |
"""
|
|
92 |
# In the local file system, where user-modifiable data files should be
|
|
93 |
# located.""", ask=False)) |
|
94 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
95 |
config_options.append(ConfigOption("paths/logs", |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
96 |
"/var/log/ivle", |
893
by dcoles
Dispatch: Now attempts to log unhandled exceptions to a log directory specified |
97 |
"""Directory where IVLE log files are stored (on the local
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
98 |
file system). Note - this must be writable by the user the IVLE server
|
99 |
process runs as (usually www-data):""", |
|
893
by dcoles
Dispatch: Now attempts to log unhandled exceptions to a log directory specified |
100 |
"""
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
101 |
# In the local file system, where IVLE error logs should be located.""", |
102 |
ask=False)) |
|
103 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
104 |
config_options.append(ConfigOption("urls/public_host", "public.localhost", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
105 |
"""Hostname which will cause the server to go into "public mode",
|
106 |
providing login-free access to student's published work:""", |
|
107 |
"""
|
|
108 |
# The server goes into "public mode" if the browser sends a request with this
|
|
109 |
# host. This is for security reasons - we only serve public student files on a
|
|
110 |
# separate domain to the main IVLE site.
|
|
111 |
# Public mode does not use cookies, and serves only public content.
|
|
112 |
# Private mode (normal mode) requires login, and only serves files relevant to
|
|
113 |
# the logged-in user.""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
114 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
115 |
config_options.append(ConfigOption("os/allowed_uids", "33", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
116 |
"""UID of the web server process which will run IVLE.
|
117 |
Only this user may execute the trampoline. May specify multiple users as
|
|
118 |
a comma-separated list.
|
|
119 |
(eg. "1002,78")""", |
|
120 |
"""
|
|
121 |
# The User-ID of the web server process which will run IVLE, and any other
|
|
122 |
# users who are allowed to run the trampoline. This is stores as a string of
|
|
123 |
# comma-separated integers, simply because it is not used within Python, only
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
124 |
# used by the setup program to write to conf.h (see setup.py config).""", |
125 |
ask=False)) |
|
126 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
127 |
config_options.append(ConfigOption("database/host", "localhost", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
128 |
"""PostgreSQL Database config
|
129 |
==========================
|
|
130 |
Hostname of the DB server:""", |
|
131 |
"""
|
|
132 |
# Database server hostname""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
133 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
134 |
config_options.append(ConfigOption("database/port", "5432", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
135 |
"""Port of the DB server:""", |
136 |
"""
|
|
137 |
# Database server port""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
138 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
139 |
config_options.append(ConfigOption("database/name", "ivle", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
140 |
"""Database name:""", |
141 |
"""
|
|
142 |
# Database name""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
143 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
144 |
config_options.append(ConfigOption("plugins/forum/dbname", "ivle_forum", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
145 |
"""Forum Database name:""", |
146 |
"""
|
|
147 |
# Forum Database name""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
148 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
149 |
config_options.append(ConfigOption("database/username", "postgres", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
150 |
"""Username for DB server login:""", |
151 |
"""
|
|
152 |
# Database username""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
153 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
154 |
config_options.append(ConfigOption("database/password", "", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
155 |
"""Password for DB server login:
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
156 |
(Caution: This password is stored in plaintext in ivle/conf/conf.py)""", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
157 |
"""
|
158 |
# Database password""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
159 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
160 |
config_options.append(ConfigOption("auth/modules", "", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
161 |
"""Authentication config
|
162 |
=====================
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
163 |
Comma-separated list of authentication modules.""", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
164 |
"""
|
165 |
# Comma-separated list of authentication modules.
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
166 |
# Note that auth is always enabled against the local database, and NO OTHER
|
167 |
# auth is enabled by default. This section is for specifying additional auth
|
|
168 |
# modules.
|
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
169 |
# These refer to importable Python modules in the www/auth directory.
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
170 |
# Modules "ldap_auth" and "guest" are available in the source tree, but
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
171 |
# other modules may be plugged in to auth against organisation-specific
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
172 |
# auth backends.""", ask=False)) |
173 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
174 |
config_options.append(ConfigOption("auth/ldap_url", "ldaps://www.example.com", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
175 |
"""(LDAP options are only relevant if "ldap" is included in the list of
|
176 |
auth modules).
|
|
177 |
URL for LDAP authentication server:""", |
|
178 |
"""
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
179 |
# URL for LDAP authentication server""", ask=False)) |
180 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
181 |
config_options.append(ConfigOption("auth/ldap_format_string", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
182 |
"uid=%s,ou=users,o=example", |
183 |
"""Format string for LDAP auth request:
|
|
184 |
(Must contain a single "%s" for the user's login name)""", |
|
185 |
"""
|
|
186 |
# Format string for LDAP auth request
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
187 |
# (Must contain a single "%s" for the user's login name)""", ask=False)) |
188 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
189 |
config_options.append(ConfigOption("auth/subject_pulldown_modules", "", |
819
by mattgiuca
setup/configure.py: Added "import sys". |
190 |
"""Comma-separated list of subject pulldown modules.
|
191 |
Add proprietary modules to automatically enrol students in subjects.""", |
|
192 |
"""
|
|
193 |
# Comma-separated list of subject pulldown modules.
|
|
194 |
# These refer to importable Python modules in the lib/pulldown_subj directory.
|
|
820
by mattgiuca
lib: Added new package pulldown_subj, a collection of modules designed to |
195 |
# Only "dummy_subj" is available in the source tree (an example), but
|
819
by mattgiuca
setup/configure.py: Added "import sys". |
196 |
# other modules may be plugged in to pulldown against organisation-specific
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
197 |
# pulldown backends.""", ask=False)) |
198 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
199 |
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
200 |
"""Subversion config
|
201 |
=================
|
|
202 |
The base url for accessing subversion repositories:""", |
|
203 |
"""
|
|
204 |
# The base url for accessing subversion repositories.""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
205 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
206 |
config_options.append(ConfigOption("usrmgt/host", "localhost", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
207 |
"""User Management Server config
|
208 |
============================
|
|
209 |
The hostname where the usrmgt-server runs:""", |
|
210 |
"""
|
|
211 |
# The hostname where the usrmgt-server runs.""")) |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
212 |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
213 |
config_options.append(ConfigOption("usrmgt/port", "2178", |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
214 |
"""The port where the usrmgt-server runs:""", |
215 |
"""
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
216 |
# The port where the usrmgt-server runs.""", ask=False)) |
217 |
||
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
218 |
config_options.append(ConfigOption("usrmgt/magic", None, |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
219 |
"""The password for the usrmgt-server:""", |
220 |
"""
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
221 |
# The password for the usrmgt-server.""", ask=False)) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
222 |
|
1092.1.44
by Matt Giuca
setup.util: Moved query_user to setup.configure. (It's the only user of this |
223 |
def query_user(default, prompt): |
224 |
"""Prompts the user for a string, which is read from a line of stdin.
|
|
225 |
Exits silently if EOF is encountered. Returns the string, with spaces
|
|
226 |
removed from the beginning and end.
|
|
227 |
||
228 |
Returns default if a 0-length line (after spaces removed) was read.
|
|
229 |
"""
|
|
230 |
if default is None: |
|
231 |
# A default of None means the value will be computed specially, so we
|
|
232 |
# can't really tell you what it is
|
|
233 |
defaultstr = "computed" |
|
234 |
elif isinstance(default, basestring): |
|
235 |
defaultstr = '"%s"' % default |
|
236 |
else: |
|
237 |
defaultstr = repr(default) |
|
238 |
sys.stdout.write('%s\n (default: %s)\n>' % (prompt, defaultstr)) |
|
239 |
try: |
|
240 |
val = sys.stdin.readline() |
|
241 |
except KeyboardInterrupt: |
|
242 |
# Ctrl+C
|
|
243 |
sys.stdout.write("\n") |
|
244 |
sys.exit(1) |
|
245 |
sys.stdout.write("\n") |
|
246 |
# If EOF, exit
|
|
247 |
if val == '': sys.exit(1) |
|
248 |
# If empty line, return default
|
|
249 |
val = val.strip() |
|
250 |
if val == '': return default |
|
251 |
return val |
|
252 |
||
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
253 |
def configure(args): |
254 |
# Try importing existing conf, but if we can't just set up defaults
|
|
255 |
# The reason for this is that these settings are used by other phases
|
|
256 |
# of setup besides conf, so we need to know them.
|
|
257 |
# Also this allows you to hit Return to accept the existing value.
|
|
1092.1.37
by Matt Giuca
setup.configure: Now handles the case of a missing config file. |
258 |
try: |
259 |
conf = ivle.config.Config() |
|
260 |
except ivle.config.ConfigError: |
|
261 |
# Couldn't find a config file anywhere.
|
|
262 |
# Create a new blank config object (not yet bound to a file)
|
|
263 |
# All lookups (below) will fail, so it will be initialised with all
|
|
264 |
# the default values.
|
|
265 |
conf = ivle.config.Config(blank=True) |
|
266 |
||
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
267 |
# Check that all the options are present, and if not, load the default
|
1092.1.34
by Matt Giuca
setup.configure: Replaced use of legacy conf.py for loading existing values. |
268 |
for opt in config_options: |
269 |
try: |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
270 |
conf.get_by_path(opt.option_name) |
1092.1.34
by Matt Giuca
setup.configure: Replaced use of legacy conf.py for loading existing values. |
271 |
except KeyError: |
1092.1.41
by Matt Giuca
setup.configure: Fixed "None" as the default - now writes nothing rather than |
272 |
# If the default is None, omit it
|
273 |
# Else ConfigObj will write the string 'None' to the conf file
|
|
274 |
if opt.default is not None: |
|
275 |
conf.set_by_path(opt.option_name, opt.default) |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
276 |
|
277 |
# Store comments in the conf object
|
|
278 |
for opt in config_options: |
|
1092.1.45
by Matt Giuca
setup.configure: Fixed bug if usrmgt_magic is None. Does not write comment if |
279 |
# Omitted if the key doesn't exist
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
280 |
conf.set_by_path(opt.option_name, comment=opt.comment) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
281 |
|
282 |
# Set up some variables
|
|
283 |
cwd = os.getcwd() |
|
284 |
||
285 |
# the files that will be created/overwritten
|
|
1092.1.11
by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using |
286 |
conffile = os.path.join(cwd, "etc/ivle.conf") |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
287 |
conf_hfile = os.path.join(cwd, "bin/trampoline/conf.h") |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
288 |
phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php") |
289 |
||
290 |
# Get command-line arguments to avoid asking questions.
|
|
291 |
||
292 |
optnames = [] |
|
293 |
for opt in config_options: |
|
294 |
optnames.append(opt.option_name + "=") |
|
295 |
(opts, args) = getopt.gnu_getopt(args, "", optnames) |
|
296 |
||
297 |
if args != []: |
|
298 |
print >>sys.stderr, "Invalid arguments:", string.join(args, ' ') |
|
299 |
return 2 |
|
300 |
||
301 |
if opts == []: |
|
302 |
# Interactive mode. Prompt the user for all the values.
|
|
303 |
||
304 |
print """This tool will create the following files: |
|
305 |
%s |
|
306 |
%s |
|
307 |
%s |
|
308 |
prompting you for details about your configuration. The file will be
|
|
309 |
overwritten if it already exists. It will *not* install or deploy IVLE.
|
|
310 |
||
311 |
Please hit Ctrl+C now if you do not wish to do this.
|
|
1092.1.1
by William Grant
[Uber-commit of holiday work because I lacked a local copy of the branch.] |
312 |
""" % (conffile, conf_hfile, phpBBconffile) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
313 |
|
314 |
# Get information from the administrator
|
|
315 |
# If EOF is encountered at any time during the questioning, just exit
|
|
316 |
# silently
|
|
317 |
||
318 |
for opt in config_options: |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
319 |
if opt.ask: |
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
320 |
conf.set_by_path(opt.option_name, |
321 |
query_user(conf.get_by_path(opt.option_name), opt.prompt)) |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
322 |
else: |
323 |
opts = dict(opts) |
|
324 |
# Non-interactive mode. Parse the options.
|
|
325 |
for opt in config_options: |
|
326 |
if '--' + opt.option_name in opts: |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
327 |
conf.set_by_path(opt.option_name, |
328 |
opts['--' + opt.option_name]) |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
329 |
|
330 |
# Error handling on input values
|
|
331 |
try: |
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
332 |
allowed_uids_list = map(int, |
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
333 |
conf['os']['allowed_uids'].split(',')) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
334 |
except ValueError: |
335 |
print >>sys.stderr, ( |
|
336 |
"Invalid UID list (%s).\n" |
|
1092.1.30
by Matt Giuca
setup.configure: Replaced all uses of config-variable global variables with |
337 |
"Must be a comma-separated list of integers." % |
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
338 |
conf['os']['allowed_uids']) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
339 |
return 1 |
340 |
try: |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
341 |
conf['database']['port'] = int(conf['database']['port']) |
342 |
if (conf['database']['port'] < 0 |
|
343 |
or conf['database']['port'] >= 65536): |
|
1092.1.30
by Matt Giuca
setup.configure: Replaced all uses of config-variable global variables with |
344 |
raise ValueError() |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
345 |
except ValueError: |
346 |
print >>sys.stderr, ( |
|
347 |
"Invalid DB port (%s).\n" |
|
1092.1.32
by Matt Giuca
configure.py: Fixed missing reference to conf_options in error case. |
348 |
"Must be an integer between 0 and 65535." % |
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
349 |
repr(conf['database']['port'])) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
350 |
return 1 |
351 |
try: |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
352 |
conf['usrmgt']['port'] = int(conf['usrmgt']['port']) |
353 |
if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536): |
|
1092.1.30
by Matt Giuca
setup.configure: Replaced all uses of config-variable global variables with |
354 |
raise ValueError() |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
355 |
except ValueError: |
356 |
print >>sys.stderr, ( |
|
357 |
"Invalid user management port (%s).\n" |
|
1092.1.32
by Matt Giuca
configure.py: Fixed missing reference to conf_options in error case. |
358 |
"Must be an integer between 0 and 65535." % |
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
359 |
repr(conf['usrmgt']['port'])) |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
360 |
return 1 |
361 |
||
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
362 |
# By default we generate the magic randomly.
|
1092.1.45
by Matt Giuca
setup.configure: Fixed bug if usrmgt_magic is None. Does not write comment if |
363 |
try: |
364 |
conf['usrmgt']['magic'] # Throw away; just check for KeyError |
|
365 |
except KeyError: |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
366 |
conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest() |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
367 |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
368 |
# Generate the forum secret
|
369 |
forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest() |
|
370 |
||
1092.1.37
by Matt Giuca
setup.configure: Now handles the case of a missing config file. |
371 |
# Write ./etc/ivle.conf (even if we loaded from a different filename)
|
1092.1.11
by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using |
372 |
conf.filename = conffile |
373 |
||
374 |
conf.initial_comment = ["# IVLE Configuration File"] |
|
375 |
||
1092.1.10
by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf. |
376 |
# Add the forum secret to the config file (regenerated each config)
|
1092.1.33
by Matt Giuca
setup.configure: Replaced all of the config option names with the new path |
377 |
config_options.append(ConfigOption('plugins/forum/secret', None, '', '')) |
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
378 |
conf['plugins']['forum']['secret'] = forum_secret |
1092.1.11
by Matt Giuca
Replaced Python config files (conf.py) with new config files system, using |
379 |
|
380 |
conf.write() |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
381 |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
382 |
print "Successfully wrote %s" % conffile |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
383 |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
384 |
# Write bin/trampoline/conf.h
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
385 |
|
1092.1.38
by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were |
386 |
conf_h = open(conf_hfile, "w") |
1092.1.10
by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf. |
387 |
|
388 |
# XXX Compute jail_base, jail_src_base and jail_system. These will
|
|
389 |
# ALSO be done by the boilerplate code, but we need them here in order
|
|
390 |
# to write to the C file.
|
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
391 |
jail_base = os.path.join(conf['paths']['data'], 'jailmounts') |
392 |
jail_src_base = os.path.join(conf['paths']['data'], 'jails') |
|
1092.1.10
by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf. |
393 |
jail_system = os.path.join(jail_src_base, '__base__') |
394 |
||
1092.1.38
by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were |
395 |
conf_h.write("""/* IVLE Configuration File |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
396 |
* conf.h
|
397 |
* Administrator settings required by trampoline.
|
|
398 |
* Note: trampoline will have to be rebuilt in order for changes to this file
|
|
399 |
* to take effect.
|
|
400 |
*/
|
|
401 |
||
813
by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens |
402 |
#define IVLE_AUFS_JAILS
|
403 |
||
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
404 |
/* In the local file system, where are the jails located.
|
405 |
* The trampoline does not allow the creation of a jail anywhere besides
|
|
406 |
* jail_base or a subdirectory of jail_base.
|
|
407 |
*/
|
|
408 |
static const char* jail_base = "%s"; |
|
813
by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens |
409 |
static const char* jail_src_base = "%s"; |
410 |
static const char* jail_system = "%s"; |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
411 |
|
412 |
/* Which user IDs are allowed to run the trampoline.
|
|
413 |
* This list should be limited to the web server user.
|
|
414 |
* (Note that root is an implicit member of this list).
|
|
415 |
*/
|
|
416 |
static const int allowed_uids[] = { %s }; |
|
813
by William Grant
Merge jails-redux branch. We now use aufs rather than hardlinking tens |
417 |
""" % (repr(jail_base)[1:-1], repr(jail_src_base)[1:-1], |
418 |
repr(jail_system)[1:-1], repr(allowed_uids_list)[1:-1])) |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
419 |
# Note: The above uses PYTHON reprs, not C reprs
|
420 |
# However they should be the same with the exception of the outer
|
|
421 |
# characters, which are stripped off and replaced
|
|
422 |
||
1092.1.38
by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were |
423 |
conf_h.close() |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
424 |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
425 |
print "Successfully wrote %s" % conf_hfile |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
426 |
|
427 |
# Write www/php/phpBB3/config.php
|
|
428 |
||
1092.1.38
by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were |
429 |
conf_php = open(phpBBconffile, "w") |
1092.1.10
by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf. |
430 |
|
431 |
# php-pg work around
|
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
432 |
if conf['database']['host'] == 'localhost': |
1092.1.10
by Matt Giuca
setup/configure.py: Removed exception handling of IOErrors when writing conf. |
433 |
forumdb_host = '127.0.0.1' |
434 |
else: |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
435 |
forumdb_host = conf['database']['host'] |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
436 |
|
1092.1.38
by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were |
437 |
conf_php.write( """<?php |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
438 |
// phpBB 3.0.x auto-generated configuration file
|
439 |
// Do not change anything in this file!
|
|
440 |
$dbms = 'postgres';
|
|
441 |
$dbhost = '""" + forumdb_host + """'; |
|
1092.1.39
by Matt Giuca
setup.configure: Replaced the use of an intermediate dictionary for storing |
442 |
$dbport = '""" + str(conf['database']['port']) + """'; |
443 |
$dbname = '""" + conf['plugins']['forum']['dbname'] + """'; |
|
444 |
$dbuser = '""" + conf['database']['username'] + """'; |
|
445 |
$dbpasswd = '""" + conf['database']['password'] + """'; |
|
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
446 |
|
447 |
$table_prefix = 'phpbb_';
|
|
448 |
$acm_type = 'file';
|
|
449 |
$load_extensions = '';
|
|
450 |
@define('PHPBB_INSTALLED', true);
|
|
451 |
// @define('DEBUG', true);
|
|
452 |
//@define('DEBUG_EXTRA', true);
|
|
453 |
||
454 |
$forum_secret = '""" + forum_secret +"""'; |
|
455 |
?>""" ) |
|
456 |
||
1092.1.38
by Matt Giuca
setup.configure: There were a bunch of variables all called 'conf' which were |
457 |
conf_php.close() |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
458 |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
459 |
print "Successfully wrote %s" % phpBBconffile |
803
by dcoles
Setup: Modularised setup.py so it is now no longer over 1000 lines. This should |
460 |
|
461 |
print
|
|
462 |
print "You may modify the configuration at any time by editing" |
|
463 |
print conffile |
|
464 |
print conf_hfile |
|
465 |
print phpBBconffile |
|
466 |
print
|
|
467 |
||
468 |
return 0 |
|
1092.1.46
by Matt Giuca
setup: Removed 'config' mode. It's now standalone. |
469 |
|
470 |
def main(argv=None): |
|
471 |
if argv is None: |
|
472 |
argv = sys.argv |
|
473 |
||
474 |
# Print the opening spiel including the GPL notice
|
|
475 |
||
476 |
print """IVLE - Informatics Virtual Learning Environment Setup |
|
477 |
Copyright (C) 2007-2009 The University of Melbourne
|
|
478 |
IVLE comes with ABSOLUTELY NO WARRANTY.
|
|
479 |
This is free software, and you are welcome to redistribute it
|
|
480 |
under certain conditions. See LICENSE.txt for details.
|
|
481 |
||
482 |
IVLE Configuration
|
|
483 |
"""
|
|
484 |
||
485 |
return configure(argv[1:]) |
|
486 |
||
487 |
if __name__ == "__main__": |
|
488 |
sys.exit(main()) |