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

« back to all changes in this revision

Viewing changes to bin/ivle-config

Merge from new-dispatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import getopt
30
30
import os
31
31
import sys
32
 
import stat
33
32
import hashlib
34
33
import uuid
35
34
 
75
74
# ('/usr/local' for the usual install, '/usr' for distribution packages)""",
76
75
    ask=False))
77
76
 
 
77
config_options.append(ConfigOption("paths/site_packages",
 
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
 
84
# installed. May be omitted (recommended), in which case the value will be
 
85
# computed from prefix and the current Python version.""", ask=False))
 
86
 
78
87
config_options.append(ConfigOption("paths/data",
79
88
    "/var/lib/ivle",
80
89
    "In the local file system, where user-modifiable data files should be "
92
101
# In the local file system, where IVLE error logs should be located.""",
93
102
    ask=False))
94
103
 
95
 
config_options.append(ConfigOption("urls/public_host",
96
 
    "public.ivle.localhost",
 
104
config_options.append(ConfigOption("urls/public_host", "public.localhost",
97
105
    """Hostname which will cause the server to go into "public mode",
98
106
providing login-free access to student's published work:""",
99
107
    """
104
112
# Private mode (normal mode) requires login, and only serves files relevant to
105
113
# the logged-in user."""))
106
114
 
107
 
config_options.append(ConfigOption("media/version", None,
108
 
    """Version of IVLE media resources (must change on each upgrade):""",
109
 
    """
110
 
# Version string for IVLE media resource URLs. When set, they are aggressively
111
 
# cached by the browser, so it must be either left unset or changed each time
112
 
# a media file is changed.""", ask=False))
113
 
 
114
115
config_options.append(ConfigOption("database/host", "localhost",
115
116
    """PostgreSQL Database config
116
117
==========================
135
136
 
136
137
config_options.append(ConfigOption("database/password", "",
137
138
    """Password for DB server login:
138
 
    (Caution: This password is stored in plaintext!)""",
 
139
    (Caution: This password is stored in plaintext in ivle/conf/conf.py)""",
139
140
    """
140
141
# Database password"""))
141
142
 
178
179
# other modules may be plugged in to pulldown against organisation-specific
179
180
# pulldown backends.""", ask=False))
180
181
 
181
 
config_options.append(ConfigOption("urls/svn_addr",
182
 
    "http://svn.ivle.localhost/",
 
182
config_options.append(ConfigOption("urls/svn_addr", "http://svn.localhost/",
183
183
    """Subversion config
184
184
=================
185
185
The base url for accessing subversion repositories:""",
266
266
    cwd = os.getcwd()
267
267
 
268
268
    # the files that will be created/overwritten
269
 
    try:
270
 
        confdir = os.environ['IVLECONF']
271
 
    except KeyError:
272
 
        confdir = '/etc/ivle'
273
 
 
274
 
    conffile = os.path.join(confdir, 'ivle.conf')
275
 
    plugindefaultfile = os.path.join(confdir, 'plugins.d/000default.conf')
 
269
    conffile = os.path.join(cwd, "etc/ivle.conf")
276
270
 
277
271
    # Get command-line arguments to avoid asking questions.
278
272
 
289
283
        # Interactive mode. Prompt the user for all the values.
290
284
 
291
285
        print """This tool will create %s, prompting you for details about
292
 
your configuration. The file will be updated with modified options if it already
293
 
exists. If it does not already exist, it will be created with sane defaults and
294
 
restrictive permissions.
295
 
 
296
 
%s will also be overwritten with the default list of plugins.
 
286
your configuration. The file will be overwritten if it already exists.
297
287
 
298
288
Please hit Ctrl+C now if you do not wish to do this.
299
 
""" % (conffile, plugindefaultfile)
 
289
""" % conffile
300
290
 
301
291
        # Get information from the administrator
302
292
        # If EOF is encountered at any time during the questioning, just exit
321
311
            or conf['database']['port'] >= 65536):
322
312
            raise ValueError()
323
313
    except ValueError:
324
 
        if conf['database']['port'] == '' or conf['database']['port'] is None:
325
 
            pass
326
 
        else:
327
 
            print >>sys.stderr, (
328
 
            "Invalid DB port (%s).\n"
329
 
            "Must be an integer between 0 and 65535." %
330
 
                repr(conf['database']['port']))
331
 
            return 1
 
314
        print >>sys.stderr, (
 
315
        "Invalid DB port (%s).\n"
 
316
        "Must be an integer between 0 and 65535." %
 
317
            repr(conf['database']['port']))
 
318
        return 1
332
319
    try:
333
320
        conf['usrmgt']['port'] = int(conf['usrmgt']['port'])
334
321
        if (conf['usrmgt']['port'] < 0 or conf['usrmgt']['port'] >= 65536):
346
333
    except KeyError:
347
334
        conf['usrmgt']['magic'] = hashlib.md5(uuid.uuid4().bytes).hexdigest()
348
335
 
349
 
    clobber_permissions = not os.path.exists(conffile)
350
336
 
351
337
    # Write ./etc/ivle.conf (even if we loaded from a different filename)
352
338
    conf.filename = conffile
 
339
 
353
340
    conf.initial_comment = ["# IVLE Configuration File"]
 
341
 
 
342
    try:
 
343
        conf['plugins']['forum']['secret']
 
344
    except KeyError:
 
345
        # Generate the forum secret.
 
346
        forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
 
347
        conf['plugins']['forum']['secret'] = forum_secret
 
348
 
354
349
    conf.write()
355
350
 
356
 
    # We need to restrict permissions on a new file, as it contains
357
 
    # a nice database password.
358
 
    if clobber_permissions:
359
 
        os.chown(conffile, 33, 33) # chown to www-data
360
 
        os.chmod(conffile, stat.S_IRUSR | stat.S_IWUSR) # No g/o perms!
361
 
 
362
351
    print "Successfully wrote %s" % conffile
363
 
 
364
 
    plugindefault = open(plugindefaultfile, 'w')
365
 
    plugindefault.write("""# IVLE default plugin configuration file
366
 
[ivle.webapp.core#Plugin]
367
 
[ivle.webapp.admin.user#Plugin]
368
 
[ivle.webapp.tutorial#Plugin]
369
 
[ivle.webapp.admin.subject#Plugin]
370
 
[ivle.webapp.filesystem.browser#Plugin]
371
 
[ivle.webapp.filesystem.diff#Plugin]
372
 
[ivle.webapp.filesystem.svnlog#Plugin]
373
 
[ivle.webapp.filesystem.serve#Plugin]
374
 
[ivle.webapp.groups#Plugin]
375
 
[ivle.webapp.console#Plugin]
376
 
[ivle.webapp.security#Plugin]
377
 
[ivle.webapp.media#Plugin]
378
 
[ivle.webapp.help#Plugin]
379
 
[ivle.webapp.tos#Plugin]
380
 
[ivle.webapp.userservice#Plugin]
381
 
[ivle.webapp.fileservice#Plugin]
382
 
[ivle.webapp.submit#Plugin]
383
 
""")
384
 
    plugindefault.close()
385
 
    print "Successfully wrote %s" % plugindefaultfile
386
 
 
387
352
    print
388
353
    print "You may modify the configuration at any time by editing " + conffile
389
354