19
19
# Author: Matt Giuca, Refactored by David Coles
23
# Compiles all files and sets up a jail template in the source directory.
25
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
27
# Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
28
# Copies console/ to a location within the jail.
29
# Copies OS programs and files to corresponding locations within the jail
30
# (eg. python and Python libs, ld.so, etc).
31
# Generates .pyc files for all the IVLE .py files.
36
from setuputil import *
27
from setup import util
39
30
usage = """usage: %prog build [options]
41
Compiles all files and sets up a jail template in the source directory.
42
-O is recommended to cause compilation to be optimised.
32
Compiles platform-specific code, and optionally Python too.
44
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
45
Compiles (GCC) timount/timount.c to timount/timount.
46
Creates jail with system and student packages installed from MIRROR.
47
Copies console/ to a location within the jail.
48
Copies OS programs and files to corresponding locations within the jail
49
(eg. python and Python libs, ld.so, etc).
50
Generates .pyc or .pyo files for all the IVLE .py files."""
34
Compiles (GCC) bin/trampoline/trampoline.c to bin/trampoline/trampoline.
35
Compiles (GCC) bin/timount/timount.c to bin/timount/timount.
36
Optionally generates .pyc files for all the IVLE .py files."""
53
39
parser = optparse.OptionParser(usage)
54
40
parser.add_option("-n", "--dry",
55
41
action="store_true", dest="dry",
56
42
help="Print out the actions but don't do anything.")
57
parser.add_option("-j", "--rebuildjail",
58
action="store_true", dest="rebuildjail",
59
help="Don't recreate jail/ - just update its IVLE code.")
60
parser.add_option("-m", "--mirror",
61
action="store", dest="apt_mirror",
62
help="Sets the APT mirror used to build the jail.")
43
parser.add_option("--no-compile",
44
action="store_true", dest="nocompile",
45
help="Don't byte-compile .py files.")
46
parser.add_option("-t", "--trampoline-uids",
47
action="store", dest="tuids", default="33",
48
help="Comma-separated list of UIDs allowed to use trampoline. "
63
50
(options, args) = parser.parse_args(args)
65
52
# Call the real function
66
__build(options.dry, options.rebuildjail, options.apt_mirror)
68
def __build(dry=False,rebuildjail=False,apt_mirror=None):
69
# Importing configuration is a little tricky
70
sys.path.append(os.pardir)
73
# Must be run as root or a dry run
53
return __build(options.dry, options.nocompile, options.tuids)
55
def __build(dry=False, no_compile=None, tuids=None):
56
install_list = util.InstallList()
75
59
print "Dry run (no actions will be executed)\n"
77
if not dry and os.geteuid() != 0:
78
print >>sys.stderr, "Must be root to run build"
79
print >>sys.stderr, "(I need to chroot)."
82
if not rebuildjail and not os.path.exists('jail'):
83
print >> sys.stderr, "No jail exists -- please rerun with -j."
86
# Find out the revison number
87
revnum = get_svn_revision()
88
print "Building Revision %s"%str(revnum)
90
vfile = open('BUILD-VERSION','w')
91
vfile.write(str(revnum) + '\n')
61
# Create trampoline configuration.
62
conf_hfile = os.path.join(os.getcwd(), "bin/trampoline/conf.h")
63
conf_h = open(conf_hfile, "w")
65
conf_h.write("""/* IVLE Configuration File
67
* Administrator settings required by trampoline.
68
* Note: trampoline will have to be rebuilt in order for changes to this file
72
#define IVLE_AUFS_JAILS
74
/* Which user IDs are allowed to run the trampoline.
75
* This list should be limited to the web server user.
76
* (Note that root is an implicit member of this list).
78
static const int allowed_uids[] = { %s };
94
82
# Compile the trampoline
95
83
curdir = os.getcwd()
96
os.chdir('trampoline')
97
action_runprog('make', [], dry)
84
os.chdir('bin/trampoline')
85
util.action_runprog('make', [], dry)
101
89
curdir = os.getcwd()
103
action_runprog('make', [], dry)
90
os.chdir('bin/timount')
91
util.action_runprog('make', [], dry)
107
# Create the jail and its subdirectories
108
# Note: Other subdirs will be made by copying files
109
if apt_mirror != None:
110
os.environ['MIRROR'] = apt_mirror
111
action_runprog('./bin/buildjail.sh', [], dry)
113
# Copy all console and operating system files into the jail
114
action_copylist(install_list.list_services, 'jail/opt/ivle', dry)
116
# Chmod the python console
117
action_chmod_x('jail/opt/ivle/services/python-console', dry)
118
action_chmod_x('jail/opt/ivle/services/fileservice', dry)
119
action_chmod_x('jail/opt/ivle/services/serveservice', dry)
121
# Also copy the IVLE lib directory into the jail
122
# This is necessary for running certain services
123
action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
124
# IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
125
# which could compromise security if left in the jail (such as the DB
127
# The "safe" version is in jailconf.py. Delete conf.py and replace it with
129
action_copyfile('lib/conf/jailconf.py',
130
'jail/opt/ivle/lib/conf/conf.py', dry)
132
94
# Compile .py files into .pyc or .pyo files
133
compileall.compile_dir('www', quiet=True)
134
compileall.compile_dir('lib', quiet=True)
135
compileall.compile_dir('services', quiet=True)
136
compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
138
# Set up ivle.pth inside the jail
139
# Need to set /opt/ivle/lib to be on the import path
141
"jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
142
f = open(ivle_pth, 'w')
143
f.write('/opt/ivle/lib\n')
96
compileall.compile_dir('ivle', quiet=True)
97
compileall.compile_dir('services', quiet=True)