-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmaximapool-build
executable file
·173 lines (145 loc) · 5.38 KB
/
maximapool-build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Name: maximapool-build
#
# Description:
#
# Script for configuring and building the Maxima pool for a particular version of STACK.
#
# You must have Moodle/STACK running on the same server.
# You must have qtype_stack | platform = unix-optimised (i.e. be using the optimised mode)
#
# See: https://github.com/maths/stack_util_maximapool
######################################################################
# Changelog (newest first)
######################################################################
VERSION="001"
# 001. 2018-10-20 csangwin Follow the documented install process.
echo Setting up Maxima pool.
echo
# Set this to the location of these scripts.
# MAXIMAPOOL=/var/lib/maximapool
MAXIMAPOOL=/var/lib/maximapool
# Tomcat 8 location
# TOMCAT=/usr/share/tomcat8
# TOMCAT=/var/lib/tomcat8
TOMCAT=/var/lib/tomcat8
# The root directory of the moodle site on the server is $MOODLE. (This should have the moodle config.php file in it.)
MOODLE=/var/www/moodle
# The moodle data directory which is $CFG->dataroot in Moodle's config.php.
# We seek to find this automatically from Moodle's config file.
MOODLEDATALINE=$(grep -i 'CFG->dataroot' $MOODLE/config.php)
echo CFG dataroot found in $MOODLE/config.php
echo $MOODLEDATALINE
MOODLEDATAPATTERN="(\'.*\')"
MATCHED=$(grep -oP $MOODLEDATAPATTERN <<< "$MOODLEDATALINE")
MOODLEDATA=${MATCHED:1:-1}
echo Using Moodle data directory:
echo $MOODLEDATA
echo
# Or set it explicitly here.
# MOODLEDATA=/var/data/moodle35
# Find the STACK maxima version.
STACKVERSIONLINE=$(grep -i 'stackmaximaversion:' $MOODLE/question/type/stack/stack/maxima/stackmaxima.mac)
# This should all be a fixed length
STACKVERSION=${STACKVERSIONLINE:19:-1}
# Sanity check at this point
if [ "$STACKVERSION" = "" ]; then
echo "Stack version is not defined: exiting."
exit 1
else
echo "Found the STACK version: $STACKVERSION"
fi
# Ensure we have servlet.conf
echo
if [ -f $MAXIMAPOOL/servlet.conf ]; then
echo "The file $MAXIMAPOOL/servlet.conf already exists (continuing)."
else
echo "The file $MAXIMAPOOL/servlet.conf is missing."
echo "Copy $MAXIMAPOOL/doc/servlet.example.conf to $MAXIMAPOOL/servlet.conf and edit it (including the password!)."
exit 1
fi
# Ensure we have pool.conf
echo
if [ -f $MAXIMAPOOL/pool.conf ]; then
echo "The file $MAXIMAPOOL/pool.conf already exists (continuing)."
else
echo "The file $MAXIMAPOOL/pool.conf is missing, so using the default."
cp $MAXIMAPOOL/doc/pool.example.conf $MAXIMAPOOL/pool.conf
fi
echo
# Make the directory
if [ -d $MAXIMAPOOL/$STACKVERSION ]; then
echo "Directory $MAXIMAPOOL/$STACKVERSION already exists (which is ok..)."
else
echo "Making $MAXIMAPOOL/$STACKVERSION"
mkdir $MAXIMAPOOL/$STACKVERSION
fi
# Copy all the maxima files
cp -R $MOODLE/question/type/stack/stack/maxima/ $MAXIMAPOOL/$STACKVERSION/.
# Copy all the data files
cp -R $MOODLEDATA/stack/* $MAXIMAPOOL/$STACKVERSION/.
# qtype_stack | maximacommand
# How to call the optimized image on your system, in its original location (check it exists...).
# Remove the "timeout" command, and update the paths.
#
# E.g. with SBCL
# /var/data/moodle35/stack/maxima_opt_auto
# RAWMAXIMACOMMAND=$MAXIMAPOOL/$STACKVERSION/maxima_opt_auto
#
# E.g. with clisp
# /usr/lib/clisp-2.49/base/lisp.run -q -M /var/data/moodle35/stack/maxima_opt_auto.mem
# RAWMAXIMACOMMAND="/usr/lib/clisp-2.49/base/lisp.run -q -M $MAXIMAPOOL/$STACKVERSION/maxima_opt_auto.mem"
#
# E.g. with GCL
# /var/data/moodle35/stack/maxima_opt_auto -eval '(cl-user::run)'"
# RAWMAXIMACOMMAND="$MAXIMAPOOL/$STACKVERSION/maxima_opt_auto -eval '(cl-user::run)'"
RAWMAXIMACOMMAND=$MAXIMAPOOL/$STACKVERSION/maxima_opt_auto
# An issue was found with running the optimised maxima image. The maxima command needs to be wrapped
# within another script to preserve quotes and such things.
echo $RAWMAXIMACOMMAND > $MAXIMAPOOL/$STACKVERSION/maxima_wrapped
chmod a+x $MAXIMAPOOL/$STACKVERSION/maxima_wrapped
MAXIMACOMMAND="$MAXIMAPOOL/$STACKVERSION/maxima_wrapped"
echo
echo Can we start the Maxima image?
echo Trying: $MAXIMACOMMAND
MAXIMACOMMANDSTARTED=$($MAXIMACOMMAND <<< "quit();\n")
if [[ $MAXIMACOMMANDSTARTED == *"Maxima restarted"* ]]; then
echo "Maxima restarted: so continuing."
else
echo "Maxima restart failed. Please look up qtype_stack | maximacommand"
echo $MAXIMACOMMANDSTARTED
exit 1
fi
# Now create the process conf file.
cp doc/process.example.conf $STACKVERSION/process.conf
# Using ! characters as the break in sed, because / is used in the filenames.
SEDREP="s!%%MAXIMACOMMAND%%!${MAXIMACOMMAND}!g"
sed -i "${SEDREP}" $STACKVERSION/process.conf
SEDREP="s!%%MAXIMAPOOL%%!${MAXIMAPOOL}!g"
sed -i "${SEDREP}" $STACKVERSION/process.conf
SEDREP="s!%%VERSION%%!${STACKVERSION}!g"
sed -i "${SEDREP}" $STACKVERSION/process.conf
# Run ant
# Remember to set an appropriate JAVA_HOME if you're getting java version issues.
echo
if [ -f $MAXIMAPOOL/MaximaPool.war ]; then
rm $MAXIMAPOOL/MaximaPool.war
echo Removing old MaximaPool.war
fi
echo Running ant....
ant
if [ -f $MAXIMAPOOL/MaximaPool.war ]; then
service tomcat8 stop
echo
echo Copying MaximaPool.war to $TOMCAT/webapps/.
cp MaximaPool.war $TOMCAT/webapps/.
chown -R tomcat8 $MAXIMAPOOL
chgrp -R tomcat8 $MAXIMAPOOL
service tomcat8 start
else
echo $MAXIMAPOOL/MaximaPool.war is missing, so ant probably did not work...
exit 1
fi
echo All done.
echo "Try localhost:8080/MaximaPool/MaximaPool (or whatever url you have configured)."