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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: William Grant
  • Date: 2009-02-18 00:31:46 UTC
  • mto: (1092.1.63 setup-stuff)
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: grantw@unimelb.edu.au-20090218003146-jictayp2dg05ec1d
Remove phpBB3 installation code and instructions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Author: Matt Giuca, Refactored by David Coles
20
20
# Date:   03/07/2008
21
21
 
22
 
# setup/build.py
23
 
# Compiles all files and sets up a jail template in the source directory.
24
 
# Details:
25
 
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
26
 
# Creates jail/.
27
 
# Creates standard subdirs inside the jail, eg bin, opt, home, tmp.
28
 
# Copies console/ to a location within the jail.
29
 
# Copies OS programs and files to corresponding locations within the jail
30
 
#   (eg. python and Python libs, ld.so, etc).
31
 
# Generates .pyc files for all the IVLE .py files.
32
 
 
33
22
import optparse
34
23
import os
35
 
from setuputil import *
 
24
import sys
 
25
import functools
 
26
 
 
27
from setup import util
 
28
 
 
29
PYTHON_VERSION = sys.version[:3]
36
30
 
37
31
def install(args):
38
32
    usage = """usage: %prog install [options]
39
33
(Requires root)
40
34
Create target install directory ($target).
41
35
Create $target/bin.
42
 
Copy trampoline/trampoline to $target/bin.
43
 
Copy timount/timount to $target/bin.
 
36
Copy bin/trampoline/trampoline to $target/bin.
 
37
Copy bin/timount/timount to $target/bin.
44
38
chown and chmod the installed trampoline.
45
39
Copy www/ to $target.
46
 
Copy jail/ to jail_system directory (unless --nojail specified).
47
 
Copy subjects/ to subjects directory (unless --nosubjects specified).
48
40
"""
49
41
 
50
42
    # Parse arguments
52
44
    parser.add_option("-n", "--dry",
53
45
        action="store_true", dest="dry",
54
46
        help="Print out the actions but don't do anything.")
55
 
    parser.add_option("-J", "--nojail",
56
 
        action="store_true", dest="nojail",
57
 
        help="Don't copy jail/ to jail_system directory")
58
 
    parser.add_option("-S", "--nosubjects",
59
 
        action="store_true", dest="nosubjects",
60
 
        help="Don't copy subject/ to subjects directory.")
 
47
    parser.add_option("-R", "--nosvnrevno",
 
48
        action="store_true", dest="nosvnrevno",
 
49
        help="Don't write out the Subversion revision to the share directory.")
 
50
    parser.add_option("--root",
 
51
        action="store", dest="rootdir",
 
52
        help="Install into a different root directory.",
 
53
        default='/')
 
54
    parser.add_option("--prefix",
 
55
        action="store", dest="prefix",
 
56
        help="Base prefix to install IVLE into (default: /usr/local).",
 
57
        default='/usr/local')
 
