1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/usr/bin/python
# IVLE - Informatics Virtual Learning Environment
# Copyright (C) 2009 The University of Melbourne
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import optparse
import os
import sys
import shutil
import ivle.conf
usage = """usage: %prog [options]
(requires root)
Builds or updates the base IVLE jail."""
# Parse arguments
parser = optparse.OptionParser(usage)
parser.add_option("-r", "--recreate",
action="store_true", dest="recreate",
help='''Completely recreate the jail - don't just update its IVLE code.
Be warned, this may download hundreds of megabytes!''')
parser.add_option("-m", "--mirror",
action="store", dest="apt_mirror",
help="Sets the apt mirror used when recreating the jail.")
(options, args) = parser.parse_args(sys.argv)
if os.geteuid() != 0:
print >> sys.stderr, "Must be root to run buildjail."
sys.exit(1)
if not options.recreate and not os.path.exists(ivle.conf.jail_system_build):
print >> sys.stderr, "No jail exists -- please rerun with -r."
sys.exit(1)
if options.recreate:
# Create the jail and its subdirectories
# Note: Other subdirs will be made by copying files
if options.apt_mirror is not None:
os.environ['MIRROR'] = options.apt_mirror
# XXX: buildjail.sh should be reimplemented in Python, with its envvars
# turned into config options.
if os.spawnvp(os.P_WAIT, 'setup/buildjail.sh',
['setup/buildjail.sh', ivle.conf.jail_system_build]) != 0:
print >> sys.stderr, "Jail creation failed."
sys.exit(1)
# Copy all console and operating system files into the jail
services_path = os.path.join(ivle.conf.share_path, 'services')
jail_services_path = os.path.join(ivle.conf.jail_system_build,
services_path[1:])
if os.path.exists(jail_services_path):
shutil.rmtree(jail_services_path)
shutil.copytree(services_path, jail_services_path)
# Also copy the IVLE lib directory into the jail
# This is necessary for running certain services
ivle_site_packages = os.path.join(ivle.conf.python_site_packages, 'ivle')
jail_site_packages = os.path.join(ivle.conf.jail_system_build,
ivle_site_packages[1:])
if os.path.exists(jail_site_packages):
shutil.rmtree(jail_site_packages)
shutil.copytree(ivle_site_packages, jail_site_packages)
# IMPORTANT: ivle/conf/conf.py contains details which could compromise security
# if left in the jail (such as the DB password). We delete it now! It would be
# shadowed by the per-user conf.py anyway, but it's best to be safe.
os.unlink(os.path.join(jail_site_packages, 'conf/conf.py'))
# XXX: Shouldn't copy the compiled files at all, but compile them in the jail!
os.unlink(os.path.join(jail_site_packages, 'conf/conf.pyc'))
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
ivle.conf.jail_system_build + '/', ivle.conf.jail_system]) != 0:
print >> sys.stderr, "Jail copying failed."
sys.exit(1)
|