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

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: mattgiuca
  • Date: 2008-02-05 01:51:26 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:411
Renamed lib/fileservice to lib/fileservice_lib (naming conflict).
Added new app: fileservice. This app replaces the old one that was deleted -
it simply calls fileservice_lib.handle, and that's it (so it functions exactly
the same).

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
import mimetypes
68
68
import compileall
69
69
import getopt
70
 
import hashlib
71
 
import uuid
72
70
 
73
71
# Import modules from the website is tricky since they're in the www
74
72
# directory.
102
100
    '/bin/echo',
103
101
    # Needed by python
104
102
    '/usr/bin/python%s' % PYTHON_VERSION,
105
 
    # Needed by fileservice
106
 
    '/lib/libcom_err.so.2',
107
 
    '/lib/libcrypt.so.1',
108
 
    '/lib/libkeyutils.so.1',
109
 
    '/lib/libresolv.so.2',
110
 
    '/lib/librt.so.1',
111
 
    '/lib/libuuid.so.1',
112
 
    '/usr/lib/libapr-1.so.0',
113
 
    '/usr/lib/libaprutil-1.so.0',
114
 
    '/usr/lib/libdb-4.4.so',
115
 
    '/usr/lib/libexpat.so.1',
116
 
    '/usr/lib/libgcrypt.so.11',
117
 
    '/usr/lib/libgnutls.so.13',
118
 
    '/usr/lib/libgpg-error.so.0',
119
 
    '/usr/lib/libgssapi_krb5.so.2',
120
 
    '/usr/lib/libk5crypto.so.3',
121
 
    '/usr/lib/libkrb5.so.3',
122
 
    '/usr/lib/libkrb5support.so.0',
123
 
    '/usr/lib/liblber.so.2',
124
 
    '/usr/lib/libldap_r.so.2',
125
 
    '/usr/lib/libneon.so.26',
126
 
    '/usr/lib/libpq.so.5',
127
 
    '/usr/lib/libsasl2.so.2',
128
 
    '/usr/lib/libsqlite3.so.0',
129
 
    '/usr/lib/libsvn_client-1.so.1',
130
 
    '/usr/lib/libsvn_delta-1.so.1',
131
 
    '/usr/lib/libsvn_diff-1.so.1',
132
 
    '/usr/lib/libsvn_fs-1.so.1',
133
 
    '/usr/lib/libsvn_fs_base-1.so.1',
134
 
    '/usr/lib/libsvn_fs_fs-1.so.1',
135
 
    '/usr/lib/libsvn_ra-1.so.1',
136
 
    '/usr/lib/libsvn_ra_dav-1.so.1',
137
 
    '/usr/lib/libsvn_ra_local-1.so.1',
138
 
    '/usr/lib/libsvn_ra_svn-1.so.1',
139
 
    '/usr/lib/libsvn_repos-1.so.1',
140
 
    '/usr/lib/libsvn_subr-1.so.1',
141
 
    '/usr/lib/libsvn_wc-1.so.1',
142
 
    '/usr/lib/libtasn1.so.3',
143
 
    '/usr/lib/libxml2.so.2',
144
103
    # Needed by matplotlib
145
104
    '/usr/lib/i686/cmov/libssl.so.0.9.8',
146
105
    '/usr/lib/i686/cmov/libcrypto.so.0.9.8',
161
120
    '/usr/lib/libXdmcp.so.6',
162
121
    '/lib/libgcc_s.so.1',
163
122
    '/etc/matplotlibrc',
164
 
    # Needed for resolv
165
 
    '/lib/libnss_dns.so.2',
166
 
    '/lib/libnss_mdns4_minimal.so.2',
167
 
    '/etc/hosts',
168
 
    '/etc/resolv.conf',
169
 
    #'/etc/hosts.conf',
170
 
    #'/etc/hostname',
171
 
    '/etc/nsswitch.conf',
172
 
    '/lib/libnss_files.so.2',
173
123
]
174
124
# Symlinks to make within the jail. Src mapped to dst.
175
125
JAIL_LINKS = {
181
131
        'jail/usr/lib/python%s' % PYTHON_VERSION,
182
132
    '/usr/share/matplotlib': 'jail/usr/share/matplotlib',
183
133
    '/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
184
 
    '/usr/share/nltk': 'jail/usr/share/nltk',
185
134
}
186
135
 
