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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: dcoles
  • Date: 2008-07-18 02:40:58 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:912
Makeuser: Makeuser will now chown all files in a users home directory to the
unixid provided by the database. This means remakeallusers.py can be used to
update everyones unixids after a database change. The makeuser script will also 
no longer generate a random unixid when one is not given on the command line.

Database: Change to database so that a sequence is used by default. The allowed  
range is 1000-29999 (let's start at 5000, because 1000+ is used by adduser.  
Reference: http://www.debian.org/doc/debian-policy/ch-opersys.html)
See SF Bug '[ 2012190 ] Student UID generation'
Migration script will reallocate all users a new unixid from the sequence.

Usermgt-Server: Now no longer generates a random unixid. Rely on the database 
to come up with a new sequence number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE - Informatics Virtual Learning Environment
 
2
# Copyright (C) 2007-2008 The University of Melbourne
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
# Module: setup/install
 
19
# Author: Matt Giuca, Refactored by David Coles
 
20
# Date:   03/07/2008
 
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
import optparse
 
34
import os
 
35
from setuputil import *
 
36
 
 
37
def install(args):
 
38
    usage = """usage: %prog install [options]
 
39
(Requires root)
 
40
Create target install directory ($target).
 
41
Create $target/bin.
 
42
Copy trampoline/trampoline to $target/bin.
 
43
Copy timount/timount to $target/bin.
 
44
chown and chmod the installed trampoline.
 
45
Copy www/ to $target.
 
46
Copy jail/ to jail_system directory (unless --nojail specified).
 
47
Copy subjects/ to subjects directory (unless --nosubjects specified).
 
48
"""
 
49
 
 
50
    # Parse arguments
 
51
    parser = optparse.OptionParser(usage)
 
52
    parser.add_option("-n", "--dry",
 
53
        action="store_true", dest="dry",
 
54
        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.")
 
61
    (options, args) = parser.parse_args(args)
 
62
 
 
63
    # 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
 
78
 
 
79
    # Must be run as root or a dry run  
 
80
    if dry:
 
81
        print "Dry run (no actions will be executed)\n"
 
82
    
 
83
    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)."
 
86
        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)
 
95
    # 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
    # Copy the php directory
 
112
    forum_dir = "www/php/phpBB3"
 
113
    forum_path = os.path.join(ivle_install_dir, forum_dir)
 
114
    action_copytree(forum_dir, forum_path, dry)
 
115
    print "chown -R www-data:www-data %s" % forum_path
 
116
    if not dry:
 
117
        os.system("chown -R www-data:www-data %s" % forum_path)
 
118
 
 
119
    if not nojail:
 
120
        # Copy the local jail directory built by the build action
 
121
        # to the jail_system directory (it will be used to help build
 
122
        # all the students' jails).
 
123
        action_copytree('jail', jail_system, dry)
 
124
    if not nosubjects:
 
125
        # Copy the subjects and exercises directories across
 
126
        action_copylist(install_list.list_subjects, subjects_base, dry,
 
127
            srcdir="./subjects")
 
128
        action_copylist(install_list.list_exercises, exercises_base, dry,
 
129
            srcdir="./exercises")
 
130
 
 
131
    # Append IVLE path to ivle.pth in python site packages
 
132
    # (Unless it's already there)
 
133
    ivle_pth = os.path.join(sys.prefix,
 
134
        "lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
 
135
    ivle_www = os.path.join(ivle_install_dir, "www")
 
136
    ivle_lib = os.path.join(ivle_install_dir, "lib")
 
137
    write_ivle_pth = True
 
138
    write_ivle_lib_pth = True
 
139
    try:
 
140
        file = open(ivle_pth, 'r')
 
141
        for line in file:
 
142
            if line.strip() == ivle_www:
 
143
                write_ivle_pth = False
 
144
            elif line.strip() == ivle_lib:
 
145
                write_ivle_lib_pth = False
 
146
        file.close()
 
147
    except (IOError, OSError):
 
148
        pass
 
149
    if write_ivle_pth:
 
150
        action_append(ivle_pth, ivle_www)
 
151
    if write_ivle_lib_pth:
 
152
        action_append(ivle_pth, ivle_lib)
 
153
 
 
154
 
 
155
    # Create the ivle working revision record file
 
156
    action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
 
157
    ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
 
158
    if not dry:
 
159
        try:
 
160
            conf = open(ivle_revision_record_file, "w")
 
161
 
 
162
            conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
 
163
 
 
164
            conf.close()
 
165
        except IOError, (errno, strerror):
 
166
            print "IO error(%s): %s" % (errno, strerror)
 
167
            sys.exit(1)
 
168
 
 
169
        os.system("svn status -v . >> %s" % ivle_revision_record_file)
 
170
 
 
171
    print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
 
172
 
 
173
    return 0
 
174