-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.sh
executable file
·180 lines (151 loc) · 5.46 KB
/
setup.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
#!/bin/bash
# ------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ------------------------------------------------------------
# This script is used to install all the dependency programs
# Assumption that it is run as sudo
clear
echo "Script to setup Aerolyzer environment."
echo "This script assumes JAVA verion 7 or higher, pip and Python 2.7.9 are installed."
echo " Engage number 1!"
APP="$PWD"
INST_DIR="$APP/../installDir"
if [ ! -d $INST_DIR ]; then
mkdir $INST_DIR
fi
MEDIA_DIR="$APP/../installDir/aerolyzerImgs"
if [ ! -d $MEDIA_DIR ]; then
mkdir $MEDIA_DIR
fi
cd $INST_DIR
# Check for installation machine distro and package manager
APT_GET_CMD=$(which apt-get)
BREW_CMD=$(which brew)
YUM_CMD=$(which yum)
DISTRO_VER=$(uname -v)
DISTRO_LONG=(${DISTRO_VER//;/ })
if [[ $DISTRO_LONG =~ .*Ubuntu* ]]; then
DISTRO="Ubuntu"
elif [[ $DISTRO_LONG =~ .*Darwin* ]]; then
DISTRO="Darwin"
elif [[ $DISTRO_LONG =~ .*Debian* ]]; then
DISTRO="Debian"
fi
# install PostgreSQL
if [ ! -z $APT_GET_CMD ]; then
echo "Ubuntu OS config ..."
$APT_GET_CMD install postgresql postgresql-contrib
$APT_GET_CMD install python-psycopg2
$APT_GET_CMD install libpq-dev
$APT_GET_CMD install python-qt4 # Install PyQt4
echo "configure PostgreSQL"
# configure PostgreSQL
sudo -u postgres bash -c "psql postgres -c \"CREATE DATABASE aerolyzer\""
sudo -u postgres bash -c "psql postgres -c \"ALTER USER postgres WITH PASSWORD 'Aerolyzer_1'\""
elif [[ ! -z $YUM_CMD ]]; then
echo "Red Hat OS config ..."
$YUM_CMD install postgresql-server
service postgresql initdb
chkconfig postgresql on
sudo -u postgres bash -c "psql postgres -c \"CREATE DATABASE aerolyzer\""
sudo -u postgres bash -c "psql postgres -c \"ALTER USER postgres WITH PASSWORD 'Aerolyzer_1'\""
elif [ $DISTRO == "Darwin" ]; then
echo "Mac OS config ..."
if [ -z $BREW_CMD ]; then
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# ref: https://gist.github.com/lxneng/741932
$BREW_CMD update
$BREW_CMD doctor
$BREW_CMD install postgresql
$BREW_CMD cleanup PostgreSQL
echo "initalize PostgreSQL"
initdb /usr/local/var/postgres
echo "start the postgres server"
$BREW_CMD services start postgresql
postgres -D /usr/local/var/postgres
echo "set up postgres user pwd"
bash -c "psql -U postgres -c \"ALTER USER postgres WITH PASSWORD 'Aerolyzer_1'\""
echo "create aerolyzer database"
bash -c "psql -U postgres -c \"CREATE DATABASE aerolyzer"\"
else
echo "Error: Cannot identify package manager, thus cannot install PostgreSQL. Exiting!!!!!"
exit 1;
fi
echo "End PostgreSQL config"
# solr stuff
if [ ! -d "$INST_DIR/solr-5.5.4" ]; then
wget http://archive.apache.org/dist/lucene/solr/5.5.4/solr-5.5.4.tgz
tar -xvzf solr-5.5.4.tgz
rm solr-5.5.4.tgz
fi
# configure Solr and start
if [ ! -d "$INST_DIR/solr-5.5.4/server/solr/aerolyzer" ]; then
mkdir solr-5.5.4/server/solr/aerolyzer
mkdir solr-5.5.4/server/solr/aerolyzer/data
cp -R solr-5.5.4/server/solr/configsets/data_driven_schema_configs/conf solr-5.5.4/server/solr/aerolyzer
cp $APP/schema.xml solr-5.5.4/server/solr/aerolyzer/conf
cp $APP/solrconfig.xml solr-5.5.4/server/solr/aerolyzer/conf
fi
# start Solr
$INST_DIR/solr-5.5.4/bin/solr start
# add aerolyzer core
$INST_DIR/solr-5.5.4/bin/solr create -c aerolyzer
$INST_DIR/solr-5.5.4/bin/solr restart
# update Solr index every hr
crontab -l > $INST_DIR/mycron
echo "0 * * * * $APP/Aerolyzer/manage.py update_index" >> $INST_DIR/mycron
crontab $INST_DIR/mycron
rm $INST_DIR/mycron
if [ ! -d "$INST_DIR/.virtualenvs/" ]; then
mkdir $INST_DIR/.virtualenvs/
fi
if [ ! -d "$INST_DIR/.virtualenvs/aerolyzer" ]; then
cd $INST_DIR/.virtualenvs/
if [ ! -z $(which virtualenv) ]; then
virtualenv aerolyzer
else
pip install virtualenvs
fi
echo "Virtualenv env created at $INST_DIR/.virtualenvs/aerolyzer"
fi
# start aerolyzer virtual env
source $INST_DIR/.virtualenvs/aerolyzer/bin/activate
cd $APP/Aerolyzer
# install requirements
pip install -r requirements.txt
echo "Requirements installed into aerolyzer virtualenv"
source deactivate
echo "Successful setup environment for Aerolyzer App."
echo "**********************************************************"
echo "Please choose option to deploy Aerolyzer App: "
read -p "1 - in local mode OR 2 - production mode ": mode
if [ $mode = "1" ]; then
# start aerolyzer virtual env
source $INST_DIR/.virtualenvs/aerolyzer/bin/activate
# update Aerolyzer
cd $APP/Aerolyzer
python manage.py migrate
echo "Running Aerolyzer App at http://127.0.0.1:8000/app"
# start Aerolyzer
python manage.py runserver
fi
if [ $mode = "2" ]; then
sudo $APP/production/run_production.sh
fi
echo "We out fam!"