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

« back to all changes in this revision

Viewing changes to setup/build.py

ivle-buildjail now only copies the system's IVLE files if jail/devmode
is True. It defaults to False.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Author: Matt Giuca, Refactored by David Coles
20
20
# Date:   02/07/2008
21
21
 
22
 
# setup/build.py
23
 
# Compiles all files and sets up a jail template in the source directory.
24
 
# Details:
25
 
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
26
 
# Creates jail/.
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.
32
 
 
33
22
import optparse
34
23
import os
 
24
import sys
35
25
import compileall
36
 
from setuputil import *
 
26
 
 
27
from setup import util
37
28
 
38
29
def build(args):
39
30
    usage = """usage: %prog build [options]
40
31
(requires root)
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.
43
33
Details:
44
 
Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
45
 
Creates jail with system and student packages installed from MIRROR.
46
 
Copies console/ to a location within the jail.
47
 
Copies OS programs and files to corresponding locations within the jail
48
 
  (eg. python and Python libs, ld.so, etc).
49
 
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."""
50
37
 
51
38
    # Parse arguments
52
39
    parser = optparse.OptionParser(usage)
53
40
    parser.add_option("-n", "--dry",
54
41
        action="store_true", dest="dry",
55
42
        help="Print out the actions but don't do anything.")
56
 
    parser.add_option("-m", "--mirror",
57
 
        action="store", dest="apt_mirror",
58
 
        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. "
 
49
             "(default: 33)")
59
50
    (options, args) = parser.parse_args(args)
60
51
 
61
52
    # Call the real function
62
 
    __build(options.dry, options.apt_mirror)
63
 
 
64
 
def __build(dry=False,apt_mirror="http://archive.ubuntu.com/ubuntu/"):
65
 
    # Importing configuration is a little tricky
66
 
    sys.path.append(os.pardir)
67
 
    import install_list
68
 
 
69
 
    # Must be run as root or a dry run  
 
53
    return __build(options.dry, options.nocompile, options.tuids)
 
54
 
 
55
def __build(dry=False, no_compile=None, tuids=None):
 
56
    install_list = util.InstallList()
 
57
 
70
58
    if dry:
71
59
        print "Dry run (no actions will be executed)\n"
72
 
    
73
 
    if not dry and os.geteuid() != 0:
74
 
        print >>sys.stderr, "Must be root to run build"
75
 
        print >>sys.stderr, "(I need to chroot)."
76
 
        return 1
77
 
    
78
 
    # Find out the revison number
79
 
    revnum = get_svn_revision()
80
 
    print "Building Revision %s"%str(revnum)
81
 
    if not dry:
82
 
        vfile = open('BUILD-VERSION','w')
83
 
        vfile.write(str(revnum) + '\n')
84
 
        vfile.close()
 
60
 
 
61
    # Create trampoline configuration.
 
62
    conf_hfile = os.path.join(os.getcwd(), "bin/trampoline/conf.h")
 
63
    conf_h = open(conf_hfile, "w")
 
64
 
 
65
    conf_h.write("""/* IVLE Configuration File
 
66
 * conf.h
 
67
 * Administrator settings required by trampoline.
 
68
 * Note: trampoline will have to be rebuilt in order for changes to this file
 
69
 * to take effect.
 
70
 */
 
71
 
 
72
#define IVLE_AUFS_JAILS
 
73
 
 
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).
 
77
 */
 
78
static const int allowed_uids[] = { %s };
 
79
""" % tuids)
 
80
    conf_h.close()
85
81
 
86
82
    # Compile the trampoline
87
83
    curdir = os.getcwd()
88
 
    os.chdir('trampoline')
89
 
    action_runprog('make', [], dry)
90
 
    os.chdir(curdir)
91
 
 
92
 
    # Create the jail and its subdirectories
93
 
    # Note: Other subdirs will be made by copying files
94
 
    action_runprog('./buildjail.sh', [], dry)
95
 
 
96
 
    # Copy all console and operating system files into the jail
97
 
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
98
 
    
99
 
    # Chmod the python console
100
 
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
101
 
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
102
 
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
103
 
    
104
 
    # Also copy the IVLE lib directory into the jail
105
 
    # This is necessary for running certain scripts
106
 
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
107
 
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
108
 
    # which could compromise security if left in the jail (such as the DB
109
 
    # password).
110
 
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
111
 
    # jailconf.py.
112
 
    action_copyfile('lib/conf/jailconf.py',
113
 
        'jail/opt/ivle/lib/conf/conf.py', dry)
 
84
    os.chdir('bin/trampoline')
 
85
    util.action_runprog('make', [], dry)
 
86
    os.chdir(curdir)
 
87
 
 
88
    # Compile timount
 
89
    curdir = os.getcwd()
 
90
    os.chdir('bin/timount')
 
91
    util.action_runprog('make', [], dry)
 
92
    os.chdir(curdir)
114
93
 
115
94
    # Compile .py files into .pyc or .pyo files
116
 
    compileall.compile_dir('www', quiet=True)
117
 
    compileall.compile_dir('lib', quiet=True)
118
 
    compileall.compile_dir('scripts', quiet=True)
119
 
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
120
 
 
121
 
    # Set up ivle.pth inside the jail
122
 
    # Need to set /opt/ivle/lib to be on the import path
123
 
    ivle_pth = \
124
 
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
125
 
    f = open(ivle_pth, 'w')
126
 
    f.write('/opt/ivle/lib\n')
127
 
    f.close()
 
95
    if not no_compile:
 
96
        compileall.compile_dir('ivle', quiet=True)
 
97
        compileall.compile_dir('services', quiet=True)
128
98
 
129
99
    return 0
130
100