71
# Import modules from the website is tricky since they're in the www
73
sys.path.append(os.path.join(os.getcwd(), 'www'))
75
import common.makeuser
77
# Determine which Python version (2.4 or 2.5, for example) we are running,
78
# and use that as the filename to the Python directory.
79
# Just get the first 3 characters of sys.version.
80
PYTHON_VERSION = sys.version[0:3]
82
# Operating system files to copy over into the jail.
83
# These will be copied from the given place on the OS file system into the
84
# same place within the jail.
87
'/lib/tls/i686/cmov/libc.so.6',
88
'/lib/tls/i686/cmov/libdl.so.2',
89
'/lib/tls/i686/cmov/libm.so.6',
90
'/lib/tls/i686/cmov/libpthread.so.0',
91
'/lib/tls/i686/cmov/libutil.so.1',
94
# These 2 files do not exist in Ubuntu
95
#'/etc/ld.so.preload',
96
#'/etc/ld.so.nohwcap',
102
'/usr/bin/python%s' % PYTHON_VERSION,
103
# Needed by matplotlib
104
'/usr/lib/i686/cmov/libssl.so.0.9.8',
105
'/usr/lib/i686/cmov/libcrypto.so.0.9.8',
106
'/lib/tls/i686/cmov/libnsl.so.1',
107
'/usr/lib/libz.so.1',
108
'/usr/lib/atlas/liblapack.so.3',
109
'/usr/lib/atlas/libblas.so.3',
110
'/usr/lib/libg2c.so.0',
111
'/usr/lib/libstdc++.so.6',
112
'/usr/lib/libfreetype.so.6',
113
'/usr/lib/libpng12.so.0',
114
'/usr/lib/libBLT.2.4.so.8.4',
115
'/usr/lib/libtk8.4.so.0',
116
'/usr/lib/libtcl8.4.so.0',
117
'/usr/lib/tcl8.4/init.tcl',
118
'/usr/lib/libX11.so.6',
119
'/usr/lib/libXau.so.6',
120
'/usr/lib/libXdmcp.so.6',
121
'/lib/libgcc_s.so.1',
124
# Symlinks to make within the jail. Src mapped to dst.
126
'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
128
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
130
'/usr/lib/python%s' % PYTHON_VERSION:
131
'jail/usr/lib/python%s' % PYTHON_VERSION,
132
'/usr/share/matplotlib': 'jail/usr/share/matplotlib',
133
'/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
71
136
# Try importing existing conf, but if we can't just set up defaults
72
137
# The reason for this is that these settings are used by other phases
73
138
# of setup besides conf, so we need to know them.
74
139
# Also this allows you to hit Return to accept the existing value.
76
141
confmodule = __import__("www/conf/conf")
77
root_dir = confmodule.root_dir
78
ivle_install_dir = confmodule.ivle_install_dir
79
jail_base = confmodule.jail_base
143
root_dir = confmodule.root_dir
147
ivle_install_dir = confmodule.ivle_install_dir
149
ivle_install_dir = "/opt/ivle"
151
public_host = confmodule.public_host
153
public_host = "public.localhost"
155
jail_base = confmodule.jail_base
157
jail_base = "/home/informatics/jails"
159
subjects_base = confmodule.subjects_base
161
subjects_base = "/home/informatics/subjects"
80
162
except ImportError:
81
163
# Just set reasonable defaults
82
164
root_dir = "/ivle"
83
165
ivle_install_dir = "/opt/ivle"
166
public_host = "public.localhost"
84
167
jail_base = "/home/informatics/jails"
168
subjects_base = "/home/informatics/subjects"
86
170
allowed_uids = "0"
176
262
be copied upon installation. This should be run by the developer before
177
263
cutting a distribution, and the listfile it generates should be included in
178
264
the distribution, avoiding the administrator having to run it."""
179
elif operation == 'conf':
180
print """python setup.py conf [args]
265
elif operation == 'config':
266
print """python setup.py config [args]
181
267
Configures IVLE with machine-specific details, most notably, various paths.
182
268
Either prompts the administrator for these details or accepts them as
183
269
command-line args. Will be interactive only if there are no arguments given.
219
307
chown and chmod the installed trampoline.
220
308
Copy www/ to $target.
221
309
Copy jail/ to jails template directory (unless --nojail specified).
223
--nojail Do not copy the jail.
310
Copy subjects/ to subjects directory (unless --nosubjects specified).
312
--nojail Do not copy the jail.
313
--nosubjects Do not copy the subjects.
314
--dry | -n Print out the actions but don't do anything."""
315
elif operation == 'updatejails':
316
print """sudo python setup.py updatejails [--dry|-n]
318
Copy jail/ to each subdirectory in jails directory.
224
320
--dry | -n Print out the actions but don't do anything."""
226
322
print >>sys.stderr, (
344
450
jail_base = query_user(jail_base,
345
451
"""Root directory where the jails (containing user files) are stored
346
452
(on the local file system):""")
453
subjects_base = query_user(subjects_base,
454
"""Root directory where the subject directories (containing worksheets
455
and other per-subject files) are stored (on the local file system):""")
456
public_host = query_user(public_host,
457
"""Hostname which will cause the server to go into "public mode",
458
providing login-free access to student's published work:""")
347
459
allowed_uids = query_user(allowed_uids,
348
460
"""UID of the web server process which will run IVLE.
349
461
Only this user may execute the trampoline. May specify multiple users as
390
506
# This directory should contain the "www" and "bin" directories.
391
507
ivle_install_dir = "%s"
509
# The server goes into "public mode" if the browser sends a request with this
510
# host. This is for security reasons - we only serve public student files on a
511
# separate domain to the main IVLE site.
512
# Public mode does not use cookies, and serves only public content.
513
# Private mode (normal mode) requires login, and only serves files relevant to
514
# the logged-in user.
393
517
# In the local file system, where are the student/user file spaces located.
394
518
# The user jails are expected to be located immediately in subdirectories of
398
# Which application to load by default (if the user navigates to the top level
399
# of the site). This is the app's URL name.
400
# Note that if this app requires authentication, the user will first be
401
# presented with the login screen.
403
""" % (root_dir, ivle_install_dir, jail_base, default_app))
522
# In the local file system, where are the per-subject file spaces located.
523
# The individual subject directories are expected to be located immediately
524
# in subdirectories of this location.
526
""" % (root_dir, ivle_install_dir, public_host, jail_base, subjects_base))
406
529
except IOError, (errno, strerror):
481
607
"""Copies necessary Operating System files from their usual locations
482
608
into the jail/ directory of the cwd."""
483
609
# Currently source paths are configured for Ubuntu.
484
copy_file_to_jail('/lib/ld-linux.so.2', dry)
485
copy_file_to_jail('/lib/tls/i686/cmov/libc.so.6', dry)
486
copy_file_to_jail('/lib/tls/i686/cmov/libdl.so.2', dry)
487
copy_file_to_jail('/lib/tls/i686/cmov/libm.so.6', dry)
488
copy_file_to_jail('/lib/tls/i686/cmov/libpthread.so.0', dry)
489
copy_file_to_jail('/lib/tls/i686/cmov/libutil.so.1', dry)
490
copy_file_to_jail('/usr/bin/python2.5', dry)
491
action_symlink('python2.5', 'jail/usr/bin/python', dry)
492
action_copytree('/usr/lib/python2.5', 'jail/usr/lib/python2.5', dry)
610
for filename in JAIL_FILES:
611
copy_file_to_jail(filename, dry)
612
for src, dst in JAIL_LINKS.items():
613
action_symlink(src, dst, dry)
614
for src, dst in JAIL_COPYTREES.items():
615
action_copytree(src, dst, dry)
494
617
def copy_file_to_jail(src, dry):
495
618
"""Copies a single file from an absolute location into the same location
500
623
def install(args):
501
624
# Get "dry" and "nojail" variables from command line
502
(opts, args) = getopt.gnu_getopt(args, "n", ['dry', 'nojail'])
625
(opts, args) = getopt.gnu_getopt(args, "n",
626
['dry', 'nojail', 'nosubjects'])
503
627
opts = dict(opts)
504
628
dry = '-n' in opts or '--dry' in opts
505
629
nojail = '--nojail' in opts
630
nosubjects = '--nosubjects' in opts
508
633
print "Dry run (no actions will be executed\n"
530
655
# to the jails template directory (it will be used as a template
531
656
# for all the students' jails).
532
657
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
659
# Copy the subjects directory across
660
action_copylist(install_list.list_subjects, subjects_base, dry,
663
# Append IVLE path to ivle.pth in python site packages
664
# (Unless it's already there)
665
ivle_pth = os.path.join(sys.prefix,
666
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
667
ivle_www = os.path.join(ivle_install_dir, "www")
668
write_ivle_pth = True
670
file = open(ivle_pth, 'r')
672
if line.strip() == ivle_www:
673
write_ivle_pth = False
675
except (IOError, OSError):
678
action_append(ivle_pth, ivle_www)
682
def updatejails(args):
683
# Get "dry" variable from command line
684
(opts, args) = getopt.gnu_getopt(args, "n", ['dry'])
686
dry = '-n' in opts or '--dry' in opts
689
print "Dry run (no actions will be executed\n"
691
if not dry and os.geteuid() != 0:
692
print >>sys.stderr, "Must be root to run install"
693
print >>sys.stderr, "(I need to chown some files)."
696
# Update the template jail directory in case it hasn't been installed
698
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
700
# Re-link all the files in all students jails.
701
for dir in os.listdir(jail_base):
702
if dir == 'template': continue
703
# First back up the student's home directory
704
temp_home = os.tmpnam()
705
action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
706
# Delete the student's jail and relink the jail files
707
action_linktree(os.path.join(jail_base, 'template'),
708
os.path.join(jail_base, dir), dry)
709
# Restore the student's home directory
710
action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)
711
# Set up the user's home directory just in case they don't have a
712
# directory for this yet
713
action_mkdir(os.path.join(jail_base, dir, 'home', dir), dry)
563
744
raise RunError(prog, ret)
746
def action_rename(src, dst, dry):
747
"""Calls rename. Deletes the target if it already exists."""
748
if os.access(dst, os.F_OK):
751
shutil.rmtree(dst, True)
752
print "mv ", src, dst
756
except OSError, (err, msg):
757
if err != errno.EEXIST:
565
760
def action_mkdir(path, dry):
566
761
"""Calls mkdir. Silently ignored if the directory already exists.
567
762
Creates all parent directories as necessary."""
588
783
shutil.copytree(src, dst, True)
590
def action_copylist(srclist, dst, dry):
785
def action_linktree(src, dst, dry):
786
"""Hard-links an entire directory tree. Same as copytree but the created
787
files are hard-links not actual copies. Removes the existing destination.
789
if os.access(dst, os.F_OK):
792
shutil.rmtree(dst, True)
793
print "<cp with hardlinks> -r", src, dst
795
common.makeuser.linktree(src, dst)
797
def action_copylist(srclist, dst, dry, srcdir="."):
591
798
"""Copies all files in a list to a new location. The files in the list
592
799
are read relative to the current directory, and their destinations are the
593
800
same paths relative to dst. Creates all parent directories as necessary.
801
srcdir is "." by default, can be overridden.
595
803
for srcfile in srclist:
596
804
dstfile = os.path.join(dst, srcfile)
805
srcfile = os.path.join(srcdir, srcfile)
597
806
dstdir = os.path.split(dstfile)[0]
598
807
if not os.path.isdir(dstdir):
599
808
action_mkdir(dstdir, dry)
648
863
os.chmod(file, stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
649
864
| stat.S_ISUID | stat.S_IRUSR | stat.S_IWUSR)
866
def action_chmod_x(file, dry):
867
"""Chmod +xs a file (sets execute permission)."""
868
print "chmod u+rwx", file
870
os.chmod(file, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR)
651
872
def query_user(default, prompt):
652
873
"""Prompts the user for a string, which is read from a line of stdin.
653
874
Exits silently if EOF is encountered. Returns the string, with spaces