~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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# IVLE - Informatics Virtual Learning Environment
# Copyright (C) 2007-2008 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

# Module: setup/install
# Author: Matt Giuca, Refactored by David Coles
# Date:   03/07/2008

import optparse
import os
import sys
import functools

from setup import util

PYTHON_VERSION = sys.version[:3]

def install(args):
    usage = """usage: %prog install [options]
(Requires root)
Create target install directory ($target).
Create $target/bin.
Copy bin/trampoline/trampoline to $target/bin.
Copy bin/timount/timount to $target/bin.
chown and chmod the installed trampoline.
"""

    # Parse arguments
    parser = optparse.OptionParser(usage)
    parser.add_option("-n", "--dry",
        action="store_true", dest="dry",
        help="Print out the actions but don't do anything.")
    parser.add_option("-R", "--nosvnrevno",
        action="store_true", dest="nosvnrevno",
        help="Don't write out the Subversion revision to the share directory.")
    parser.add_option("--root",
        action="store", dest="rootdir",
        help="Install into a different root directory.",
        default='/')
    parser.add_option("--prefix",
        action="store", dest="prefix",
        help="Base prefix to install IVLE into (default: /usr/local).",
        default='/usr/local')
    parser.add_option("--python-site-packages",
        action="store", dest="python_site_packages",
        help="Path to Python site packages directory.",
        default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
    (options, args) = parser.parse_args(args)

    # Call the real function
    return __install(prefix=options.prefix,
                     python_site_packages=options.python_site_packages,
                     dry=options.dry, rootdir=options.rootdir,
                     nosvnrevno=options.nosvnrevno)

def __install(prefix, python_site_packages, dry=False, rootdir=None,
              nosvnrevno=False):
    install_list = util.InstallList()

    # We need to apply make_install_path with the rootdir to an awful lot of
    # config variables, so make it easy:
    mip = functools.partial(util.make_install_path, rootdir)

    # Compute the lib_path, share_path and bin_path (copied from
    # ivle/conf/conf.py).
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
    share_path = mip(os.path.join(prefix, 'share/ivle'))
    bin_path = mip(os.path.join(prefix, 'bin'))
    python_site_packages = mip(python_site_packages)

    # Must be run as root or a dry run  
    if dry:
        print "Dry run (no actions will be executed)\n"
    
    if not dry and os.geteuid() != 0:
        print >>sys.stderr, "Must be root to run install"
        return 1

    # Create the config directory.
    util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)

    # Create lib and copy the compiled files there
    util.action_mkdir(lib_path, dry)

    tramppath = os.path.join(lib_path, 'trampoline')
    util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
    # chown trampoline to root and set setuid bit
    util.action_chown_setuid(tramppath, dry)

    timountpath = os.path.join(lib_path, 'timount')
    util.action_copyfile('bin/timount/timount', timountpath, dry)

    # Copy in the services (only usrmgt-server is needed on the host, but
    # the jail build requires the rest).
    util.action_copylist(install_list.list_services, share_path, dry)
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
    util.action_chmod_x(usrmgtpath, dry)

    # Copy the user-executable binaries using the list.
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
                         onlybasename=True)

    # Copy the lib directory (using the list)
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)

    if not nosvnrevno:
        # Create the ivle working revision record file
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
        if not dry:
            try:
                conf = open(ivle_revision_file, "w")

                conf.write("""# SVN revision r%s
# Source tree location: %s
# Modified files:
""" % (util.get_svn_revision(), os.getcwd()))

                conf.close()
            except IOError, (errno, strerror):
                print "IO error(%s): %s" % (errno, strerror)
                sys.exit(1)

            os.system("svn status . >> %s" % ivle_revision_file)

        print "Wrote IVLE code revision status to %s" % ivle_revision_file

    return 0