58
    parser.add_option("--python-site-packages",
 
59
        action="store", dest="python_site_packages",
 
60
        help="Path to Python site packages directory.",
 
61
        default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
61
62
    (options, args) = parser.parse_args(args)
62
63
 
63
64
    # Call the real function
64
 
    __install(options.dry, options.nojail, options.nosubjects)
65
 
 
66
 
def __install(dry=False,nojail=False,nosubjects=False):
67
 
    # Importing configuration is a little tricky
68
 
    sys.path.append('lib')
69
 
    import conf.conf
70
 
    import install_list
71
 
 
72
 
    # Pull the required varibles out of the config
73
 
    ivle_install_dir = conf.conf.ivle_install_dir
74
 
    jail_base = conf.conf.jail_base
75
 
    jail_system = conf.conf.jail_system
76
 
    subjects_base = conf.conf.subjects_base
77
 
    exercises_base = conf.conf.exercises_base
 
65
    return __install(prefix=options.prefix,
 
66
                     python_site_packages=options.python_site_packages,
 
67
                     dry=options.dry, rootdir=options.rootdir,
 
68
                     nosvnrevno=options.nosvnrevno)
 
69
 
 
70
def __install(prefix, python_site_packages, dry=False, rootdir=None,
 
71
              nosvnrevno=False):
 
72
    install_list = util.InstallList()
 
73
 
 
74
    # We need to apply make_install_path with the rootdir to an awful lot of
 
75
    # config variables, so make it easy:
 
76
    mip = functools.partial(util.make_install_path, rootdir)
 
77
 
 
78
    # Compute the lib_path, share_path and bin_path (copied from
 
79
    # ivle/conf/conf.py).
 
80
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
 
81
    share_path = mip(os.path.join(prefix, 'share/ivle'))
 
82
    bin_path = mip(os.path.join(prefix, 'bin'))
 
83
    python_site_packages = mip(python_site_packages)
78
84
 
79
85
    # Must be run as root or a dry run  
80
86
    if dry:
81
87
        print "Dry run (no actions will be executed)\n"
82
88
    
83
89
    if not dry and os.geteuid() != 0:
84
 
        print >>sys.stderr, "Must be root to run build"
85
 
        print >>sys.stderr, "(I need to chown)."
 
90
        print >>sys.stderr, "Must be root to run install"
86
91
        return 1
87
 
    
88
 
    # Create the target (install) directory
89
 
    action_mkdir(ivle_install_dir, dry)
90
 
 
91
 
    # Create bin and copy the compiled files there
92
 
    action_mkdir(os.path.join(ivle_install_dir, 'bin'), dry)
93
 
    tramppath = os.path.join(ivle_install_dir, 'bin/trampoline')
94
 
    action_copyfile('trampoline/trampoline', tramppath, dry)
 
92
 
 
93
    # Create the config directory.
 
94
    util.action_mkdir('/etc/ivle/plugins.d', dry)
 
95
 
 
96
    # Create lib and copy the compiled files there
 
97
    util.action_mkdir(lib_path, dry)
 
98
 
 
99
    tramppath = os.path.join(lib_path, 'trampoline')
 
100
    util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
95
101
    # chown trampoline to root and set setuid bit
96
 
    action_chown_setuid(tramppath, dry)
97
 
 
98
 
    timountpath = os.path.join(ivle_install_dir, 'bin/timount')
99
 
    action_copyfile('timount/timount', timountpath, dry)
100
 
 
101
 
    # Create a scripts directory to put the usrmgt-server in.
102
 
    action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
103
 
    usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
104
 
    action_copyfile('scripts/usrmgt-server', usrmgtpath, dry)
105
 
    action_chmod_x(usrmgtpath, dry)
106
 
 
107
 
    # Copy the www and lib directories using the list
108
 
    action_copylist(install_list.list_www, ivle_install_dir, dry)
109
 
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
110
 
    
111
 
    # Make the config file private
112
 
    configpath = os.path.join(ivle_install_dir, 'lib/conf/conf.py')
113
 
    action_make_private(configpath, dry)
114
 
 
115
 
    # Copy the php directory
116
 
    forum_dir = "www/php/phpBB3"
117
 
    forum_path = os.path.join(ivle_install_dir, forum_dir)
118
 
    action_copytree(forum_dir, forum_path, dry)
119
 
    print "chown -R www-data:www-data %s" % forum_path
120
 
    if not dry:
121
 
        os.system("chown -R www-data:www-data %s" % forum_path)
122
 
 
123
 
    if not nojail:
124
 
        # Copy the local jail directory built by the build action
125
 
        # to the jail_system directory (it will be used to help build
126
 
        # all the students' jails).
127
 
        action_copytree('jail', jail_system, dry)
128
 
    if not nosubjects:
129
 
        # Copy the subjects and exercises directories across
130
 
        action_copylist(install_list.list_subjects, subjects_base, dry,
131
 
            srcdir="./subjects")
132
 
        action_copylist(install_list.list_exercises, exercises_base, dry,
133
 
            srcdir="./exercises")
134
 
 
135
 
    # Append IVLE path to ivle.pth in python site packages
136
 
    # (Unless it's already there)
137
 
    ivle_pth = os.path.join(sys.prefix,
138
 
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
139
 
    ivle_www = os.path.join(ivle_install_dir, "www")
140
 
    ivle_lib = os.path.join(ivle_install_dir, "lib")
141
 
    write_ivle_pth = True
142
 
    write_ivle_lib_pth = True
 
102
    util.action_chown_setuid(tramppath, dry)
 
103
 
 
104
    timountpath = os.path.join(lib_path, 'timount')
 
105
    util.action_copyfile('bin/timount/timount', timountpath, dry)
 
106
 
 
107
    # Copy in the services (only usrmgt-server is needed on the host, but
 
108
    # the jail build requires the rest).
 
109
    util.action_copylist(install_list.list_services, share_path, dry)
 
110
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
 
111
    util.action_chmod_x(usrmgtpath, dry)
 
112
 
 
113
    # Copy the user-executable binaries using the list.
 
114
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
 
115
                         onlybasename=True)
 
116
 
 
117
    # Copy the www directory (using the list)
 
118
    util.action_copylist(install_list.list_www, share_path, dry)
 
119
 
 
120
    # Copy the lib directory (using the list)
 
121
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
 
122
 
 
123
    # XXX We shouldn't have ivle.pth at all any more.
 
124
    # We may still need the www packages to be importable.
 
125
    # Anything from www that is needed from the outside should go to lib.
 
126
    ivle_pth = os.path.join(python_site_packages, "ivle.pth")
143
127
    try:
144
 
        file = open(ivle_pth, 'r')
145
 
        for line in file:
146
 
            if line.strip() == ivle_www:
147
 
                write_ivle_pth = False
148
 
            elif line.strip() == ivle_lib:
149
 
                write_ivle_lib_pth = False
 
128
        file = open(ivle_pth, 'w')
 
129
        file.write(os.path.join(share_path, "www"))
150
130
        file.close()
151
131
    except (IOError, OSError):
152
132
        pass
153
 
    if write_ivle_pth:
154
 
        action_append(ivle_pth, ivle_www)
155
 
    if write_ivle_lib_pth:
156
 
        action_append(ivle_pth, ivle_lib)
157
 
 
158
 
 
159
 
    # Create the ivle working revision record file
160
 
    action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
161
 
    ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
162
 
    if not dry:
163
 
        try:
164
 
            conf = open(ivle_revision_record_file, "w")
165
 
 
166
 
            conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
167
 
 
168
 
            conf.close()
169
 
        except IOError, (errno, strerror):
170
 
            print "IO error(%s): %s" % (errno, strerror)
171
 
            sys.exit(1)
172
 
 
173
 
        os.system("svn status -v . >> %s" % ivle_revision_record_file)
174
 
 
175
 
    print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
 
133
 
 
134
    if not nosvnrevno:
 
135
        # Create the ivle working revision record file
 
136
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
 
137
        if not dry:
 
138
            try:
 
139
                conf = open(ivle_revision_file, "w")
 
140
 
 
141
                conf.write("""# SVN revision r%s
 
142
# Source tree location: %s
 
143
# Modified files:
 
144
""" % (util.get_svn_revision(), os.getcwd()))
 
145
 
 
146
                conf.close()
 
147
            except IOError, (errno, strerror):
 
148
                print "IO error(%s): %s" % (errno, strerror)
 
149
                sys.exit(1)
 
150
 
 
151
            os.system("svn status . >> %s" % ivle_revision_file)
 
152
 
 
153
        print "Wrote IVLE code revision status to %s" % ivle_revision_file
176
154
 
177
155
    return 0
178
156