187
136
class ConfigOption:
203
152
 
204
153
# Configuration options, defaults and descriptions
205
154
config_options = []
206
 
config_options.append(ConfigOption("root_dir", "/",
 
155
config_options.append(ConfigOption("root_dir", "/ivle",
207
156
    """Root directory where IVLE is located (in URL space):""",
208
157
    """
209
158
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
216
165
# In the local file system, where IVLE is actually installed.
217
166
# This directory should contain the "www" and "bin" directories."""))
218
167
config_options.append(ConfigOption("jail_base", "/home/informatics/jails",
219
 
    """Location of Directories
220
 
=======================
221
 
Root directory where the jails (containing user files) are stored
 
168
    """Root directory where the jails (containing user files) are stored
222
169
(on the local file system):""",
223
170
    """
224
171
# In the local file system, where are the student/user file spaces located.
232
179
# In the local file system, where are the per-subject file spaces located.
233
180
# The individual subject directories are expected to be located immediately
234
181
# in subdirectories of this location."""))
235
 
config_options.append(ConfigOption("exercises_base",
236
 
    "/home/informatics/exercises",
237
 
    """Root directory where the exercise directories (containing
238
 
subject-independent exercise sheets) are stored (on the local file
 
182
config_options.append(ConfigOption("problems_base",
 
183
    "/home/informatics/problems",
 
184
    """Root directory where the problem directories (containing
 
185
subject-independent problem sheets) are stored (on the local file
239
186
system):""",
240
187
    """
241
 
# In the local file system, where are the subject-independent exercise sheet
 
188
# In the local file system, where are the subject-independent problem sheet
242
189
# file spaces located."""))
243
 
config_options.append(ConfigOption("tos_path",
244
 
    "/home/informatics/tos.html",
245
 
    """Location where the Terms of Service document is stored (on the local
246
 
    file system):""",
247
 
    """
248
 
# In the local file system, where is the Terms of Service document located."""))
249
 
config_options.append(ConfigOption("motd_path",
250
 
    "/home/informatics/motd.html",
251
 
    """Location where the Message of the Day document is stored (on the local
252
 
    file system):""",
253
 
    """
254
 
# In the local file system, where is the Message of the Day document
255
 
# located. This is an HTML file (just the body fragment), which will
256
 
# be displayed on the login page. It is optional."""))
257
190
config_options.append(ConfigOption("public_host", "public.localhost",
258
191
    """Hostname which will cause the server to go into "public mode",
259
192
providing login-free access to student's published work:""",
289
222
    """Database name:""",
290
223
    """
291
224
# Database name"""))
292
 
config_options.append(ConfigOption("db_forumdbname", "ivle_forum",
293
 
    """Forum Database name:""",
294
 
    """
295
 
# Forum Database name"""))
296
225
config_options.append(ConfigOption("db_user", "postgres",
297
226
    """Username for DB server login:""",
298
227
    """
302
231
    (Caution: This password is stored in plaintext in lib/conf/conf.py)""",
303
232
    """
304
233
# Database password"""))
305
 
config_options.append(ConfigOption("auth_modules", "ldap_auth",
306
 
    """Authentication config
307
 
=====================
308
 
Comma-separated list of authentication modules. Only "ldap" is available
309
 
by default.""",
310
 
    """
311
 
# Comma-separated list of authentication modules.
312
 
# These refer to importable Python modules in the www/auth directory.
313
 
# Modules "ldap" and "guest" are available in the source tree, but
314
 
# other modules may be plugged in to auth against organisation-specific
315
 
# auth backends."""))
316
 
config_options.append(ConfigOption("ldap_url", "ldaps://www.example.com",
317
 
    """(LDAP options are only relevant if "ldap" is included in the list of
318
 
auth modules).
319
 
URL for LDAP authentication server:""",
320
 
    """
321
 
# URL for LDAP authentication server"""))
322
 
config_options.append(ConfigOption("ldap_format_string",
323
 
    "uid=%s,ou=users,o=example",
324
 
    """Format string for LDAP auth request:
325
 
    (Must contain a single "%s" for the user's login name)""",
326
 
    """
327
 
# Format string for LDAP auth request
328
 
# (Must contain a single "%s" for the user's login name)"""))
329
 
config_options.append(ConfigOption("svn_addr", "http://svn.localhost/",
330
 
    """Subversion config
331
 
=================
332
 
The base url for accessing subversion repositories:""",
333
 
    """
334
 
# The base url for accessing subversion repositories."""))
335
 
config_options.append(ConfigOption("svn_conf", "/opt/ivle/svn/svn.conf",
336
 
    """The location of the subversion configuration file used by apache
337
 
to host the user repositories:""",
338
 
    """
339
 
# The location of the subversion configuration file used by
340
 
# apache to host the user repositories."""))
341
 
config_options.append(ConfigOption("svn_repo_path", "/home/informatics/repositories",
342
 
    """The root directory for the subversion repositories:""",
343
 
    """
344
 
# The root directory for the subversion repositories."""))
345
 
config_options.append(ConfigOption("svn_auth_ivle", "/opt/ivle/svn/ivle.auth",
346
 
    """The location of the password file used to authenticate users
347
 
of the subversion repository from the ivle server:""",
348
 
    """
349
 
# The location of the password file used to authenticate users
350
 
# of the subversion repository from the ivle server."""))
351
 
config_options.append(ConfigOption("svn_auth_local", "/opt/ivle/svn/local.auth",
352
 
    """The location of the password file used to authenticate local users
353
 
of the subversion repository:""",
354
 
    """
355
 
# The location of the password file used to authenticate local users
356
 
# of the subversion repository."""))
357
 
config_options.append(ConfigOption("usrmgt_host", "localhost",
358
 
    """User Management Server config
359
 
============================
360
 
The hostname where the usrmgt-server runs:""",
361
 
    """
362
 
# The hostname where the usrmgt-server runs."""))
363
 
config_options.append(ConfigOption("usrmgt_port", "2178",
364
 
    """The port where the usrmgt-server runs:""",
365
 
    """
366
 
# The port where the usrmgt-server runs."""))
367
 
config_options.append(ConfigOption("usrmgt_magic", "",
368
 
    """The password for the usrmgt-server:""",
369
 
    """
370
 
# The password for the usrmgt-server."""))
371
234
 
372
235
# Try importing existing conf, but if we can't just set up defaults
373
236
# The reason for this is that these settings are used by other phases
398
261
# as necessary, and include it in the distribution.
399
262
listmake_mimetypes = ['text/x-python', 'text/html',
400
263
    'application/x-javascript', 'application/javascript',
401
 
    'text/css', 'image/png', 'image/gif', 'application/xml']
 
264
    'text/css', 'image/png', 'application/xml']
402
265
 
403
266
# Main function skeleton from Guido van Rossum
404
267
# http://www.artima.com/weblogs/viewpost.jsp?thread=4829
522
385
Copy subjects/ to subjects directory (unless --nosubjects specified).
523
386
 
524
387
--nojail        Do not copy the jail.
525
 
--nosubjects    Do not copy the subjects and exercises directories.
 
388
--nosubjects    Do not copy the subjects and problems directories.
526
389
--dry | -n  Print out the actions but don't do anything."""
527
390
    elif operation == 'updatejails':
528
391
        print """sudo python setup.py updatejails [--dry|-n]
540
403
    # We build two separate lists, by walking www and console
541
404
    list_www = build_list_py_files('www')
542
405
    list_lib = build_list_py_files('lib')
 
406
    list_console = build_list_py_files('console')
543
407
    list_subjects = build_list_py_files('subjects', no_top_level=True)
544
 
    list_exercises = build_list_py_files('exercises', no_top_level=True)
545
 
    list_scripts = [
546
 
        "scripts/python-console",
547
 
        "scripts/fileservice",
548
 
        "scripts/serveservice",
549
 
        "scripts/usrmgt-server",
550
 
        "scripts/diffservice",
551
 
    ]
 
408
    list_problems = build_list_py_files('problems', no_top_level=True)
552
409
    # Make sure that the files generated by conf are in the list
553
410
    # (since listmake is typically run before conf)
554
411
    if "lib/conf/conf.py" not in list_lib:
555
 
        list_lib.append("lib/conf/conf.py")
 
412
        list_www.append("lib/conf/conf.py")
 
413
    # Make sure that console/python-console is in the list
 
414
    if "console/python-console" not in list_console:
 
415
        list_console.append("console/python-console")
556
416
    # Write these out to a file
557
417
    cwd = os.getcwd()
558
418
    # the files that will be created/overwritten
576
436
list_lib = """)
577
437
        writelist_pretty(file, list_lib)
578
438
        file.write("""
579
 
# List of all installable files in scripts directory.
580
 
list_scripts = """)
581
 
        writelist_pretty(file, list_scripts)
 
439
# List of all installable files in console directory.
 
440
list_console = """)
 
441
        writelist_pretty(file, list_console)
582
442
        file.write("""
583
443
# List of all installable files in subjects directory.
584
444
# This is to install sample subjects and material.
585
445
list_subjects = """)
586
446
        writelist_pretty(file, list_subjects)
587
447
        file.write("""
588
 
# List of all installable files in exercises directory.
 
448
# List of all installable files in problems directory.
589
449
# This is to install sample exercise material.
590
 
list_exercises = """)
591
 
        writelist_pretty(file, list_exercises)
 
450
list_problems = """)
 
451
        writelist_pretty(file, list_problems)
592
452
 
593
453
        file.close()
594
454
    except IOError, (errno, strerror):
634
494
        file.write(']\n')
635
495
 
636
496
def conf(args):
637
 
    global db_port, usrmgt_port
 
497
    global db_port
638
498
    # Set up some variables
639
499
 
640
500
    cwd = os.getcwd()
641
501
    # the files that will be created/overwritten
642
502
    conffile = os.path.join(cwd, "lib/conf/conf.py")
643
 
    jailconffile = os.path.join(cwd, "lib/conf/jailconf.py")
644
503
    conf_hfile = os.path.join(cwd, "trampoline/conf.h")
645
 
    phpBBconffile = os.path.join(cwd, "www/php/phpBB3/config.php")
646
 
    usrmgtserver_initdfile = os.path.join(cwd, "doc/setup/usrmgt-server.init")
647
504
 
648
505
    # Get command-line arguments to avoid asking questions.
649
506
 
662
519
        print """This tool will create the following files:
663
520
    %s
664
521
    %s
665
 
    %s
666
 
    %s
667
 
    %s
668
522
prompting you for details about your configuration. The file will be
669
523
overwritten if it already exists. It will *not* install or deploy IVLE.
670
524
 
671
525
Please hit Ctrl+C now if you do not wish to do this.
672
 
""" % (conffile, jailconffile, conf_hfile, phpBBconffile, usrmgtserver_initdfile)
 
526
""" % (conffile, conf_hfile)
673
527
 
674
528
        # Get information from the administrator
675
529
        # If EOF is encountered at any time during the questioning, just exit
701
555
        "Invalid DB port (%s).\n"
702
556
        "Must be an integer between 0 and 65535." % repr(db_port))
703
557
        return 1
704
 
    try:
705
 
        usrmgt_port = int(usrmgt_port)
706
 
        if usrmgt_port < 0 or usrmgt_port >= 65536: raise ValueError()
707
 
    except ValueError:
708
 
        print >>sys.stderr, (
709
 
        "Invalid user management port (%s).\n"
710
 
        "Must be an integer between 0 and 65535." % repr(usrmgt_port))
711
 
        return 1
712
 
 
713
 
    # Generate the forum secret
714
 
    forum_secret = hashlib.md5(uuid.uuid4().bytes).hexdigest()
715
558
 
716
559
    # Write lib/conf/conf.py
717
560
 
727
570
            conf.write('%s\n%s = %s\n' % (opt.comment, opt.option_name,
728
571
                repr(globals()[opt.option_name])))
729
572
 
730
 
        # Add the forum secret to the config file (regenerated each config)
731
 
        conf.write('forum_secret = "%s"\n' % (forum_secret))
732
 
 
733
573
        conf.close()
734
574
    except IOError, (errno, strerror):
735
575
        print "IO error(%s): %s" % (errno, strerror)
737
577
 
738
578
    print "Successfully wrote lib/conf/conf.py"
739
579
 
740
 
    # Write conf/jailconf.py
741
 
 
742
 
    try:
743
 
        conf = open(jailconffile, "w")
744
 
 
745
 
        # In the "in-jail" version of conf, we don't need MOST of the details
746
 
        # (it would be a security risk to have them here).
747
 
        # So we just write root_dir, and jail_base is "/".
748
 
        # (jail_base being "/" means "jail-relative" paths are relative to "/"
749
 
        # when inside the jail.)
750
 
        conf.write("""# IVLE Configuration File
751
 
# conf.py
752
 
# Miscellaneous application settings
753
 
# (User jail version)
754
 
 
755
 
 
756
 
# In URL space, where in the site is IVLE located. (All URLs will be prefixed
757
 
# with this).
758
 
# eg. "/" or "/ivle".
759
 
root_dir = %s
760
 
 
761
 
# In the local file system, where are the student/user file spaces located.
762
 
# The user jails are expected to be located immediately in subdirectories of
763
 
# this location.
764
 
jail_base = '/'
765
 
 
766
 
# The hostname for serving publicly accessible pages
767
 
public_host = %s
768
 
""" % (repr(root_dir),repr(public_host)))
769
 
 
770
 
        conf.close()
771
 
    except IOError, (errno, strerror):
772
 
        print "IO error(%s): %s" % (errno, strerror)
773
 
        sys.exit(1)
774
 
 
775
 
    print "Successfully wrote lib/conf/jailconf.py"
776
 
 
777
580
    # Write trampoline/conf.h
778
581
 
779
582
    try:
797
600
 * (Note that root is an implicit member of this list).
798
601
 */
799
602
static const int allowed_uids[] = { %s };
800
 
""" % (repr(jail_base)[1:-1], repr(allowed_uids_list)[1:-1]))
801
 
    # Note: The above uses PYTHON reprs, not C reprs
802
 
    # However they should be the same with the exception of the outer
803
 
    # characters, which are stripped off and replaced
 
603
""" % (jail_base, repr(allowed_uids_list)[1:-1]))
804
604
 
805
605
        conf.close()
806
606
    except IOError, (errno, strerror):
809
609
 
810
610
    print "Successfully wrote trampoline/conf.h"
811
611
 
812
 
    # Write www/php/phpBB3/config.php
813
 
 
814
 
    try:
815
 
        conf = open(phpBBconffile, "w")
816
 
        
817
 
        # php-pg work around
818
 
        if db_host == 'localhost':
819
 
            forumdb_host = '127.0.0.1'
820
 
        else:
821
 
            forumdb_host = db_host
822
 
 
823
 
        conf.write( """<?php
824
 
// phpBB 3.0.x auto-generated configuration file
825
 
// Do not change anything in this file!
826
 
$dbms = 'postgres';
827
 
$dbhost = '""" + forumdb_host + """';
828
 
$dbport = '""" + str(db_port) + """';
829
 
$dbname = '""" + db_forumdbname + """';
830
 
$dbuser = '""" + db_user + """';
831
 
$dbpasswd = '""" + db_password + """';
832
 
 
833
 
$table_prefix = 'phpbb_';
834
 
$acm_type = 'file';
835
 
$load_extensions = '';
836
 
@define('PHPBB_INSTALLED', true);
837
 
// @define('DEBUG', true);
838
 
//@define('DEBUG_EXTRA', true);
839
 
 
840
 
$forum_secret = '""" + forum_secret +"""';
841
 
?>"""   )
842
 
    
843
 
        conf.close()
844
 
    except IOError, (errno, strerror):
845
 
        print "IO error(%s): %s" % (errno, strerror)
846
 
        sys.exit(1)
847
 
 
848
 
    print "Successfully wrote www/php/phpBB3/config.php"
849
 
 
850
 
    # Write lib/conf/usrmgt-server.init
851
 
 
852
 
    try:
853
 
        conf = open(usrmgtserver_initdfile, "w")
854
 
 
855
 
        conf.write( '''#! /bin/sh
856
 
 
857
 
# Works for Ubuntu. Check before using on other distributions
858
 
 
859
 
### BEGIN INIT INFO
860
 
# Provides:          usrmgt-server
861
 
# Required-Start:    $syslog $networking $urandom
862
 
# Required-Stop:     $syslog
863
 
# Default-Start:     2 3 4 5
864
 
# Default-Stop:      1
865
 
# Short-Description: IVLE user management server
866
 
# Description:       Daemon connecting to the IVLE user management database.
867
 
### END INIT INFO
868
 
 
869
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin
870
 
DESC="IVLE user management server"
871
 
NAME=usrmgt-server
872
 
DAEMON=/opt/ivle/scripts/$NAME
873
 
DAEMON_ARGS="''' + str(usrmgt_port) + ''' ''' + usrmgt_magic + '''"
874
 
PIDFILE=/var/run/$NAME.pid
875
 
SCRIPTNAME=/etc/init.d/usrmgt-server
876
 
 
877
 
# Exit if the daemon does not exist 
878
 
test -f $DAEMON || exit 0
879
 
 
880
 
# Load the VERBOSE setting and other rcS variables
881
 
[ -f /etc/default/rcS ] && . /etc/default/rcS
882
 
 
883
 
# Define LSB log_* functions.
884
 
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
885
 
. /lib/lsb/init-functions
886
 
 
887
 
#
888
 
# Function that starts the daemon/service
889
 
#
890
 
do_start()
891
 
{
892
 
        # Return
893
 
        #   0 if daemon has been started
894
 
        #   1 if daemon was already running
895
 
        #   2 if daemon could not be started
896
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
897
 
                || return 1
898
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
899
 
                $DAEMON_ARGS \
900
 
                || return 2
901
 
        # Add code here, if necessary, that waits for the process to be ready
902
 
        # to handle requests from services started subsequently which depend
903
 
        # on this one.  As a last resort, sleep for some time.
904
 
}
905
 
 
906
 
#
907
 
# Function that stops the daemon/service
908
 
#
909
 
do_stop()
910
 
{
911
 
        # Return
912
 
        #   0 if daemon has been stopped
913
 
        #   1 if daemon was already stopped
914
 
        #   2 if daemon could not be stopped
915
 
        #   other if a failure occurred
916
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
917
 
        RETVAL="$?"
918
 
        [ "$RETVAL" = 2 ] && return 2
919
 
        # Wait for children to finish too if this is a daemon that forks
920
 
        # and if the daemon is only ever run from this initscript.
921
 
        # If the above conditions are not satisfied then add some other code
922
 
        # that waits for the process to drop all resources that could be
923
 
        # needed by services started subsequently.  A last resort is to
924
 
        # sleep for some time.
925
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
926
 
        [ "$?" = 2 ] && return 2
927
 
        # Many daemons don't delete their pidfiles when they exit.
928
 
        rm -f $PIDFILE
929
 
        return "$RETVAL"
930
 
}
931
 
 
932
 
#
933
 
# Function that sends a SIGHUP to the daemon/service
934
 
#
935
 
do_reload() {
936
 
        #
937
 
        # If the daemon can reload its configuration without
938
 
        # restarting (for example, when it is sent a SIGHUP),
939
 
        # then implement that here.
940
 
        #
941
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
942
 
        return 0
943
 
}
944
 
 
945
 
case "$1" in
946
 
  start)
947
 
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
948
 
        do_start
949
 
        case "$?" in
950
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
951
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
952
 
        esac
953
 
        ;;
954
 
  stop)
955
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
956
 
        do_stop
957
 
        case "$?" in
958
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
959
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
960
 
        esac
961
 
        ;;
962
 
  #reload|force-reload)
963
 
        #
964
 
        # If do_reload() is not implemented then leave this commented out
965
 
        # and leave 'force-reload' as an alias for 'restart'.
966
 
        #
967
 
        #log_daemon_msg "Reloading $DESC" "$NAME"
968
 
        #do_reload
969
 
        #log_end_msg $?
970
 
        #;;
971
 
  restart|force-reload)
972
 
        #
973
 
        # If the "reload" option is implemented then remove the
974
 
        # 'force-reload' alias
975
 
        #
976
 
        log_daemon_msg "Restarting $DESC" "$NAME"
977
 
        do_stop
978
 
        case "$?" in
979
 
          0|1)
980
 
                do_start
981
 
                case "$?" in
982
 
                        0) log_end_msg 0 ;;
983
 
                        1) log_end_msg 1 ;; # Old process is still running
984
 
                        *) log_end_msg 1 ;; # Failed to start
985
 
                esac
986
 
                ;;
987
 
          *)
988
 
                # Failed to stop
989
 
                log_end_msg 1
990
 
                ;;
991
 
        esac
992
 
        ;;
993
 
  *)
994
 
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
995
 
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
996
 
        exit 3
997
 
        ;;
998
 
esac
999
 
 
1000
 
:
1001
 
''')
1002
 
        
1003
 
        conf.close()
1004
 
    except IOError, (errno, strerror):
1005
 
        print "IO error(%s): %s" % (errno, strerror)
1006
 
        sys.exit(1)
1007
 
 
1008
 
    # fix permissions as the file contains the database password
1009
 
    try:
1010
 
        os.chmod('doc/setup/usrmgt-server.init', 0600)
1011
 
    except OSError, (errno, strerror):
1012
 
        print "WARNING: Couldn't chmod doc/setup/usrmgt-server.init:"
1013
 
        print "OS error(%s): %s" % (errno, strerror)
1014
 
 
1015
 
    print "Successfully wrote lib/conf/usrmgt-server.init"
1016
 
 
1017
612
    print
1018
613
    print "You may modify the configuration at any time by editing"
1019
614
    print conffile
1020
 
    print jailconffile
1021
615
    print conf_hfile
1022
 
    print phpBBconffile
1023
 
    print usrmgtserver_initdfile
1024
616
    print
1025
617
    return 0
1026
618
 
1045
637
    action_mkdir('jail/home', dry)
1046
638
    action_mkdir('jail/tmp', dry)
1047
639
 
1048
 
    # Chmod the tmp directory to world writable
1049
 
    action_chmod_w('jail/tmp', dry)
1050
 
 
1051
640
    # Copy all console and operating system files into the jail
1052
 
    action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
 
641
    action_copylist(install_list.list_console, 'jail/opt/ivle', dry)
1053
642
    copy_os_files_jail(dry)
1054
643
    # Chmod the python console
1055
 
    action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
1056
 
    action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
1057
 
    action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
 
644
    action_chmod_x('jail/opt/ivle/console/python-console', dry)
1058
645
    
1059
 
    # Also copy the IVLE lib directory into the jail
1060
 
    # This is necessary for running certain scripts
1061
 
    action_copylist(install_list.list_lib, 'jail/opt/ivle', dry)
1062
 
    # IMPORTANT: The file jail/opt/ivle/lib/conf/conf.py contains details
1063
 
    # which could compromise security if left in the jail (such as the DB
1064
 
    # password).
1065
 
    # The "safe" version is in jailconf.py. Delete conf.py and replace it with
1066
 
    # jailconf.py.
1067
 
    action_copyfile('lib/conf/jailconf.py',
1068
 
        'jail/opt/ivle/lib/conf/conf.py', dry)
1069
646
 
1070
647
    # Compile .py files into .pyc or .pyo files
1071
648
    compileall.compile_dir('www', quiet=True)
1072
 
    compileall.compile_dir('lib', quiet=True)
1073
 
    compileall.compile_dir('scripts', quiet=True)
1074
 
    compileall.compile_dir('jail/opt/ivle/lib', quiet=True)
1075
 
 
1076
 
    # Set up ivle.pth inside the jail
1077
 
    # Need to set /opt/ivle/lib to be on the import path
1078
 
    ivle_pth = \
1079
 
        "jail/usr/lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION
1080
 
    f = open(ivle_pth, 'w')
1081
 
    f.write('/opt/ivle/lib\n')
1082
 
    f.close()
 
649
    compileall.compile_dir('console', quiet=True)
1083
650
 
1084
651
    return 0
1085
652
 
1127
694
    # chown trampoline to root and set setuid bit
1128
695
    action_chown_setuid(tramppath, dry)
1129
696
 
1130
 
    # Create a scripts directory to put the usrmgt-server in.
1131
 
    action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
1132
 
    usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
1133
 
    action_copyfile('scripts/usrmgt-server', usrmgtpath, dry)
1134
 
    action_chmod_x(usrmgtpath, dry)
1135
 
 
1136
697
    # Copy the www and lib directories using the list
1137
698
    action_copylist(install_list.list_www, ivle_install_dir, dry)
1138
699
    action_copylist(install_list.list_lib, ivle_install_dir, dry)
1139
 
    
1140
 
    # Copy the php directory
1141
 
    forum_dir = "www/php/phpBB3"
1142
 
    forum_path = os.path.join(ivle_install_dir, forum_dir)
1143
 
    action_copytree(forum_dir, forum_path, dry)
1144
 
    print "chown -R www-data:www-data %s" % forum_path
1145
 
    if not dry:
1146
 
        os.system("chown -R www-data:www-data %s" % forum_path)
1147
700
 
1148
701
    if not nojail:
1149
702
        # Copy the local jail directory built by the build action
1151
704
        # for all the students' jails).
1152
705
        action_copytree('jail', os.path.join(jail_base, 'template'), dry)
1153
706
    if not nosubjects:
1154
 
        # Copy the subjects and exercises directories across
 
707
        # Copy the subjects and problems directories across
1155
708
        action_copylist(install_list.list_subjects, subjects_base, dry,
1156
709
            srcdir="./subjects")
1157
 
        action_copylist(install_list.list_exercises, exercises_base, dry,
1158
 
            srcdir="./exercises")
 
710
        action_copylist(install_list.list_problems, problems_base, dry,
 
711
            srcdir="./problems")
1159
712
 
1160
713
    # Append IVLE path to ivle.pth in python site packages
1161
714
    # (Unless it's already there)
1246
799
    if ret != 0:
1247
800
        raise RunError(prog, ret)
1248
801
 
1249
 
def action_remove(path, dry):
1250
 
    """Calls rmtree, deleting the target file if it exists."""
1251
 
    try:
1252
 
        print "rm -r", path
1253
 
        if not dry:
1254
 
            shutil.rmtree(path, True)
1255
 
    except OSError, (err, msg):
1256
 
        if err != errno.EEXIST:
1257
 
            raise
1258
 
        # Otherwise, didn't exist, so we don't care
1259
 
 
1260
802
def action_rename(src, dst, dry):
1261
803
    """Calls rename. Deletes the target if it already exists."""
1262
 
    action_remove(dst, dry)
 
804
    if os.access(dst, os.F_OK):
 
805
        print "rm -r", dst
 
806
        if not dry:
 
807
            shutil.rmtree(dst, True)
1263
808
    print "mv ", src, dst
1264
809
    if dry: return
1265
810
    try:
1285
830
    directories as necessary.
1286
831
 
1287
832
    See shutil.copytree."""
1288
 
    # Allow copying over itself
1289
 
    if (os.path.normpath(os.path.join(os.getcwd(),src)) ==
1290
 
        os.path.normpath(os.path.join(os.getcwd(),dst))):
1291
 
        return
1292
 
    action_remove(dst, dry)
 
833
    if os.access(dst, os.F_OK):
 
834
        print "rm -r", dst
 
835
        if not dry:
 
836
            shutil.rmtree(dst, True)
1293
837
    print "cp -r", src, dst
1294
838
    if dry: return
1295
839
    shutil.copytree(src, dst, True)
1298
842
    """Hard-links an entire directory tree. Same as copytree but the created
1299
843
    files are hard-links not actual copies. Removes the existing destination.
1300
844
    """
1301
 
    action_remove(dst, dry)
 
845
    if os.access(dst, os.F_OK):
 
846
        print "rm -r", dst
 
847
        if not dry:
 
848
            shutil.rmtree(dst, True)
1302
849
    print "<cp with hardlinks> -r", src, dst
1303
850
    if dry: return
1304
851
    common.makeuser.linktree(src, dst)
1379
926
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
1380
927
            | stat.S_IXGRP | stat.S_IRGRP | stat.S_IXOTH | stat.S_IROTH)
1381
928
 
1382
 
 
1383
 
def action_chmod_w(file, dry):
1384
 
    """Chmod 777 a file (sets permissions to rwxrwxrwx)."""
1385
 
    print "chmod 777", file
1386
 
    if not dry:
1387
 
        os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR
1388
 
            | stat.S_IXGRP | stat.S_IWGRP | stat.S_IRGRP | stat.S_IXOTH
1389
 
            | stat.S_IWOTH | stat.S_IROTH)
1390
 
 
1391
929
def query_user(default, prompt):
1392
930
    """Prompts the user for a string, which is read from a line of stdin.
1393
931
    Exits silently if EOF is encountered. Returns the string, with spaces