52
45
parser.add_option("-n", "--dry",
53
46
action="store_true", dest="dry",
54
47
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.")
48
parser.add_option("-R", "--nosvnrevno",
49
action="store_true", dest="nosvnrevno",
50
help="Don't write out the Subversion revision to the share directory.")
51
parser.add_option("--root",
52
action="store", dest="rootdir",
53
help="Install into a different root directory.",
55
parser.add_option("--prefix",
56
action="store", dest="prefix",
57
help="Base prefix to install IVLE into (default: /usr/local).",
59
parser.add_option("--python-site-packages",
60
action="store", dest="python_site_packages",
61
help="Path to Python site packages directory.",
62
default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
61
63
(options, args) = parser.parse_args(args)
63
65
# Call the real function
64
__install(options.dry, options.nojail, options.nosubjects)
66
def __install(dry=False,nojail=False,nosubjects=False):
67
# Importing configuration is a little tricky
68
sys.path.append('lib')
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
66
return __install(prefix=options.prefix,
67
python_site_packages=options.python_site_packages,
68
dry=options.dry, rootdir=options.rootdir,
69
nosvnrevno=options.nosvnrevno)
71
def __install(prefix, python_site_packages, dry=False, rootdir=None,
73
install_list = util.InstallList()
75
# We need to apply make_install_path with the rootdir to an awful lot of
76
# config variables, so make it easy:
77
mip = functools.partial(util.make_install_path, rootdir)
79
# Compute the lib_path, share_path and bin_path (copied from
81
lib_path = mip(os.path.join(prefix, 'lib/ivle'))
82
share_path = mip(os.path.join(prefix, 'share/ivle'))
83
bin_path = mip(os.path.join(prefix, 'bin'))
84
python_site_packages = mip(python_site_packages)
79
86
# Must be run as root or a dry run
81
88
print "Dry run (no actions will be executed)\n"
83
90
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)."
91
print >>sys.stderr, "Must be root to run install"
88
# Create the target (install) directory
89
action_mkdir(ivle_install_dir, dry)
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)
94
# Create the config directory.
95
util.action_mkdir('/etc/ivle', dry)
97
# Create lib and copy the compiled files there
98
util.action_mkdir(lib_path, dry)
100
tramppath = os.path.join(lib_path, 'trampoline')
101
util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
95
102
# chown trampoline to root and set setuid bit
96
action_chown_setuid(tramppath, dry)
98
timountpath = os.path.join(ivle_install_dir, 'bin/timount')
99
action_copyfile('timount/timount', timountpath, dry)
101
# Create a services directory to put the usrmgt-server in.
102
action_mkdir(os.path.join(ivle_install_dir, 'services'), dry)
103
usrmgtpath = os.path.join(ivle_install_dir, 'services/usrmgt-server')
104
action_copyfile('services/usrmgt-server', usrmgtpath, dry)
105
action_chmod_x(usrmgtpath, dry)
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)
111
# Make the config file private
112
configpath = os.path.join(ivle_install_dir, 'lib/conf/conf.py')
113
action_make_private(configpath, dry)
115
# Copy the php directory
103
util.action_chown_setuid(tramppath, dry)
105
timountpath = os.path.join(lib_path, 'timount')
106
util.action_copyfile('bin/timount/timount', timountpath, dry)
108
# Copy in the services (only usrmgt-server is needed on the host, but
109
# the jail build requires the rest).
110
util.action_copylist(install_list.list_services, share_path, dry)
111
usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
112
util.action_chmod_x(usrmgtpath, dry)
114
# Copy the user-executable binaries using the list.
115
util.action_copylist(install_list.list_user_binaries, bin_path, dry,
118
# Copy the www directory (using the list)
119
util.action_copylist(install_list.list_www, share_path, dry)
121
# Set appropriate permissions on the php directory
116
122
forum_dir = "www/php/phpBB3"
117
forum_path = os.path.join(ivle_install_dir, forum_dir)
118
action_copytree(forum_dir, forum_path, dry)
123
forum_path = os.path.join(share_path, forum_dir)
119
124
print "chown -R www-data:www-data %s" % forum_path
121
126
os.system("chown -R www-data:www-data %s" % forum_path)
124
# Copy the local jail directory built by the build action
125
# to the jail_system directory (it will be used to help build
126
# all the students' jails).
127
action_copytree('jail', jail_system, dry)
129
# Copy the subjects and exercises directories across
130
action_copylist(install_list.list_subjects, subjects_base, dry,
132
action_copylist(install_list.list_exercises, exercises_base, dry,
133
srcdir="./exercises")
128
# Copy the lib directory (using the list)
129
util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
135
# Append IVLE path to ivle.pth in python site packages
136
# (Unless it's already there)
137
ivle_pth = os.path.join(sys.prefix,
138
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
139
ivle_www = os.path.join(ivle_install_dir, "www")
140
ivle_lib = os.path.join(ivle_install_dir, "lib")
141
write_ivle_pth = True
142
write_ivle_lib_pth = True
131
# XXX We shouldn't have ivle.pth at all any more.
132
# We may still need the www packages to be importable.
133
# Anything from www that is needed from the outside should go to lib.
134
ivle_pth = os.path.join(python_site_packages, "ivle.pth")
144
file = open(ivle_pth, 'r')
146
if line.strip() == ivle_www:
147
write_ivle_pth = False
148
elif line.strip() == ivle_lib:
149
write_ivle_lib_pth = False
136
file = open(ivle_pth, 'w')
137
file.write(os.path.join(share_path, "www"))
151
139
except (IOError, OSError):
154
action_append(ivle_pth, ivle_www)
155
if write_ivle_lib_pth:
156
action_append(ivle_pth, ivle_lib)
159
# Create the ivle working revision record file
160
action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
161
ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
164
conf = open(ivle_revision_record_file, "w")
166
conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
169
except IOError, (errno, strerror):
170
print "IO error(%s): %s" % (errno, strerror)
173
os.system("svn status -v . >> %s" % ivle_revision_record_file)
175
print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
143
# Create the ivle working revision record file
144
ivle_revision_file = os.path.join(share_path, 'revision.txt')
147
conf = open(ivle_revision_file, "w")
149
conf.write("""# SVN revision r%s
150
# Source tree location: %s
152
""" % (util.get_svn_revision(), os.getcwd()))
155
except IOError, (errno, strerror):
156
print "IO error(%s): %s" % (errno, strerror)
159
os.system("svn status . >> %s" % ivle_revision_file)
161
print "Wrote IVLE code revision status to %s" % ivle_revision_file