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

« back to all changes in this revision

Viewing changes to bin/ivle-buildjail

Added module ivle.config, which takes care of some work interfacing with
    configobj, including searching for the file and opening the object.
ivle.conf.conf now uses this instead of having its own search.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# IVLE - Informatics Virtual Learning Environment
 
3
# Copyright (C) 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
import optparse
 
20
import os
 
21
import sys
 
22
import shutil
 
23
 
 
24
import ivle.conf
 
25
 
 
26
usage = """usage: %prog [options]
 
27
(requires root)
 
28
Builds or updates the base IVLE jail."""
 
29
 
 
30
# Parse arguments
 
31
parser = optparse.OptionParser(usage)
 
32
parser.add_option("-r", "--recreate",
 
33
    action="store_true", dest="recreate",
 
34
    help='''Completely recreate the jail - don't just update its IVLE code.
 
35
Be warned, this may download hundreds of megabytes!''')
 
36
parser.add_option("-m", "--mirror",
 
37
    action="store", dest="apt_mirror",
 
38
    help="Sets the apt mirror used when recreating the jail.")
 
39
(options, args) = parser.parse_args(sys.argv)
 
40
 
 
41
if os.geteuid() != 0:
 
42
    print >> sys.stderr, "Must be root to run buildjail."
 
43
    sys.exit(1)
 
44
 
 
45
if not options.recreate and not os.path.exists(ivle.conf.jail_system_build):
 
46
    print >> sys.stderr, "No jail exists -- please rerun with -r."
 
47
    sys.exit(1)
 
48
 
 
49
if options.recreate:
 
50
    # Create the jail and its subdirectories
 
51
    # Note: Other subdirs will be made by copying files
 
52
    if options.apt_mirror is not None:
 
53
        os.environ['MIRROR'] = options.apt_mirror
 
54
 
 
55
    # XXX: buildjail.sh should be reimplemented in Python, with its envvars
 
56
    # turned into config options.
 
57
    if os.spawnvp(os.P_WAIT, 'setup/buildjail.sh',
 
58
                  ['setup/buildjail.sh', ivle.conf.jail_system_build]) != 0:
 
59
        print >> sys.stderr, "Jail creation failed."
 
60
        sys.exit(1)
 
61
 
 
62
# Copy all console and operating system files into the jail
 
63
services_path = os.path.join(ivle.conf.share_path, 'services')
 
64
jail_services_path = os.path.join(ivle.conf.jail_system_build,
 
65
                                  services_path[1:])
 
66
if os.path.exists(jail_services_path):
 
67
    shutil.rmtree(jail_services_path)
 
68
shutil.copytree(services_path, jail_services_path)
 
69
 
 
70
# Also copy the IVLE lib directory into the jail
 
71
# This is necessary for running certain services
 
72
ivle_site_packages = os.path.join(ivle.conf.python_site_packages, 'ivle')
 
73
jail_site_packages = os.path.join(ivle.conf.jail_system_build,
 
74
                                  ivle_site_packages[1:])
 
75
if os.path.exists(jail_site_packages):
 
76
    shutil.rmtree(jail_site_packages)
 
77
shutil.copytree(ivle_site_packages, jail_site_packages)
 
78
 
 
79
# IMPORTANT: ivle/conf/conf.py contains details which could compromise security
 
80
# if left in the jail (such as the DB password). We delete it now! It would be
 
81
# shadowed by the per-user conf.py anyway, but it's best to be safe.
 
82
os.unlink(os.path.join(jail_site_packages, 'conf/conf.py'))
 
83
# XXX: Shouldn't copy the compiled files at all, but compile them in the jail!
 
84
os.unlink(os.path.join(jail_site_packages, 'conf/conf.pyc'))
 
85
 
 
86
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
 
87
              ivle.conf.jail_system_build + '/', ivle.conf.jail_system]) != 0:
 
88
    print >> sys.stderr, "Jail copying failed."
 
89
    sys.exit(1)
 
90