2
# IVLE - Informatics Virtual Learning Environment
3
# Copyright (C) 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
26
usage = """usage: %prog [options]
28
Builds or updates the base IVLE jail."""
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)
42
print >> sys.stderr, "Must be root to run buildjail."
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."
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
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."
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,
66
if os.path.exists(jail_services_path):
67
shutil.rmtree(jail_services_path)
68
shutil.copytree(services_path, jail_services_path)
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)
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'))
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."