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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python
# IVLE - Informatics Virtual Learning Environment
# Copyright (C) 2009 The University of Melbourne
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import optparse
import os
import sys
import shutil

import ivle.conf
import ivle.config
import ivle.jailbuilder.debian

usage = """usage: %prog [options]
(requires root)
Builds or updates the base IVLE jail."""

conf = ivle.config.Config()
build_path = ivle.conf.jail_system_build

# Parse arguments
parser = optparse.OptionParser(usage)
parser.add_option("-r", "--recreate",
    action="store_true", dest="recreate",
    help='''Completely recreate the jail - don't just update its IVLE code.
Be warned, this may download hundreds of megabytes!''')
parser.add_option("-u", "--upgrade",
    action="store_true", dest="upgrade",
    help='''Apply any package updates in the jail.''')
parser.add_option("-m", "--mirror",
    action="store", dest="apt_mirror",
    help="Sets the apt mirror.", default="http://archive.ubuntu.com/ubuntu")
(options, args) = parser.parse_args(sys.argv)

if os.geteuid() != 0:
    print >> sys.stderr, "Must be root to run buildjail."
    sys.exit(1)

if not options.recreate and not os.path.exists(build_path):
    print >> sys.stderr, "No jail exists -- please rerun with -r."
    sys.exit(1)

if options.recreate:
    options.upgrade = True

    # Create the jail and its subdirectories
    # Note: Other subdirs will be made by copying files
    if options.apt_mirror is not None:
        os.environ['MIRROR'] = options.apt_mirror

    os.system('rm -rf --one-file-system ' + build_path)
    ivle.jailbuilder.debian.debootstrap_create_jail(conf['jail']['suite'],
              build_path, mirror=options.apt_mirror)

    ivle.jailbuilder.debian.apt_update_cache(build_path)
    ivle.jailbuilder.debian.apt_install(build_path,
                        ['python2.5', 'python-cjson', 'python-svn'])

    ivle.jailbuilder.debian.apt_clean(build_path)

if options.upgrade:
    # Run apt-get update, apt-get upgrade and apt-get clean.
    ivle.jailbuilder.debian.mangle_sources_list(build_path, clobber=True)
    ivle.jailbuilder.debian.mangle_sources_list(build_path, lines=[
            'deb %s %s%s %s' % (options.apt_mirror, conf['jail']['suite'],
                                pocket, ' '.join(['main', 'universe']))
            for pocket in ('', '-updates', '-security')])

    # Add any extra site apt sources.
    if conf['jail']['extra_sources']:
        ivle.jailbuilder.debian.mangle_sources_list(build_path,
                  conf['jail']['extra_sources'])

    # Add any extra site apt keys.
    if conf['jail']['extra_keys']:
        ivle.jailbuilder.debian.apt_add_key(build_path,
                                            conf['jail']['extra_keys'])

    ivle.jailbuilder.debian.apt_update_cache(build_path)
    ivle.jailbuilder.debian.apt_upgrade(build_path)

    # Install any extra site packages.
    if conf['jail']['extra_packages']:
        ivle.jailbuilder.debian.apt_install(build_path,
                  conf['jail']['extra_packages'])

    ivle.jailbuilder.debian.apt_clean(build_path)

if conf['jail']['devmode']:
    # Copy all console and operating system files into the jail
    services_path = os.path.join(ivle.conf.share_path, 'services')
    jail_services_path = os.path.join(build_path, services_path[1:])
    if os.path.exists(jail_services_path):
        shutil.rmtree(jail_services_path)
    shutil.copytree(services_path, jail_services_path)

    # Also copy the IVLE lib directory into the jail
    # This is necessary for running certain services
    ivle_site_packages = os.path.join(os.path.dirname(ivle.__file__))
    jail_site_packages = os.path.join(build_path, ivle_site_packages[1:])
    if os.path.exists(jail_site_packages):
        shutil.rmtree(jail_site_packages)
    shutil.copytree(ivle_site_packages, jail_site_packages)

if os.spawnvp(os.P_WAIT, 'rsync', ['rsync', '-a', '--delete',
              build_path + '/', ivle.conf.jail_system]) != 0:
    print >> sys.stderr, "Jail copying failed."
    sys.exit(1)