CoreCommunity ExtensionsIncubatorDistributionsTYPO3 4.5 ProjectsTYPO3 4.6 ProjectsTYPO3 4.7 ProjectsTYPO3 6.0 ProjectsTYPO3 6.1 ProjectsTYPO3 6.2 Projects (+)

install-solr-debian6-without-tomcat.sh

Loek Hilgersom, 2012-02-17 23:18

Download (8.3 kB)

 
1
#!/bin/bash
2
3
# Usage:
4
#	sudo ./install-solr.sh
5
#	sudo ./install-solr.sh english german french
6
7
clear
8
9
TOMCAT_VER=6.0.35
10
SOLR_VER=3.5.0
11
EXT_SOLR_VER=2.0
12
EXT_SOLR_PLUGIN_VER=1.2.0
13
14
SVNBRANCH_PATH="branches/solr_$EXT_SOLR_VER.x"
15
16
# Set default language for cores to download to english, if no commandline parameters are given
17
if [ $# -eq 0 ]
18
then
19
	LANGUAGES=english
20
else
21
	LANGUAGES=$@
22
fi
23
24
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
25
26
progressfilt ()
27
{
28
	local flag=false c count cr=$'\r' nl=$'\n'
29
	while IFS='' read -d '' -rn 1 c
30
	do
31
		if $flag
32
		then
33
			printf '%c' "$c"
34
		else
35
			if [[ $c != $cr && $c != $nl ]]
36
			then
37
				count=0
38
			else
39
				((count++))
40
				if ((count > 1))
41
				then
42
					flag=true
43
				fi
44
			fi
45
		fi
46
	done
47
}
48
49
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
50
51
# wgetresource
52
# usage: wgetresource relative/filepath/inside/resourcesdir [justcheck]
53
# second parameter is optional, if set, do not download, only check if resource exists
54
wgetresource ()
55
{
56
	local wget_result
57
58
	if [ $BRANCH_TEST_RETURN -eq "0" ]
59
	then
60
		RESOURCE="https://svn.typo3.org/TYPO3v4/Extensions/solr/$SVNBRANCH_PATH/resources/"$1
61
	else
62
		RESOURCE="https://svn.typo3.org/TYPO3v4/Extensions/solr/trunk/resources/"$1
63
	fi
64
65
	if [ "$2" ]
66
	then
67
		# If second parameter is set, just check if resource exists, no output
68
		wget -q -O /dev/null --no-check-certificate $RESOURCE
69
	else
70
		echo "wget $RESOURCE"
71
		wget --progress=bar:force --no-check-certificate $RESOURCE 2>&1 | progressfilt
72
	fi
73
74
	# return wget error code
75
	return $?
76
}
77
78
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
79
80
# color echo http://www.faqs.org/docs/abs/HTML/colorizing.html
81
82
black="\033[30m"
83
red="\033[31m"
84
green="\033[32m"
85
yellow="\033[33m"
86
blue="\033[34m"
87
magenta="\033[35m"
88
cyan="\033[36m"
89
white="\033[37m"
90
91
92
# Color-echo, Argument $1 = message, Argument $2 = color
93
cecho ()
94
{
95
	local default_msg="No message passed."
96
97
	# Defaults to default message.
98
	message=${1:-$default_msg}
99
100
	# Defaults to black, if not specified.
101
	color=${2:-$black}
102
103
	echo -e "$color$message"
104
105
	# Reset text attributes to normal + without clearing screen.
106
	tput sgr0
107
108
	return
109
}
110
111
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
112
113
cecho "Checking requirements." $green
114
115
PASSALLCHECKS=1
116
117
# test if release branch exists, if so we'll download from there
118
wget --no-check-certificate -q -O /dev/null https://svn.typo3.org/TYPO3v4/Extensions/solr/$SVNBRANCH_PATH
119
BRANCH_TEST_RETURN=$?
120
121
# Make sure only root can run this script
122
if [[ $EUID -ne 0 ]]
123
then
124
	cecho "This script must be run as root." $red
125
	PASSALLCHECKS=0
126
fi
127
128
java -version > /dev/null 2>&1
129
CHECK=$?
130
if [ $CHECK -ne "0" ]
131
then
132
	cecho "ERROR couldn't find Java (Oracle Java is recommended)." $red
133
	PASSALLCHECKS=0
134
fi
135
136
wget --version > /dev/null 2>&1
137
CHECK=$?
138
if [ $CHECK -ne "0" ]
139
then
140
	cecho "ERROR couldn't find wget." $red
141
	PASSALLCHECKS=0
142
fi
143
144
ping -c 1 apache.osuosl.org > /dev/null 2>&1
145
CHECK=$?
146
if [ $CHECK -ne "0" ]
147
then
148
	cecho "ERROR couldn't ping Apache download mirror, try again using wget" $yellow
149
	wget -q -O /dev/null http://apache.osuosl.org
150
	if [ $? -ne "0" ]
151
	then
152
		cecho "ERROR also couldn't wget Apache download mirror at Oregon State University Open Source Lab - OSUOSL" $red
153
		PASSALLCHECKS=0
154
	fi
155
fi
156
157
unzip -v > /dev/null 2>&1
158
CHECK=$?
159
if [ $CHECK -ne "0" ]
160
then
161
	cecho "ERROR: couldn't find unzip." $red
162
	PASSALLCHECKS=0
163
fi
164
165
# Check if solr scheme files etc. for specified languages are available
166
for LANGUAGE in ${LANGUAGES[*]}
167
do
168
	echo -n "Checking availability of language \"$LANGUAGE\": "
169
	wgetresource solr/typo3cores/conf/"$LANGUAGE"/schema.xml justcheck
170
	if [ $? -ne 0 ]
171
	then
172
		cecho "ERROR: Could not find Solr configuration files for language \"$LANGUAGE\"" $red
173
		exit 1
174
	else cecho "passed" $green
175
	fi
176
done
177
178
if [ $PASSALLCHECKS -eq "0" ]
179
then
180
	cecho "Please install all missing requirements or fix any other errors listed above and try again." $red
181
	exit 1
182
else
183
	cecho "All requirements met, starting to install Solr." $green
184
fi
185
186
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
187
188
cecho "Stopping Tomcat." $green
189
service tomcat6 stop
190
191
mkdir -p /opt/solr-tomcat
192
cd /opt/solr-tomcat/
193
194
#cecho "Using the mirror at Oregon State University Open Source Lab - OSUOSL." $green
195
#cecho "Downloading Apache Tomcat $TOMCAT_VER" $green
196
#TOMCAT_MAINVERSION=`echo "$TOMCAT_VER" | cut -d'.' -f1`
197
#wget --progress=bar:force http://apache.osuosl.org/tomcat/tomcat-$TOMCAT_MAINVERSION/v$TOMCAT_VER/bin/apache-tomcat-$TOMCAT_VER.zip 2>&1 | progressfilt
198
199
cecho "Downloading Apache Solr $SOLR_VER" $green
200
wget --progress=bar:force http://apache.osuosl.org/lucene/solr/$SOLR_VER/apache-solr-$SOLR_VER.zip 2>&1 | progressfilt
201
202
#cecho "Unpacking Apache Tomcat." $green
203
#unzip -q apache-tomcat-$TOMCAT_VER.zip
204
205
cecho "Unpacking Apache Solr." $green
206
unzip -q apache-solr-$SOLR_VER.zip
207
208
#mv apache-tomcat-$TOMCAT_VER tomcat
209
210
cp apache-solr-$SOLR_VER/dist/apache-solr-$SOLR_VER.war /var/lib/tomcat6/webapps/solr.war
211
cp -r apache-solr-$SOLR_VER/example/solr .
212
213
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
214
215
cecho "Downloading TYPO3 Solr configuration files." $green
216
cd solr
217
SOLRDIR=`pwd`
218
219
for LANGUAGE in ${LANGUAGES[*]}
220
do
221
	cecho "Downloading configuration for language: $LANGUAGE" $green
222
223
	cd $SOLRDIR
224
	# create / download $LANGUAGE core configuration
225
	mkdir -p typo3cores/conf/$LANGUAGE
226
	cd typo3cores/conf/$LANGUAGE
227
228
	wgetresource solr/typo3cores/conf/$LANGUAGE/protwords.txt
229
	wgetresource solr/typo3cores/conf/$LANGUAGE/schema.xml
230
	wgetresource solr/typo3cores/conf/$LANGUAGE/stopwords.txt
231
	wgetresource solr/typo3cores/conf/$LANGUAGE/synonyms.txt
232
233
	if [ $LANGUAGE = "german" ]
234
	then
235
		wgetresource solr/typo3cores/conf/$LANGUAGE/german-common-nouns.txt
236
	fi
237
238
done
239
240
# download general configuration in /opt/solr-tomcat/solr/typo3cores/conf/
241
cecho "Downloading general configruation" $green
242
cd ..
243
wgetresource solr/typo3cores/conf/admin-extra.html
244
wgetresource solr/typo3cores/conf/elevate.xml
245
wgetresource solr/typo3cores/conf/general_schema_fields.xml
246
wgetresource solr/typo3cores/conf/general_schema_types.xml
247
wgetresource solr/typo3cores/conf/mapping-ISOLatin1Accent.txt
248
wgetresource solr/typo3cores/conf/solrconfig.xml
249
250
# download core configuration file solr.xml in /opt/solr-tomcat/solr/
251
cd ../..
252
rm solr.xml
253
wgetresource solr/solr.xml
254
255
# clean up
256
rm -rf bin
257
rm -rf conf
258
rm -rf data
259
rm README.txt
260
261
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
262
263
cecho "Configuring Apache Tomcat." $green
264
cd /etc/tomcat6
265
266
if [ ! -f "server.xml.default" ]
267
then
268
	mv server.xml server.xml.default
269
else
270
	mv server.xml server.xml.latest.backup
271
fi
272
273
wgetresource tomcat/server.xml
274
chgrp tomcat6 server.xml
275
276
cd /etc/tomcat6/Catalina/localhost
277
278
# set property solr.home
279
wgetresource tomcat/solr.xml
280
chgrp tomcat6 solr.xml
281
282
# copy libs
283
cd /opt/solr-tomcat/
284
mkdir solr/dist
285
cp apache-solr-$SOLR_VER/dist/apache-solr-analysis-extras-$SOLR_VER.jar solr/dist
286
cp apache-solr-$SOLR_VER/dist/apache-solr-cell-$SOLR_VER.jar solr/dist
287
cp apache-solr-$SOLR_VER/dist/apache-solr-clustering-$SOLR_VER.jar solr/dist
288
cp apache-solr-$SOLR_VER/dist/apache-solr-dataimporthandler-$SOLR_VER.jar solr/dist
289
cp apache-solr-$SOLR_VER/dist/apache-solr-dataimporthandler-extras-$SOLR_VER.jar solr/dist
290
cp apache-solr-$SOLR_VER/dist/apache-solr-uima-$SOLR_VER.jar solr/dist
291
cp -r apache-solr-$SOLR_VER/contrib solr/
292
293
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
294
295
cecho "Downloading the Solr TYPO3 plugin for access control. Version: $EXT_SOLR_PLUGIN_VER" $green
296
mkdir solr/typo3lib
297
cd solr/typo3lib
298
wget --progress=bar:force http://www.typo3-solr.com/fileadmin/files/solr/solr-typo3-plugin-$EXT_SOLR_PLUGIN_VER.jar 2>&1 | progressfilt
299
300
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
301
302
chown -R tomcat6 /opt/solr-tomcat/solr/typo3cores
303
304
#cecho "Setting permissions." $green
305
cd /opt/solr-tomcat/
306
#chmod a+x tomcat/bin/*
307
308
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
309
310
cecho "Cleaning up." $green
311
rm -rf apache-solr-$SOLR_VER.zip
312
rm -rf apache-solr-$SOLR_VER
313
#rm -rf apache-tomcat-$TOMCAT_VER.zip
314
315
# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
316
317
cecho "Starting Tomcat." $green
318
service tomcat6 start
319
320
cecho "Done." $green
321
cecho "Now browse to http://localhost:8080/solr/" $green