82
79
# Just get the first 3 characters of sys.version.
83
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 fileservice
104
'/lib/libcom_err.so.2',
105
'/lib/libcrypt.so.1',
106
'/lib/libkeyutils.so.1',
107
'/lib/libresolv.so.2',
110
'/usr/lib/libapr-1.so.0',
111
'/usr/lib/libaprutil-1.so.0',
112
'/usr/lib/libdb-4.4.so',
113
'/usr/lib/libexpat.so.1',
114
'/usr/lib/libgcrypt.so.11',
115
'/usr/lib/libgnutls.so.13',
116
'/usr/lib/libgpg-error.so.0',
117
'/usr/lib/libgssapi_krb5.so.2',
118
'/usr/lib/libk5crypto.so.3',
119
'/usr/lib/libkrb5.so.3',
120
'/usr/lib/libkrb5support.so.0',
121
'/usr/lib/liblber.so.2',
122
'/usr/lib/libldap_r.so.2',
123
'/usr/lib/libneon.so.26',
124
'/usr/lib/libpq.so.5',
125
'/usr/lib/libsasl2.so.2',
126
'/usr/lib/libsqlite3.so.0',
127
'/usr/lib/libsvn_client-1.so.1',
128
'/usr/lib/libsvn_delta-1.so.1',
129
'/usr/lib/libsvn_diff-1.so.1',
130
'/usr/lib/libsvn_fs-1.so.1',
131
'/usr/lib/libsvn_fs_base-1.so.1',
132
'/usr/lib/libsvn_fs_fs-1.so.1',
133
'/usr/lib/libsvn_ra-1.so.1',
134
'/usr/lib/libsvn_ra_dav-1.so.1',
135
'/usr/lib/libsvn_ra_local-1.so.1',
136
'/usr/lib/libsvn_ra_svn-1.so.1',
137
'/usr/lib/libsvn_repos-1.so.1',
138
'/usr/lib/libsvn_subr-1.so.1',
139
'/usr/lib/libsvn_wc-1.so.1',
140
'/usr/lib/libtasn1.so.3',
141
'/usr/lib/libxml2.so.2',
142
# Needed by matplotlib
143
'/usr/lib/i686/cmov/libssl.so.0.9.8',
144
'/usr/lib/i686/cmov/libcrypto.so.0.9.8',
145
'/lib/tls/i686/cmov/libnsl.so.1',
146
'/usr/lib/libz.so.1',
147
'/usr/lib/atlas/liblapack.so.3',
148
'/usr/lib/atlas/libblas.so.3',
149
'/usr/lib/libg2c.so.0',
150
'/usr/lib/libstdc++.so.6',
151
'/usr/lib/libfreetype.so.6',
152
'/usr/lib/libpng12.so.0',
153
'/usr/lib/libBLT.2.4.so.8.4',
154
'/usr/lib/libtk8.4.so.0',
155
'/usr/lib/libtcl8.4.so.0',
156
'/usr/lib/tcl8.4/init.tcl',
157
'/usr/lib/libX11.so.6',
158
'/usr/lib/libXau.so.6',
159
'/usr/lib/libXdmcp.so.6',
160
'/lib/libgcc_s.so.1',
163
'/lib/libnss_dns.so.2',
164
#'/lib/libnss_mdns4.so',
169
'/etc/nsswitch.conf',
170
'/lib/libnss_files.so.2',
172
# Symlinks to make within the jail. Src mapped to dst.
174
'python%s' % PYTHON_VERSION: 'jail/usr/bin/python',
176
# Trees to copy. Src mapped to dst (these will be passed to action_copytree).
178
'/usr/lib/python%s' % PYTHON_VERSION:
179
'jail/usr/lib/python%s' % PYTHON_VERSION,
180
'/usr/share/matplotlib': 'jail/usr/share/matplotlib',
181
'/etc/ld.so.conf.d': 'jail/etc/ld.so.conf.d',
85
184
class ConfigOption:
86
185
"""A configuration option; one of the things written to conf.py."""
87
186
def __init__(self, option_name, default, prompt, comment):
139
238
# In the local file system, where are the subject-independent exercise sheet
140
239
# file spaces located."""))
141
config_options.append(ConfigOption("tos_path",
142
"/home/informatics/tos.html",
143
"""Location where the Terms of Service document is stored (on the local
146
# In the local file system, where is the Terms of Service document located."""))
147
config_options.append(ConfigOption("motd_path",
148
"/home/informatics/motd.html",
149
"""Location where the Message of the Day document is stored (on the local
152
# In the local file system, where is the Message of the Day document
153
# located. This is an HTML file (just the body fragment), which will
154
# be displayed on the login page. It is optional."""))
155
240
config_options.append(ConfigOption("public_host", "public.localhost",
156
241
"""Hostname which will cause the server to go into "public mode",
157
242
providing login-free access to student's published work:""",
747
819
print "Successfully wrote www/php/phpBB3/config.php"
749
# Write lib/conf/usrmgt-server.init
752
conf = open(usrmgtserver_initdfile, "w")
754
conf.write( '''#! /bin/sh
756
# Works for Ubuntu. Check before using on other distributions
759
# Provides: usrmgt-server
760
# Required-Start: $syslog $networking $urandom
761
# Required-Stop: $syslog
762
# Default-Start: 2 3 4 5
764
# Short-Description: IVLE user management server
765
# Description: Daemon connecting to the IVLE user management database.
768
PATH=/sbin:/bin:/usr/sbin:/usr/bin
769
DESC="IVLE user management server"
771
DAEMON=/opt/ivle/scripts/$NAME
772
DAEMON_ARGS="''' + str(usrmgt_port) + ''' ''' + usrmgt_magic + '''"
773
PIDFILE=/var/run/$NAME.pid
774
SCRIPTNAME=/etc/init.d/usrmgt-server
776
# Exit if the daemon does not exist
777
test -f $DAEMON || exit 0
779
# Load the VERBOSE setting and other rcS variables
780
[ -f /etc/default/rcS ] && . /etc/default/rcS
782
# Define LSB log_* functions.
783
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
784
. /lib/lsb/init-functions
787
# Function that starts the daemon/service
792
# 0 if daemon has been started
793
# 1 if daemon was already running
794
# 2 if daemon could not be started
795
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
797
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
800
# Add code here, if necessary, that waits for the process to be ready
801
# to handle requests from services started subsequently which depend
802
# on this one. As a last resort, sleep for some time.
806
# Function that stops the daemon/service
811
# 0 if daemon has been stopped
812
# 1 if daemon was already stopped
813
# 2 if daemon could not be stopped
814
# other if a failure occurred
815
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
817
[ "$RETVAL" = 2 ] && return 2
818
# Wait for children to finish too if this is a daemon that forks
819
# and if the daemon is only ever run from this initscript.
820
# If the above conditions are not satisfied then add some other code
821
# that waits for the process to drop all resources that could be
822
# needed by services started subsequently. A last resort is to
823
# sleep for some time.
824
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
825
[ "$?" = 2 ] && return 2
826
# Many daemons don't delete their pidfiles when they exit.
832
# Function that sends a SIGHUP to the daemon/service
836
# If the daemon can reload its configuration without
837
# restarting (for example, when it is sent a SIGHUP),
838
# then implement that here.
840
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
846
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
849
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
850
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
854
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
857
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
858
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
861
#reload|force-reload)
863
# If do_reload() is not implemented then leave this commented out
864
# and leave 'force-reload' as an alias for 'restart'.
866
#log_daemon_msg "Reloading $DESC" "$NAME"
870
restart|force-reload)
872
# If the "reload" option is implemented then remove the
873
# 'force-reload' alias
875
log_daemon_msg "Restarting $DESC" "$NAME"
882
1) log_end_msg 1 ;; # Old process is still running
883
*) log_end_msg 1 ;; # Failed to start
893
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
894
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
903
except IOError, (errno, strerror):
904
print "IO error(%s): %s" % (errno, strerror)
907
# fix permissions as the file contains the database password
909
os.chmod('doc/setup/usrmgt-server.init', 0600)
910
except OSError, (errno, strerror):
911
print "WARNING: Couldn't chmod doc/setup/usrmgt-server.init:"
912
print "OS error(%s): %s" % (errno, strerror)
914
print "Successfully wrote lib/conf/usrmgt-server.init"
917
822
print "You may modify the configuration at any time by editing"
919
824
print jailconffile
921
826
print phpBBconffile
922
print usrmgtserver_initdfile
954
845
# Create the jail and its subdirectories
955
846
# Note: Other subdirs will be made by copying files
956
action_runprog('./buildjail.sh', [], dry)
847
action_mkdir('jail', dry)
848
action_mkdir('jail/home', dry)
849
action_mkdir('jail/tmp', dry)
851
# Chmod the tmp directory to world writable
852
action_chmod_w('jail/tmp', dry)
958
854
# Copy all console and operating system files into the jail
959
855
action_copylist(install_list.list_scripts, 'jail/opt/ivle', dry)
856
copy_os_files_jail(dry)
960
857
# Chmod the python console
961
858
action_chmod_x('jail/opt/ivle/scripts/python-console', dry)
962
859
action_chmod_x('jail/opt/ivle/scripts/fileservice', dry)
963
action_chmod_x('jail/opt/ivle/scripts/serveservice', dry)
965
861
# Also copy the IVLE lib directory into the jail
966
862
# This is necessary for running certain scripts
888
def copy_os_files_jail(dry):
889
"""Copies necessary Operating System files from their usual locations
890
into the jail/ directory of the cwd."""
891
# Currently source paths are configured for Ubuntu.
892
for filename in JAIL_FILES:
893
copy_file_to_jail(filename, dry)
894
for src, dst in JAIL_LINKS.items():
895
action_symlink(src, dst, dry)
896
for src, dst in JAIL_COPYTREES.items():
897
action_copytree(src, dst, dry)
992
899
def copy_file_to_jail(src, dry):
993
900
"""Copies a single file from an absolute location into the same location
994
901
within the jail. src must begin with a '/'. The jail will be located
1033
940
action_copylist(install_list.list_lib, ivle_install_dir, dry)
1035
942
# Copy the php directory
1036
forum_dir = "www/php/phpBB3"
1037
forum_path = os.path.join(ivle_install_dir, forum_dir)
1038
action_copytree(forum_dir, forum_path, dry)
1039
print "chown -R www-data:www-data %s" % forum_path
1041
os.system("chown -R www-data:www-data %s" % forum_path)
943
action_copytree('www/php/phpBB3',os.path.join(ivle_install_dir,'www/php/phpBB3'),
1044
947
# Copy the local jail directory built by the build action
1045
# to the jails __staging__ directory (it will be used to help build
1046
# all the students' jails).
1047
action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
948
# to the jails template directory (it will be used as a template
949
# for all the students' jails).
950
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
1048
951
if not nosubjects:
1049
952
# Copy the subjects and exercises directories across
1050
953
action_copylist(install_list.list_subjects, subjects_base, dry,
1075
978
if write_ivle_lib_pth:
1076
979
action_append(ivle_pth, ivle_lib)
1079
# Create the ivle working revision record file
1080
action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
1081
ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
1084
conf = open(ivle_revision_record_file, "w")
1086
conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
1089
except IOError, (errno, strerror):
1090
print "IO error(%s): %s" % (errno, strerror)
1093
os.system("svn status -v .. >> %s" % ivle_revision_record_file)
1095
print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
1099
983
def updatejails(args):
1110
994
print >>sys.stderr, "(I need to chown some files)."
1113
# Update the staging jail directory in case it hasn't been installed
997
# Update the template jail directory in case it hasn't been installed
1115
action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
999
action_copytree('jail', os.path.join(jail_base, 'template'), dry)
1117
1001
# Re-link all the files in all students jails.
1118
1002
for dir in os.listdir(jail_base):
1119
if dir == '__staging__': continue
1003
if dir == 'template': continue
1120
1004
# First back up the student's home directory
1121
1005
temp_home = os.tmpnam()
1122
1006
action_rename(os.path.join(jail_base, dir, 'home'), temp_home, dry)
1123
1007
# Delete the student's jail and relink the jail files
1124
action_linktree(os.path.join(jail_base, '__staging__'),
1008
action_linktree(os.path.join(jail_base, 'template'),
1125
1009
os.path.join(jail_base, dir), dry)
1126
1010
# Restore the student's home directory
1127
1011
action_rename(temp_home, os.path.join(jail_base, dir, 'home'), dry)