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

« back to all changes in this revision

Viewing changes to bin/ivle-buildjail

Reimplement setup/buildjail.sh in Python. This means that sites can configure
additional repositories and packages to include in the jail, without modifying
the source tree.

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
25
27
 
26
28
usage = """usage: %prog [options]
27
29
(requires root)
28
30
Builds or updates the base IVLE jail."""
29
31
 
 
32
conf = ivle.config.Config()
 
33
build_path = ivle.conf.jail_system_build
 
34
 
30
35
# Parse arguments
31
36
parser = optparse.OptionParser(usage)
32
37
parser.add_option("-r", "--recreate",
33
38
    action="store_true", dest="recreate",
34
39
    help='''Completely recreate the jail - don't just update its IVLE code.
35
40
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.''')
36
44
parser.add_option("-m", "--mirror",
37
45
    action="store", dest="apt_mirror",
38
46
    help="Sets the apt mirror used when recreating the jail.")
42
50
    print >> sys.stderr, "Must be root to run buildjail."
43
51
    sys.exit(1)
44
52
 
45
 
if not options.recreate and not os.path.exists(ivle.conf.jail_system_build):
 
53
if not options.recreate and not os.path.exists(build_path):
46
54
    print >> sys.stderr, "No jail exists -- please rerun with -r."
47
55
    sys.exit(1)
48
56
 
52
60
    if options.apt_mirror is not None:
53
61
        os.environ['MIRROR'] = options.apt_mirror
54
62
 
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)
 
63
    os.system('rm -rf --one-file-system ' + build_path)
 
64
    ivle.jailbuilder.debian.debootstrap_create_jail('hardy',
 
65
              build_path, mirror=options.apt_mirror)
 
66
 
 
67
    # Add any extra site apt sources.
 
68
    if conf['jail']['extra_sources']:
 
69
        ivle.jailbuilder.debian.mangle_sources_list(build_path,
 
70
                  conf['jail']['extra_sources'])
 
71
 
 
72
    # Add any extra site apt keys.
 
73
    if conf['jail']['extra_keys']:
 
74
        ivle.jailbuilder.debian.apt_add_key(build_path,
 
75
                                            conf['jail']['extra_keys'])
 
76
 
 
77
    ivle.jailbuilder.debian.apt_update_cache(build_path)
 
78
    ivle.jailbuilder.debian.apt_install(build_path,
 
79
                        ['python2.5', 'python-cjson', 'python-svn'])
 
80
 
 
81
    # Install any extra site packages.
 
82
    if conf['jail']['extra_packages']:
 
83
        ivle.jailbuilder.debian.apt_install(build_path,
 
84
                  conf['jail']['extra_packages'])
 
85
 
 
86
    ivle.jailbuilder.debian.apt_clean(build_path)
 
87
 
 
88
if options.upgrade:
 
89
    # Run apt-get update, apt-get upgrade and apt-get clean.
 
90
    ivle.jailbuilder.debian.apt_update_cache(build_path)
 
91
    ivle.jailbuilder.debian.apt_upgrade(build_path)
 
92
    ivle.jailbuilder.debian.apt_clean(build_path)
61
93
 
62
94
# Copy all console and operating system files into the jail
63
95
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:])
 
96
jail_services_path = os.path.join(build_path, services_path[1:])
66
97
if os.path.exists(jail_services_path):
67
98
    shutil.rmtree(jail_services_path)
68
99
shutil.copytree(services_path, jail_services_path)
70
101
# Also copy the IVLE lib directory into the jail
71
102
# This is necessary for running certain services
72
103
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:])
 
104
jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
75
105
if os.path.exists(jail_site_packages):
76
106
    shutil.rmtree(jail_site_packages)
77
107
shutil.copytree(ivle_site_packages, jail_site_packages)
84
114
os.unlink(os.path.join(jail_site_packages, 'conf/conf.pyc'))
85
115
 
86
116
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
87
 
              ivle.conf.jail_system_build + '/', ivle.conf.jail_system]) != 0:
 
117
              build_path + '/', ivle.conf.jail_system]) != 0:
88
118
    print >> sys.stderr, "Jail copying failed."
89
119
    sys.exit(1)
90
120