52
44
parser.add_option("-n", "--dry",
53
45
action="store_true", dest="dry",
54
46
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
47
parser.add_option("-S", "--nosubjects",
59
48
action="store_true", dest="nosubjects",
60
49
help="Don't copy subject/ to subjects directory.")
50
parser.add_option("-R", "--nosvnrevno",
51
action="store_true", dest="nosvnrevno",
52
help="Don't write out the Subversion revision to the share directory.")
53
parser.add_option("--root",
54
action="store", dest="rootdir",
55
help="Install into a different root directory.",
61
57
(options, args) = parser.parse_args(args)
63
59
# 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')
60
return __install(options.dry, options.nosubjects, options.rootdir,
63
def __install(dry=False, nosubjects=False, rootdir=None, nosvnrevno=False):
64
# We need to import the one in the working copy, not in the system path.
65
confmodule = __import__("ivle/conf/conf")
66
install_list = util.InstallList()
68
# We need to apply make_install_path with the rootdir to an awful lot of
69
# config variables, so make it easy:
70
mip = functools.partial(util.make_install_path, rootdir)
72
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
73
lib_path = mip(confmodule.lib_path)
74
share_path = mip(confmodule.share_path)
75
bin_path = mip(confmodule.bin_path)
76
python_site_packages = mip(confmodule.python_site_packages)
77
jail_base = mip(confmodule.jail_base)
78
jail_system = mip(confmodule.jail_system)
79
subjects_base = mip(confmodule.subjects_base)
80
exercises_base = mip(confmodule.exercises_base)
79
82
# Must be run as root or a dry run
81
84
print "Dry run (no actions will be executed)\n"
83
86
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)."
87
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)
90
# Make some directories for data.
91
util.action_mkdir(mip(confmodule.log_path), dry)
92
util.action_mkdir(mip(confmodule.data_path), dry)
93
util.action_mkdir(mip(confmodule.jail_base), dry)
94
util.action_mkdir(mip(confmodule.jail_src_base), dry)
95
util.action_mkdir(mip(confmodule.content_path), dry)
96
util.action_mkdir(mip(confmodule.notices_path), dry)
97
util.action_mkdir(os.path.join(mip(confmodule.data_path), 'sessions'), dry)
98
util.action_mkdir(mip(confmodule.svn_path), dry)
99
util.action_mkdir(mip(confmodule.svn_repo_path), dry)
100
util.action_mkdir(os.path.join(mip(confmodule.svn_repo_path), 'users'),dry)
101
util.action_mkdir(os.path.join(mip(confmodule.svn_repo_path),'groups'),dry)
103
util.action_chown(mip(confmodule.log_path), util.wwwuid, util.wwwuid, dry)
104
util.action_chown(os.path.join(mip(confmodule.data_path), 'sessions'),
105
util.wwwuid, util.wwwuid, dry)
106
util.action_chown(os.path.join(mip(confmodule.svn_repo_path), 'users'),
107
util.wwwuid, util.wwwuid, dry)
108
util.action_chown(os.path.join(mip(confmodule.svn_repo_path), 'groups'),
109
util.wwwuid, util.wwwuid, dry)
111
# Create lib and copy the compiled files there
112
util.action_mkdir(lib_path, dry)
114
tramppath = os.path.join(lib_path, 'trampoline')
115
util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
95
116
# 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 scripts directory to put the usrmgt-server in.
102
action_mkdir(os.path.join(ivle_install_dir, 'scripts'), dry)
103
usrmgtpath = os.path.join(ivle_install_dir, 'scripts/usrmgt-server')
104
action_copyfile('scripts/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
# Copy the php directory
117
util.action_chown_setuid(tramppath, dry)
119
timountpath = os.path.join(lib_path, 'timount')
120
util.action_copyfile('bin/timount/timount', timountpath, dry)
122
ivleconfpath = mip('/etc/ivle/ivle.conf')
123
util.action_copyfile('etc/ivle.conf', ivleconfpath, dry)
125
# Copy in the services (only usrmgt-server is needed on the host, but
126
# the jail build requires the rest).
127
util.action_copylist(install_list.list_services, share_path, dry)
128
usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
129
util.action_chmod_x(usrmgtpath, dry)
131
# Copy the user-executable binaries using the list.
132
util.action_copylist(install_list.list_user_binaries, bin_path, dry,
135
# Copy the www directory (using the list)
136
util.action_copylist(install_list.list_www, share_path, dry)
138
# Set appropriate permissions on the php directory
112
139
forum_dir = "www/php/phpBB3"
113
forum_path = os.path.join(ivle_install_dir, forum_dir)
114
action_copytree(forum_dir, forum_path, dry)
140
forum_path = os.path.join(share_path, forum_dir)
115
141
print "chown -R www-data:www-data %s" % forum_path
117
143
os.system("chown -R www-data:www-data %s" % forum_path)
120
# Copy the local jail directory built by the build action
121
# to the jail_system directory (it will be used to help build
122
# all the students' jails).
123
action_copytree('jail', jail_system, dry)
145
# Copy the lib directory (using the list)
146
util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
148
# Make the config file private
149
configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
150
util.action_make_private(configpath, dry)
124
152
if not nosubjects:
125
153
# Copy the subjects and exercises directories across
126
action_copylist(install_list.list_subjects, subjects_base, dry,
154
util.action_mkdir(subjects_base, dry)
155
util.action_copylist(install_list.list_subjects, subjects_base, dry,
127
156
srcdir="./subjects")
128
action_copylist(install_list.list_exercises, exercises_base, dry,
157
util.action_mkdir(exercises_base, dry)
158
util.action_copylist(install_list.list_exercises, exercises_base, dry,
129
159
srcdir="./exercises")
131
# Append IVLE path to ivle.pth in python site packages
132
# (Unless it's already there)
133
ivle_pth = os.path.join(sys.prefix,
134
"lib/python%s/site-packages/ivle.pth" % PYTHON_VERSION)
135
ivle_www = os.path.join(ivle_install_dir, "www")
136
ivle_lib = os.path.join(ivle_install_dir, "lib")
137
write_ivle_pth = True
138
write_ivle_lib_pth = True
161
# XXX We shouldn't have ivle.pth at all any more.
162
# We may still need the www packages to be importable.
163
# Anything from www that is needed from the outside should go to lib.
164
ivle_pth = os.path.join(python_site_packages, "ivle.pth")
140
file = open(ivle_pth, 'r')
142
if line.strip() == ivle_www:
143
write_ivle_pth = False
144
elif line.strip() == ivle_lib:
145
write_ivle_lib_pth = False
166
file = open(ivle_pth, 'w')
167
file.write(os.path.join(share_path, "www"))
147
169
except (IOError, OSError):
150
action_append(ivle_pth, ivle_www)
151
if write_ivle_lib_pth:
152
action_append(ivle_pth, ivle_lib)
155
# Create the ivle working revision record file
156
action_mkdir(os.path.join(ivle_install_dir, 'version'), dry)
157
ivle_revision_record_file = os.path.join(ivle_install_dir, 'version/ivle-revision.txt')
160
conf = open(ivle_revision_record_file, "w")
162
conf.write( "# IVLE code revision listing generated by running 'svn status -v ..' from " + os.getcwd() + "\n#\n\n")
165
except IOError, (errno, strerror):
166
print "IO error(%s): %s" % (errno, strerror)
169
os.system("svn status -v . >> %s" % ivle_revision_record_file)
171
print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
173
# Create the ivle working revision record file
174
ivle_revision_file = os.path.join(share_path, 'revision.txt')
177
conf = open(ivle_revision_file, "w")
179
conf.write("""# SVN revision r%s
180
# Source tree location: %s
182
""" % (util.get_svn_revision(), os.getcwd()))
185
except IOError, (errno, strerror):
186
print "IO error(%s): %s" % (errno, strerror)
189
os.system("svn status . >> %s" % ivle_revision_file)
191
print "Wrote IVLE code revision status to %s" % ivle_revision_file