43
43
parser.add_option("-n", "--dry",
44
44
action="store_true", dest="dry",
45
45
help="Print out the actions but don't do anything.")
46
parser.add_option("-J", "--nojail",
47
action="store_true", dest="nojail",
48
help="Don't copy jail/ to jail_system directory")
49
46
parser.add_option("-S", "--nosubjects",
50
47
action="store_true", dest="nosubjects",
51
48
help="Don't copy subject/ to subjects directory.")
49
parser.add_option("-R", "--nosvnrevno",
50
action="store_true", dest="nosvnrevno",
51
help="Don't write out the Subversion revision to the share directory.")
52
parser.add_option("--root",
53
action="store", dest="rootdir",
54
help="Install into a different root directory.",
52
56
(options, args) = parser.parse_args(args)
54
58
# Call the real function
55
return __install(options.dry, options.nojail, options.nosubjects)
59
return __install(options.dry, options.nosubjects, options.rootdir,
57
def __install(dry=False,nojail=False,nosubjects=False):
62
def __install(dry=False, nosubjects=False, rootdir=None, nosvnrevno=False):
58
63
# We need to import the one in the working copy, not in the system path.
59
64
confmodule = __import__("ivle/conf/conf")
60
65
install_list = util.InstallList()
67
# We need to apply make_install_path with the rootdir to an awful lot of
68
# config variables, so make it easy:
69
mip = functools.partial(util.make_install_path, rootdir)
62
71
# Pull the required varibles out of the config
63
lib_path = confmodule.lib_path
64
share_path = confmodule.share_path
65
bin_path = confmodule.bin_path
66
python_site_packages = confmodule.python_site_packages
67
jail_base = confmodule.jail_base
68
jail_system = confmodule.jail_system
69
subjects_base = confmodule.subjects_base
70
exercises_base = confmodule.exercises_base
72
lib_path = mip(confmodule.lib_path)
73
share_path = mip(confmodule.share_path)
74
bin_path = mip(confmodule.bin_path)
75
python_site_packages = mip(confmodule.python_site_packages)
76
jail_base = mip(confmodule.jail_base)
77
jail_system = mip(confmodule.jail_system)
78
subjects_base = mip(confmodule.subjects_base)
79
exercises_base = mip(confmodule.exercises_base)
72
81
# Must be run as root or a dry run
81
90
# Make some directories for data.
82
util.action_mkdir(confmodule.log_path, dry)
83
util.action_mkdir(confmodule.data_path, dry)
84
util.action_mkdir(confmodule.jail_base, dry)
85
util.action_mkdir(confmodule.jail_src_base, dry)
86
util.action_mkdir(confmodule.content_path, dry)
87
util.action_mkdir(confmodule.notices_path, dry)
88
util.action_mkdir(os.path.join(confmodule.data_path, 'sessions'), dry)
89
util.action_mkdir(confmodule.svn_path, dry)
90
util.action_mkdir(confmodule.svn_repo_path, dry)
91
util.action_mkdir(os.path.join(confmodule.svn_repo_path, 'users'), dry)
92
util.action_mkdir(os.path.join(confmodule.svn_repo_path, 'groups'), dry)
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)
94
util.action_chown(confmodule.log_path, util.wwwuid, util.wwwuid, dry)
95
util.action_chown(os.path.join(confmodule.data_path, 'sessions'),
96
util.wwwuid, util.wwwuid, dry)
97
util.action_chown(os.path.join(confmodule.svn_repo_path, 'users'),
98
util.wwwuid, util.wwwuid, dry)
99
util.action_chown(os.path.join(confmodule.svn_repo_path, 'groups'),
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'),
100
109
util.wwwuid, util.wwwuid, dry)
102
111
# Create lib and copy the compiled files there
110
119
timountpath = os.path.join(lib_path, 'timount')
111
120
util.action_copyfile('bin/timount/timount', timountpath, dry)
113
# Create a services directory to put the usrmgt-server in.
114
util.action_mkdir(os.path.join(share_path, 'services'), dry)
122
# Copy in the services (only usrmgt-server is needed on the host, but
123
# the jail build requires the rest).
124
util.action_copylist(install_list.list_services, share_path, dry)
116
125
usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
117
util.action_copyfile('services/usrmgt-server', usrmgtpath, dry)
118
126
util.action_chmod_x(usrmgtpath, dry)
120
128
# Copy the user-executable binaries using the list.
121
129
util.action_copylist(install_list.list_user_binaries, bin_path, dry,
122
130
onlybasename=True)
124
# Copy the www and lib directories using the list
132
# Copy the www directory (using the list)
125
133
util.action_copylist(install_list.list_www, share_path, dry)
135
# Set appropriate permissions on the php directory
136
forum_dir = "www/php/phpBB3"
137
forum_path = os.path.join(share_path, forum_dir)
138
print "chown -R www-data:www-data %s" % forum_path
140
os.system("chown -R www-data:www-data %s" % forum_path)
142
# Copy the lib directory (using the list)
126
143
util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
128
145
# Make the config file private
130
146
configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
131
147
util.action_make_private(configpath, dry)
133
# Copy the php directory
134
forum_dir = "www/php/phpBB3"
135
forum_path = os.path.join(share_path, forum_dir)
136
util.action_copytree(forum_dir, forum_path, dry)
137
print "chown -R www-data:www-data %s" % forum_path
139
os.system("chown -R www-data:www-data %s" % forum_path)
142
# Copy the local jail directory built by the build action
143
# to the jail_system directory (it will be used to help build
144
# all the students' jails).
145
util.action_copytree('jail', jail_system, dry)
147
149
if not nosubjects:
148
150
# Copy the subjects and exercises directories across
149
151
util.action_mkdir(subjects_base, dry)
164
166
except (IOError, OSError):
167
# Create the ivle working revision record file
168
ivle_revision_record_file = os.path.join(share_path, 'ivle-revision.txt')
171
conf = open(ivle_revision_record_file, "w")
170
# Create the ivle working revision record file
171
ivle_revision_file = os.path.join(share_path, 'revision.txt')
174
conf = open(ivle_revision_file, "w")
173
conf.write("""# SVN revision r%s
176
conf.write("""# SVN revision r%s
174
177
# Source tree location: %s
175
178
# Modified files:
176
179
""" % (util.get_svn_revision(), os.getcwd()))
179
except IOError, (errno, strerror):
180
print "IO error(%s): %s" % (errno, strerror)
183
os.system("svn status . >> %s" % ivle_revision_record_file)
185
print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
182
except IOError, (errno, strerror):
183
print "IO error(%s): %s" % (errno, strerror)
186
os.system("svn status . >> %s" % ivle_revision_file)
188
print "Wrote IVLE code revision status to %s" % ivle_revision_file