43
51
parser.add_option("-n", "--dry",
44
52
action="store_true", dest="dry",
45
53
help="Print out the actions but don't do anything.")
46
parser.add_option("-R", "--nosvnrevno",
47
action="store_true", dest="nosvnrevno",
48
help="Don't write out the Subversion revision to the share directory.")
49
parser.add_option("--root",
50
action="store", dest="rootdir",
51
help="Install into a different root directory.",
53
parser.add_option("--prefix",
54
action="store", dest="prefix",
55
help="Base prefix to install IVLE into (default: /usr/local).",
57
parser.add_option("--python-site-packages",
58
action="store", dest="python_site_packages",
59
help="Path to Python site packages directory.",
60
default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
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.")
61
60
(options, args) = parser.parse_args(args)
63
62
# Call the real function
64
return __install(prefix=options.prefix,
65
python_site_packages=options.python_site_packages,
66
dry=options.dry, rootdir=options.rootdir,
67
nosvnrevno=options.nosvnrevno)
69
def __install(prefix, python_site_packages, dry=False, rootdir=None,
71
install_list = util.InstallList()
73
# We need to apply make_install_path with the rootdir to an awful lot of
74
# config variables, so make it easy:
75
mip = functools.partial(util.make_install_path, rootdir)
77
# Compute the lib_path, share_path and bin_path (copied from
79
lib_path = mip(os.path.join(prefix, 'lib/ivle'))
80
share_path = mip(os.path.join(prefix, 'share/ivle'))
81
bin_path = mip(os.path.join(prefix, 'bin'))
82
python_site_packages = mip(python_site_packages)
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
84
78
# Must be run as root or a dry run
86
80
print "Dry run (no actions will be executed)\n"
88
82
if not dry and os.geteuid() != 0:
89
print >>sys.stderr, "Must be root to run install"
83
print >>sys.stderr, "Must be root to run build"
84
print >>sys.stderr, "(I need to chown)."
92
# Create the config directory.
93
util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
95
# Create lib and copy the compiled files there
96
util.action_mkdir(lib_path, dry)
98
tramppath = os.path.join(lib_path, 'trampoline')
99
util.action_copyfile('bin/trampoline/trampoline', tramppath, dry)
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)
100
94
# chown trampoline to root and set setuid bit
101
util.action_chown_setuid(tramppath, dry)
103
timountpath = os.path.join(lib_path, 'timount')
104
util.action_copyfile('bin/timount/timount', timountpath, dry)
106
# Copy in the services (only usrmgt-server is needed on the host, but
107
# the jail build requires the rest).
108
util.action_copylist(install_list.list_services, share_path, dry)
109
usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
110
util.action_chmod_x(usrmgtpath, dry)
112
# Copy the user-executable binaries using the list.
113
util.action_copylist(install_list.list_user_binaries, bin_path, dry,
116
# Copy the lib directory (using the list)
117
util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
120
# Create the ivle working revision record file
121
ivle_revision_file = os.path.join(share_path, 'revision.txt')
124
conf = open(ivle_revision_file, "w")
126
conf.write("""# SVN revision r%s
127
# Source tree location: %s
129
""" % (util.get_svn_revision(), os.getcwd()))
132
except IOError, (errno, strerror):
133
print "IO error(%s): %s" % (errno, strerror)
136
os.system("svn status . >> %s" % ivle_revision_file)
138
print "Wrote IVLE code revision status to %s" % ivle_revision_file
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