~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:
22
22
import shutil
23
23
 
24
24
import ivle.conf
25
 
import ivle.config
26
 
import ivle.jailbuilder.debian
27
25
 
28
26
usage = """usage: %prog [options]
29
27
(requires root)
30
28
Builds or updates the base IVLE jail."""
31
29
 
32
 
conf = ivle.config.Config()
33
 
build_path = ivle.conf.jail_system_build
34
 
 
35
30
# Parse arguments
36
31
parser = optparse.OptionParser(usage)
37
32
parser.add_option("-r", "--recreate",
38
33
    action="store_true", dest="recreate",
39
34
    help='''Completely recreate the jail - don't just update its IVLE code.
40
35
Be warned, this may download hundreds of megabytes!''')
41
 
parser.add_option("-u", "--upgrade",
42
 
    action="store_true", dest="upgrade",
43
 
    help='''Apply any package updates in the jail.''')
44
36
parser.add_option("-m", "--mirror",
45
37
    action="store", dest="apt_mirror",
46
 
    help="Sets the apt mirror.", default=conf['jail']['mirror'])
47
 
parser.add_option("--python-site-packages",
48
 
    action="store", dest="python_site_packages",
49
 
    help="Path to Python site packages directory inside the jail.",
50
 
    default=None)
 
38
    help="Sets the apt mirror used when recreating the jail.")
51
39
(options, args) = parser.parse_args(sys.argv)
52
40
 
53
41
if os.geteuid() != 0:
54
42
    print >> sys.stderr, "Must be root to run buildjail."
55
43
    sys.exit(1)
56
44
 
57
 
if not options.recreate and not os.path.exists(build_path):
 
45
if not options.recreate and not os.path.exists(ivle.conf.jail_system_build):
58
46
    print >> sys.stderr, "No jail exists -- please rerun with -r."
59
47
    sys.exit(1)
60
48
 
61
 
if (options.python_site_packages is not None and
62
 
    options.python_site_packages[:1] not in (os.path.sep, os.path.altsep)):
63
 
    print >> sys.stderr, "python-site-packages must be an absolute path."
64
 
    sys.exit(1)
65
 
 
66
49
if options.recreate:
67
 
    options.upgrade = True
68
 
 
69
50
    # Create the jail and its subdirectories
70
51
    # Note: Other subdirs will be made by copying files
71
52
    if options.apt_mirror is not None:
72
53
        os.environ['MIRROR'] = options.apt_mirror
73
54
 
74
 
    os.system('rm -rf --one-file-system ' + build_path)
75
 
    ivle.jailbuilder.debian.debootstrap_create_jail(conf['jail']['suite'],
76
 
              build_path, mirror=options.apt_mirror)
77
 
 
78
 
    ivle.jailbuilder.debian.apt_update_cache(build_path)
79
 
    ivle.jailbuilder.debian.apt_install(build_path,
80
 
                        ['python2.5', 'python-cjson', 'python-svn'])
81
 
 
82
 
    ivle.jailbuilder.debian.apt_clean(build_path)
83
 
 
84
 
if options.upgrade:
85
 
    # Run apt-get update, apt-get upgrade and apt-get clean.
86
 
    ivle.jailbuilder.debian.mangle_sources_list(build_path, clobber=True)
87
 
    ivle.jailbuilder.debian.mangle_sources_list(build_path, lines=[
88
 
            'deb %s %s%s %s' % (options.apt_mirror, conf['jail']['suite'],
89
 
                                pocket, ' '.join(['main', 'universe']))
90
 
            for pocket in ('', '-updates', '-security')])
91
 
 
92
 
    # Add any extra site apt sources.
93
 
    if conf['jail']['extra_sources']:
94
 
        ivle.jailbuilder.debian.mangle_sources_list(build_path,
95
 
                  conf['jail']['extra_sources'])
96
 
 
97
 
    # Add any extra site apt keys.
98
 
    if conf['jail']['extra_keys']:
99
 
        ivle.jailbuilder.debian.apt_add_key(build_path,
100
 
                                            conf['jail']['extra_keys'])
101
 
 
102
 
    ivle.jailbuilder.debian.apt_update_cache(build_path)
103
 
    ivle.jailbuilder.debian.apt_upgrade(build_path)
104
 
 
105
 
    # Install any extra site packages.
106
 
    if conf['jail']['extra_packages']:
107
 
        ivle.jailbuilder.debian.apt_install(build_path,
108
 
                  conf['jail']['extra_packages'])
109
 
 
110
 
    ivle.jailbuilder.debian.apt_clean(build_path)
111
 
 
112
 
if conf['jail']['devmode']:
113
 
    # Copy all console and operating system files into the jail
114
 
    services_path = os.path.join(ivle.conf.share_path, 'services')
115
 
    jail_services_path = os.path.join(build_path, services_path[1:])
116
 
    if os.path.exists(jail_services_path):
117
 
        shutil.rmtree(jail_services_path)
118
 
    shutil.copytree(services_path, jail_services_path)
119
 
 
120
 
    # Also copy the IVLE lib directory into the jail
121
 
    # This is necessary for running certain services
122
 
 
123
 
    # ivle_site_packages is the IVLE install location outside the jail
124
 
    ivle_site_packages = os.path.dirname(ivle.__file__)
125
 
 
126
 
    if options.python_site_packages is None:
127
 
        # Get the site packages from the IVLE install location *OUTSIDE* the
128
 
        # jail. Warning! This only works if you have the same Python site
129
 
        # packages directory inside and out (ie. same Python version).
130
 
        # If not, you should use --python-site-packages.
131
 
        jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
132
 
    else:
133
 
        # User-specified site packages
134
 
        jail_site_packages = os.path.join(build_path,
135
 
                                options.python_site_packages[1:], "ivle")
136
 
    if os.path.exists(jail_site_packages):
137
 
        shutil.rmtree(jail_site_packages)
138
 
    shutil.copytree(ivle_site_packages, jail_site_packages)
 
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'))
139
85
 
140
86
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
141
 
              build_path + '/', ivle.conf.jail_system]) != 0:
 
87
              ivle.conf.jail_system_build + '/', ivle.conf.jail_system]) != 0:
142
88
    print >> sys.stderr, "Jail copying failed."
143
89
    sys.exit(1)
144
90