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

« back to all changes in this revision

Viewing changes to bin/ivle-buildjail

Replaced Python config files (conf.py) with new config files system, using
    configobj (INI-file style config files).

setup.py config now produces ./etc/ivle.conf, a new-style config file.
ivle/conf/conf.py is now part of the IVLE source code. It reads the new config
file and provides the same legacy interface, so all of IVLE still functions,
including setup.py config.

Added /etc to the source tree (config files will be stored here).
Added configobj as a dependency in doc/setup/install_proc.txt.

setup.py install copies ./etc/ivle.conf into /etc/ivle/ivle.conf.

Removed boilerplate code generation from setup/configure.py (that code is now
part of ivle/conf/conf.py which is now in 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
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="http://archive.ubuntu.com/ubuntu")
 
38
    help="Sets the apt mirror used when recreating the jail.")
47
39
(options, args) = parser.parse_args(sys.argv)
48
40
 
49
41
if os.geteuid() != 0:
50
42
    print >> sys.stderr, "Must be root to run buildjail."
51
43
    sys.exit(1)
52
44
 
53
 
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):
54
46
    print >> sys.stderr, "No jail exists -- please rerun with -r."
55
47
    sys.exit(1)
56
48
 
57
49
if options.recreate:
58
 
    options.upgrade = True
59
 
 
60
50
    # Create the jail and its subdirectories
61
51
    # Note: Other subdirs will be made by copying files
62
52
    if options.apt_mirror is not None:
63
53
        os.environ['MIRROR'] = options.apt_mirror
64
54
 
65
 
    os.system('rm -rf --one-file-system ' + build_path)
66
 
    ivle.jailbuilder.debian.debootstrap_create_jail(conf['jail']['suite'],
67
 
              build_path, mirror=options.apt_mirror)
68
 
 
69
 
    ivle.jailbuilder.debian.apt_update_cache(build_path)
70
 
    ivle.jailbuilder.debian.apt_install(build_path,
71
 
                        ['python2.5', 'python-cjson', 'python-svn'])
72
 
 
73
 
    ivle.jailbuilder.debian.apt_clean(build_path)
74
 
 
75
 
if options.upgrade:
76
 
    # Run apt-get update, apt-get upgrade and apt-get clean.
77
 
    ivle.jailbuilder.debian.mangle_sources_list(build_path, clobber=True)
78
 
    ivle.jailbuilder.debian.mangle_sources_list(build_path, lines=[
79
 
            'deb %s %s%s %s' % (options.apt_mirror, conf['jail']['suite'],
80
 
                                pocket, ' '.join(['main', 'universe']))
81
 
            for pocket in ('', '-updates', '-security')])
82
 
 
83
 
    # Add any extra site apt sources.
84
 
    if conf['jail']['extra_sources']:
85
 
        ivle.jailbuilder.debian.mangle_sources_list(build_path,
86
 
                  conf['jail']['extra_sources'])
87
 
 
88
 
    # Add any extra site apt keys.
89
 
    if conf['jail']['extra_keys']:
90
 
        ivle.jailbuilder.debian.apt_add_key(build_path,
91
 
                                            conf['jail']['extra_keys'])
92
 
 
93
 
    ivle.jailbuilder.debian.apt_update_cache(build_path)
94
 
    ivle.jailbuilder.debian.apt_upgrade(build_path)
95
 
 
96
 
    # Install any extra site packages.
97
 
    if conf['jail']['extra_packages']:
98
 
        ivle.jailbuilder.debian.apt_install(build_path,
99
 
                  conf['jail']['extra_packages'])
100
 
 
101
 
    ivle.jailbuilder.debian.apt_clean(build_path)
102
 
 
103
 
if conf['jail']['devmode']:
104
 
    # Copy all console and operating system files into the jail
105
 
    services_path = os.path.join(ivle.conf.share_path, 'services')
106
 
    jail_services_path = os.path.join(build_path, services_path[1:])
107
 
    if os.path.exists(jail_services_path):
108
 
        shutil.rmtree(jail_services_path)
109
 
    shutil.copytree(services_path, jail_services_path)
110
 
 
111
 
    # Also copy the IVLE lib directory into the jail
112
 
    # This is necessary for running certain services
113
 
    ivle_site_packages = os.path.join(ivle.conf.python_site_packages, 'ivle')
114
 
    jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
115
 
    if os.path.exists(jail_site_packages):
116
 
        shutil.rmtree(jail_site_packages)
117
 
    shutil.copytree(ivle_site_packages, jail_site_packages)
118
 
 
119
 
    # IMPORTANT: ivle/conf/conf.py contains details which could compromise security
120
 
    # if left in the jail (such as the DB password). We delete it now! It would be
121
 
    # shadowed by the per-user conf.py anyway, but it's best to be safe.
122
 
    os.unlink(os.path.join(jail_site_packages, 'conf/conf.py'))
123
 
    # XXX: Shouldn't copy the compiled files at all, but compile them in the jail!
124
 
    os.unlink(os.path.join(jail_site_packages, 'conf/conf.pyc'))
 
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'))
125
85
 
126
86
if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
127
 
              build_path + '/', ivle.conf.jail_system]) != 0:
 
87
              ivle.conf.jail_system_build + '/', ivle.conf.jail_system]) != 0:
128
88
    print >> sys.stderr, "Jail copying failed."
129
89
    sys.exit(1)
130
90