forked from apache/predictionio
-
Notifications
You must be signed in to change notification settings - Fork 16
/
install.sh
executable file
·488 lines (408 loc) · 16.6 KB
/
install.sh
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#!/usr/bin/env bash
# Copyright 2015 TappingStone, Inc.
#
# This script will install PredictionIO onto your computer!
#
# Documentation: http://docs.prediction.io
#
# License: http://www.apache.org/licenses/LICENSE-2.0
OS=`uname`
PIO_VERSION=0.9.7-aml
SPARK_VERSION=1.6.2
# Looks like support for Elasticsearch 2.0 will require 2.0 so deferring
ELASTICSEARCH_VERSION=1.7.5
HBASE_VERSION=1.2.2
POSTGRES_VERSION=9.4-1204.jdbc41
MYSQL_VERSION=5.1.37
PIO_DIR=$HOME/PredictionIO
USER_PROFILE=$HOME/.profile
PIO_FILE=PredictionIO-${PIO_VERSION}.tar.gz
TEMP_DIR=/tmp
DISTRO_DEBIAN="Debian/Ubuntu"
DISTRO_OTHER="Other"
PGSQL="PostgreSQL"
MYSQL="MySQL"
ES_PGSQL="Elasticsearch + PostgreSQL"
ES_HB="Elasticsearch + HBase"
# Ask a yes/no question, with a default of "yes".
confirm () {
echo -ne $@ "[Y/n] "
read -r response
case ${response} in
[yY][eE][sS]|[yY]|"")
true
;;
[nN][oO]|[nN])
false
;;
*)
confirm $@
;;
esac
}
echo -e "\033[1;32mWelcome to PredictionIO $PIO_VERSION!\033[0m"
# Detect OS
if [[ "$OS" = "Darwin" ]]; then
echo "Mac OS detected!"
SED_CMD="sed -i ''"
elif [[ "$OS" = "Linux" ]]; then
echo "Linux OS detected!"
SED_CMD="sed -i"
else
echo -e "\033[1;31mYour OS $OS is not yet supported for automatic install :(\033[0m"
echo -e "\033[1;31mPlease do a manual install!\033[0m"
exit 1
fi
if [[ $USER ]]; then
echo "Using user: $USER"
else
echo "No user found - this is OK!"
fi
if [[ "$OS" = "Linux" && $(cat /proc/1/cgroup) == *cpu:/docker/* ]]; then
# Docker
# REQUIRED: No user input for Docker!
echo -e "\033[1;33mDocker detected!\033[0m"
echo -e "\033[1;33mForcing Docker defaults!\033[0m"
pio_dir=${PIO_DIR}
vendors_dir=${pio_dir}/vendors
spark_dir=${vendors_dir}/spark-${SPARK_VERSION}
elasticsearch_dir=${vendors_dir}/elasticsearch-${ELASTICSEARCH_VERSION}
hbase_dir=${vendors_dir}/hbase-${HBASE_VERSION}
zookeeper_dir=${vendors_dir}/zookeeper
echo "--------------------------------------------------------------------------------"
echo -e "\033[1;32mOK, looks good!\033[0m"
echo "You are going to install PredictionIO to: $pio_dir"
echo -e "Vendor applications will go in: $vendors_dir\n"
echo "Spark: $spark_dir"
echo "Elasticsearch: $elasticsearch_dir"
echo "HBase: $hbase_dir"
echo "ZooKeeper: $zookeeper_dir"
echo "--------------------------------------------------------------------------------"
# Java Install
echo -e "\033[1;36mStarting Java install...\033[0m"
sudo apt-get update
sudo apt-get install openjdk-7-jdk libgfortran3 -y
echo -e "\033[1;32mJava install done!\033[0m"
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
elif [[ "$1" == "-y" ]]; then
# Non-interactive
echo -e "\033[1;33mNon-interactive installation requested!\033[0m"
echo -e "\033[1;33mForcing defaults!\033[0m"
pio_dir=${PIO_DIR}
vendors_dir=${pio_dir}/vendors
source_setup=${ES_HB}
spark_dir=${vendors_dir}/spark-${SPARK_VERSION}
elasticsearch_dir=${vendors_dir}/elasticsearch-${ELASTICSEARCH_VERSION}
hbase_dir=${vendors_dir}/hbase-${HBASE_VERSION}
zookeeper_dir=${vendors_dir}/zookeeper
echo "--------------------------------------------------------------------------------"
echo -e "\033[1;32mOK, looks good!\033[0m"
echo "You are going to install PredictionIO to: $pio_dir"
echo -e "Vendor applications will go in: $vendors_dir\n"
echo "Spark: $spark_dir"
echo "Elasticsearch: $elasticsearch_dir"
echo "HBase: $hbase_dir"
echo "ZooKeeper: $zookeeper_dir"
echo "--------------------------------------------------------------------------------"
# Java Install
echo -e "\033[1;36mStarting Java install...\033[0m"
# todo: make java installation platform independent
sudo apt-get update
sudo apt-get install openjdk-7-jdk libgfortran3 python-pip -y
sudo pip install predictionio
echo -e "\033[1;32mJava install done!\033[0m"
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
else
# Interactive
while true; do
echo -e "\033[1mWhere would you like to install PredictionIO?\033[0m"
read -e -p "Installation path ($PIO_DIR): " pio_dir
pio_dir=${pio_dir:-$PIO_DIR}
read -e -p "Vendor path ($pio_dir/vendors): " vendors_dir
vendors_dir=${vendors_dir:-$pio_dir/vendors}
echo -e "\033[1mPlease choose between the following sources (1, 2, 3 or 4):\033[0m"
select source_setup in "$PGSQL" "$MYSQL" "$ES_PGSQL" "$ES_HB"; do
case ${source_setup} in
"$PGSQL")
break
;;
"$MYSQL")
break
;;
"$ES_PGSQL")
break
;;
"$ES_HB")
break
;;
*)
;;
esac
done
if confirm "Receive updates?"; then
guess_email=''
if hash git 2>/dev/null; then
# Git installed!
guess_email=$(git config --global user.email)
fi
if [ -n "${guess_email}" ]; then
read -e -p "Email (${guess_email}): " email
else
read -e -p "Enter email: " email
fi
email=${email:-$guess_email}
url="https://direct.prediction.io/$PIO_VERSION/install.json/install/install/$email/"
curl --silent ${url} > /dev/null
fi
spark_dir=${vendors_dir}/spark-${SPARK_VERSION}
elasticsearch_dir=${vendors_dir}/elasticsearch-${ELASTICSEARCH_VERSION}
hbase_dir=${vendors_dir}/hbase-${HBASE_VERSION}
zookeeper_dir=${vendors_dir}/zookeeper
echo "--------------------------------------------------------------------------------"
echo -e "\033[1;32mOK, looks good!\033[0m"
echo "You are going to install PredictionIO to: $pio_dir"
echo -e "Vendor applications will go in: $vendors_dir\n"
echo "Spark: $spark_dir"
case $source_setup in
"$PGSQL")
# PostgreSQL installed by apt-get so no path is printed beforehand
break
;;
"$MYSQL")
# MySQL installed by apt-get so no path is printed beforehand
break
;;
"$ES_PGSQL")
# PostgreSQL installed by apt-get so no path is printed beforehand
echo "Elasticsearch: $elasticsearch_dir"
break
;;
"$ES_HB")
echo "Elasticsearch: $elasticsearch_dir"
echo "HBase: $hbase_dir"
echo "ZooKeeper: $zookeeper_dir"
break
;;
esac
echo "--------------------------------------------------------------------------------"
if confirm "\033[1mIs this correct?\033[0m"; then
break;
fi
done
echo -e "\033[1mSelect your linux distribution:\033[0m"
select distribution in "$DISTRO_DEBIAN" "$DISTRO_OTHER"; do
case $distribution in
"$DISTRO_DEBIAN")
break
;;
"$DISTRO_OTHER")
break
;;
*)
;;
esac
done
# Java Install
if [[ ${OS} = "Linux" ]] && confirm "\033[1mWould you like to install Java?\033[0m"; then
case ${distribution} in
"$DISTRO_DEBIAN")
echo -e "\033[1;36mStarting Java install...\033[0m"
echo -e "\033[33mThis script requires superuser access!\033[0m"
echo -e "\033[33mYou will be prompted for your password by sudo:\033[0m"
sudo apt-get update
sudo apt-get install openjdk-7-jdk libgfortran3 python-pip -y
sudo pip install predictionio
echo -e "\033[1;32mJava install done!\033[0m"
break
;;
"$DISTRO_OTHER")
echo -e "\033[1;31mYour distribution not yet supported for automatic install :(\033[0m"
echo -e "\033[1;31mPlease install Java manually!\033[0m"
exit 2
;;
*)
;;
esac
fi
# Try to find JAVA_HOME
echo "Locating JAVA_HOME..."
if [[ "$OS" = "Darwin" ]]; then
JAVA_VERSION=`echo "$(java -version 2>&1)" | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
JAVA_HOME=`/usr/libexec/java_home`
elif [[ "$OS" = "Linux" ]]; then
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
fi
echo "Found: $JAVA_HOME"
# Check JAVA_HOME
while [ ! -f "$JAVA_HOME/bin/javac" ]; do
echo -e "\033[1;31mJAVA_HOME is incorrect!\033[0m"
echo -e "\033[1;33mJAVA_HOME should be a directory containing \"bin/javac\"!\033[0m"
read -e -p "Please enter JAVA_HOME manually: " JAVA_HOME
done;
fi
if [ -n "$JAVA_VERSION" ]; then
echo "Your Java version is: $JAVA_VERSION"
fi
echo "JAVA_HOME is now set to: $JAVA_HOME"
# PredictionIO
echo -e "\033[1;36mStarting PredictionIO setup in:\033[0m $pio_dir"
cd ${TEMP_DIR}
if [[ ! -e ${PIO_FILE} ]]; then
echo "Downloading PredictionIO..."
curl -OL https://codeload.github.com/actionml/PredictionIO/tar.gz/master
mv master v${PIO_VERSION}.tar.gz
tar zxf v${PIO_VERSION}.tar.gz
mv PredictionIO-master PredictionIO-${PIO_VERSION}
sh PredictionIO-${PIO_VERSION}/make-distribution.sh
cp PredictionIO-${PIO_VERSION}/${PIO_FILE} ${TEMP_DIR}
rm -r PredictionIO-${PIO_VERSION}
fi
tar zxf ${PIO_FILE}
rm -rf ${pio_dir}
mv PredictionIO-${PIO_VERSION} ${pio_dir}
if [[ $USER ]]; then
chown -R $USER ${pio_dir}
fi
echo "Updating ~/.profile to include: $pio_dir"
PATH=$PATH:${pio_dir}/bin
echo "export PATH=\$PATH:$pio_dir/bin" >> ${USER_PROFILE}
echo -e "\033[1;32mPredictionIO setup done!\033[0m"
mkdir ${vendors_dir}
# Spark
echo -e "\033[1;36mStarting Spark setup in:\033[0m $spark_dir"
if [[ ! -e spark-${SPARK_VERSION}-bin-hadoop2.6.tgz ]]; then
echo "Downloading Spark..."
curl -O http://www-us.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop2.6.tgz
fi
tar xf spark-${SPARK_VERSION}-bin-hadoop2.6.tgz
rm -rf ${spark_dir}
mv spark-${SPARK_VERSION}-bin-hadoop2.6 ${spark_dir}
echo "Updating: $pio_dir/conf/pio-env.sh"
${SED_CMD} "s|SPARK_HOME=.*|SPARK_HOME=$spark_dir|g" ${pio_dir}/conf/pio-env.sh
echo -e "\033[1;32mSpark setup done!\033[0m"
installPGSQL () {
if [[ ${distribution} = "$DISTRO_DEBIAN" ]]; then
echo -e "\033[1;36mInstalling PostgreSQL...\033[0m"
sudo apt-get install postgresql-9.4 -y
echo -e "\033[1;36mPlease use the default password 'pio' when prompted to enter one\033[0m"
sudo -u postgres createdb pio
sudo -u postgres createuser -P pio
echo -e "\033[1;36mPlease update $pio_dir/conf/pio-env.sh if you did not enter the default password\033[0m"
else
echo -e "\033[1;31mYour distribution not yet supported for automatic install :(\033[0m"
echo -e "\033[1;31mPlease install PostgreSQL manually!\033[0m"
exit 3
fi
curl -O https://jdbc.postgresql.org/download/postgresql-${POSTGRES_VERSION}.jar
mv postgresql-${POSTGRES_VERSION}.jar ${PIO_DIR}/lib/
echo "Updating: $pio_dir/conf/pio-env.sh"
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=ELASTICSEARCH|" ${pio_dir}/conf/pio-env.sh
echo -e "\033[1;32mPGSQL setup done!\033[0m"
}
installES() {
echo -e "\033[1;36mStarting Elasticsearch setup in:\033[0m $elasticsearch_dir"
if [[ -e elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz ]]; then
if confirm "Delete existing elasticsearch-$ELASTICSEARCH_VERSION.tar.gz?"; then
rm elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz
fi
fi
if [[ ! -e elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz ]]; then
echo "Downloading Elasticsearch..."
curl -O https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz
fi
tar zxf elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz
rm -rf ${elasticsearch_dir}
mv elasticsearch-${ELASTICSEARCH_VERSION} ${elasticsearch_dir}
echo "Updating: $elasticsearch_dir/config/elasticsearch.yml"
echo 'network.host: 127.0.0.1' >> ${elasticsearch_dir}/config/elasticsearch.yml
}
case $source_setup in
"$PGSQL")
installPGSQL
;;
"$MYSQL")
if [[ ${distribution} = "$DISTRO_DEBIAN" ]]; then
echo -e "\033[1;36mInstalling MySQL...\033[0m"
echo -e "\033[1;36mPlease update $pio_dir/conf/pio-env.sh with your database configuration\033[0m"
sudo apt-get install mysql-server -y
sudo mysql -e "create database pio; grant all on pio.* to pio@localhost identified by 'pio'"
echo -e "\033[1;36mUpdating: $pio_dir/conf/pio-env.sh\033[0m"
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=MYSQL|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_MODELDATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_MODELDATA_SOURCE=MYSQL|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_EVENTDATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_EVENTDATA_SOURCE=MYSQL|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_SOURCES_PGSQL|# PIO_STORAGE_SOURCES_PGSQL|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|# PIO_STORAGE_SOURCES_MYSQL|PIO_STORAGE_SOURCES_MYSQL|" ${pio_dir}/conf/pio-env.sh
else
echo -e "\033[1;31mYour distribution not yet supported for automatic install :(\033[0m"
echo -e "\033[1;31mPlease install MySQL manually!\033[0m"
exit 4
fi
curl -O http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.37/mysql-connector-java-${MYSQL_VERSION}.jar
mv mysql-connector-java-${MYSQL_VERSION}.jar ${PIO_DIR}/lib/
;;
"$ES_HB")
# Elasticsearch
installES
echo "Updating: $pio_dir/conf/pio-env.sh"
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=ELASTICSEARCH|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_MODELDATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_MODELDATA_SOURCE=LOCALFS|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_REPOSITORIES_EVENTDATA_SOURCE=PGSQL|PIO_STORAGE_REPOSITORIES_EVENTDATA_SOURCE=HBASE|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_SOURCES_PGSQL|# PIO_STORAGE_SOURCES_PGSQL|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|# PIO_STORAGE_SOURCES_LOCALFS|PIO_STORAGE_SOURCES_LOCALFS|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|# PIO_STORAGE_SOURCES_ELASTICSEARCH_TYPE|PIO_STORAGE_SOURCES_ELASTICSEARCH_TYPE|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|# PIO_STORAGE_SOURCES_ELASTICSEARCH_HOME=.*|PIO_STORAGE_SOURCES_ELASTICSEARCH_HOME=$elasticsearch_dir|" ${pio_dir}/conf/pio-env.sh
echo -e "\033[1;32mElasticsearch setup done!\033[0m"
# HBase
echo -e "\033[1;36mStarting HBase setup in:\033[0m $hbase_dir"
if [[ ! -e hbase-${HBASE_VERSION}-bin.tar.gz ]]; then
echo "Downloading HBase..."
curl -O http://archive.apache.org/dist/hbase/${HBASE_VERSION}/hbase-${HBASE_VERSION}-bin.tar.gz
fi
tar zxf hbase-${HBASE_VERSION}-bin.tar.gz
rm -rf ${hbase_dir}
mv hbase-${HBASE_VERSION} ${hbase_dir}
echo "Creating default site in: $hbase_dir/conf/hbase-site.xml"
cat <<EOT > ${hbase_dir}/conf/hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file://${hbase_dir}/data</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>${zookeeper_dir}</value>
</property>
</configuration>
EOT
echo "Updating: $hbase_dir/conf/hbase-env.sh to include $JAVA_HOME"
${SED_CMD} "s|# export JAVA_HOME=/usr/java/jdk1.6.0/|export JAVA_HOME=$JAVA_HOME|" ${hbase_dir}/conf/hbase-env.sh
echo "Updating: $pio_dir/conf/pio-env.sh"
${SED_CMD} "s|# PIO_STORAGE_SOURCES_HBASE|PIO_STORAGE_SOURCES_HBASE|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|PIO_STORAGE_SOURCES_HBASE_HOME=.*|PIO_STORAGE_SOURCES_HBASE_HOME=$hbase_dir|" ${pio_dir}/conf/pio-env.sh
${SED_CMD} "s|# HBASE_CONF_DIR=.*|HBASE_CONF_DIR=$hbase_dir/conf|" ${pio_dir}/conf/pio-env.sh
echo -e "\033[1;32mHBase setup done!\033[0m"
;;
esac
echo "Updating permissions on: $vendors_dir"
if [[ $USER ]]; then
chown -R $USER ${vendors_dir}
fi
echo -e "\033[1;32mInstallation done!\033[0m"
echo "--------------------------------------------------------------------------------"
echo -e "\033[1;32mInstallation of PredictionIO $PIO_VERSION complete!\033[0m"
echo -e "\033[1;32mPlease follow documentation at http://docs.prediction.io/start/download/ to download the engine template based on your needs\033[0m"
echo -e
echo -e "\033[1;33mCommand Line Usage Notes:\033[0m"
if [[ ${source_setup} = $ES_HB ]]; then
echo -e "To start PredictionIO and dependencies, run: '\033[1mpio-start-all\033[0m'"
else
echo -e "To start PredictionIO Event Server in the background, run: '\033[1mpio eventserver &\033[0m'"
fi
echo -e "To check the PredictionIO status, run: '\033[1mpio status\033[0m'"
echo -e "To train/deploy engine, run: '\033[1mpio [train|deploy|...]\033[0m' commands"
if [[ ${source_setup} = $ES_HB ]]; then
echo -e "To stop PredictionIO and dependencies, run: '\033[1mpio-stop-all\033[0m'"
fi
echo -e ""
echo -e "Please report any problems to: \033[1;34msupport@prediction.io\033[0m"
echo "--------------------------------------------------------------------------------"