1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2008 The University of Melbourne
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.
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.
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
18
# Module: setup/install
19
# Author: Matt Giuca, Refactored by David Coles
23
# Compiles all files and sets up a jail template in the source directory.
25
# Compiles (GCC) trampoline/trampoline.c to trampoline/trampoline.
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.
35
from setuputil import *
38
usage = """usage: %prog install [options]
40
Create target install directory ($target).
42
Copy trampoline/trampoline to $target/bin.
43
chown and chmod the installed trampoline.
45
Copy jail/ to jails __staging__ directory (unless --nojail specified).
46
Copy subjects/ to subjects directory (unless --nosubjects specified).
50
parser = optparse.OptionParser(usage)
51
parser.add_option("-n", "--dry",
52
action="store_true", dest="dry",
53
help="Print out the actions but don't do anything.")
54
parser.add_option("-J", "--nojail",
55
action="store_true", dest="nojail",
56
help="Don't copy jail/ to jail __staging__ directory")
57
parser.add_option("-S", "--nosubjects",
58
action="store_true", dest="nosubjects",
59
help="Don't copy subject/ to subjects directory.")
60
(options, args) = parser.parse_args(args)
62
# Call the real function
63
__install(options.dry, options.nojail, options.nosubjects)
65
def __install(dry=False,nojail=False,nosubjects=False):
66
# Importing configuration is a little tricky
67
sys.path.append(os.path.join(os.pardir, 'lib'))
68
sys.path.append(os.pardir)
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
subjects_base = conf.conf.subjects_base
76
exercises_base = conf.conf.exercises_base
78
# Must be run as root or a dry run
80
print "Dry run (no actions will be executed)\n"
82
if not dry and os.geteuid() != 0:
83
print >>sys.stderr, "Must be root to run build"
84
print >>sys.stderr, "(I need to chown)."
87
# Create the target (install) directory
88
action_mkdir(ivle_install_dir, dry)
90
# Create bin and copy the compiled files there
91
action_mkdir(os.path.join(ivle_install_dir, 'bin'), dry)
92
tramppath = os.path.join(ivle_install_dir, 'bin/trampoline')
93
action_copyfile('trampoline/trampoline', tramppath, dry)
94
# chown trampoline to root and set setuid bit
95
action_chown_setuid(tramppath, dry)
97
# Create a scripts directory to put the usrmgt-server in.
98
action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
99
usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
100
action_copyfile('scripts/usrmgt-server', usrmgtpath, dry)
101
action_chmod_x(usrmgtpath, dry)
103
# Copy the www and lib directories using the list
104
action_copylist(install_list.list_www, ivle_install_dir, dry)
105
action_copylist(install_list.list_lib, ivle_install_dir, dry)
107
# Copy the php directory
108
forum_dir = "www/php/phpBB3"
109
forum_path = os.path.join(ivle_install_dir, forum_dir)
110
action_copytree(forum_dir, forum_path, dry)
111
print "chown -R www-data:www-data %s" % forum_path
113
os.system("chown -R www-data:www-data %s" % forum_path)
116
# Copy the local jail directory built by the build action
117
# to the jails __staging__ directory (it will be used to help build
118
# all the students' jails).
119
action_copytree('jail', os.path.join(jail_base, '__staging__'), dry)
121
# Copy the subjects and exercises directories across
122
action_copylist(install_list.list_subjects, subjects_base, dry,
124
action_copylist(install_list.list_exercises, exercises_base, dry,
125
srcdir="./exercises")
127
# Append IVLE path to ivle.pth in python site packages
128
# (Unless it's already there)
129
ivle_pth = os.path.join(sys.prefix,
130
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
131
ivle_www = os.path.join(ivle_install_dir, "www")
132
ivle_lib = os.path.join(ivle_install_dir, "lib")
133
write_ivle_pth = True
134
write_ivle_lib_pth = True
136
file = open(ivle_pth, 'r')
138
if line.strip() == ivle_www:
139
write_ivle_pth = False
140
elif line.strip() == ivle_lib:
141
write_ivle_lib_pth = False
143
except (IOError, OSError):
146
action_append(ivle_pth, ivle_www)
147
if write_ivle_lib_pth:
148
action_append(ivle_pth, ivle_lib)
151
# Create the ivle working revision record file
152
action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
153
ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
156
conf = open(ivle_revision_record_file, "w")
158
conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
161
except IOError, (errno, strerror):
162
print "IO error(%s): %s" % (errno, strerror)
165
os.system("svn status -v .. >> %s" % ivle_revision_record_file)
167
print "Wrote IVLE code revision status to %s" % ivle_revision_record_file