This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
/
vcap_setup
executable file
·488 lines (412 loc) · 13.2 KB
/
vcap_setup
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
#!/bin/bash
# Copyright (c) 2009-2011 VMware, Inc.
# Try to detect platform. VCAP installs well on Ubuntu and MacOS X Systems.
usage() {
cat <<EOF
usage: $0 options
OPTIONS:
-h Show this message
-a Answer yes to all questions
-s Install all optional services
-p PASSWORD Preseed the MySQL password
-q PASSWORD Preseed the PostgreSQL password
EOF
}
while getopts "hasp:q:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
a)
ALL=true
;;
s)
ALL_SERVICES=true
;;
p)
MYSQL_PASS="$OPTARG"
;;
q)
POSTGRESQL_PASS="$OPTARG"
;;
esac
done
OS=`uname -s`
if [[ $OS == 'Linux' ]]; then
PLATFORM='Linux'
elif [[ $OS == 'Darwin' ]]; then
PLATFORM='MacOSX'
else
echo "Unknown System, cancelling setup"
exit 1
fi
echo ""
echo '-----------------------------------------------------------'
echo "($PLATFORM) Setup for VMware's Cloud Application Platform!"
echo '-----------------------------------------------------------'
echo ""
if [[ $ALL != true ]]; then
echo "Just hit <enter> to skip any item"
echo ""
fi
if [ "$(id -u)" != "0" ]; then
echo '** Setup must be run as root **'
exit 1
fi
if [[ $ALL != true ]]; then
read -p "Setup all components? default: individual components? [y/N]"
if [[ $REPLY =~ ^[yY]$ ]]; then
ALL=true
fi
fi
# Defaults, done for everyone
echo "Installing default packages"
if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy wget curl libcurl3 libcurl3-dev bison build-essential zlib1g-dev libssl-dev libreadline5-dev libxml2 libxml2-dev libxslt1.1 libxslt1-dev git-core sqlite3 libsqlite3-ruby libsqlite3-dev unzip zip
fi
if [[ $PLATFORM == 'Linux' ]]; then
# Probably should make this something different instead of apt_get
echo "Installing Ruby"
apt-get install -qqy ruby-full rake
fi
# This is site/setup specific, can be commented out if not needed.
# export http_proxy='http://192.168.208.20:3128'
RUBYGEMS_VERSION=1.6.2
echo "Checking rubygems version"
if [ "$(gem -v)" != $RUBYGEMS_VERSION ]; then
echo "Installing rubygems $RUBYGEMS_VERSION"
pushd .
cd /tmp
wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBYGEMS_VERSION.tgz
tar -zxf rubygems-$RUBYGEMS_VERSION.tgz
cd rubygems-$RUBYGEMS_VERSION
ruby setup.rb
if [ -f /usr/local/bin/gem ]; then
rm /usr/local/bin/gem
fi
cd ..
rm rubygems-$RUBYGEMS_VERSION.tgz
rm -fr rubygems-$RUBYGEMS_VERSION
popd
fi
ln -sf /usr/bin/gem1.8 /usr/bin/gem
echo "Creating default directories at /var/vcap"
if [ ! -d '/var/vcap' ]; then
mkdir /var/vcap
mkdir /var/vcap/sys
mkdir /var/vcap/sys/log
mkdir /var/vcap/shared
mkdir /var/vcap/services
chmod -R 777 /var/vcap
fi
if [[ ! "$(bundle -v)" =~ "1.0.10" ]]; then
echo "Installing bundler 1.0.10"
gem install bundler -v 1.0.10 --no-rdoc --no-ri
fi
#######################################################################
# Router
if [[ $ALL != true ]]; then
echo ""
read -p "Should I do a Router setup? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
ROUTER=true
fi
fi
if [[ $ROUTER == true || $ALL == true ]]; then
echo "Installing Nginx."
if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy nginx
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
echo ""
fi
# CloudController
if [[ $ALL != true ]]; then
read -p "Should I do a CloudController setup? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
CC=true
fi
fi
if [[ $CC == true || $ALL == true ]]; then
if [[ $PLATFORM == 'Linux' ]]; then
if [[ $ALL != true ]]; then
read -p "Should I do a production setup as well (Postgres/MySQL)? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
RELATIONAL_DBS=true
fi
fi
if [[ $RELATIONAL_DBS == true || $ALL == true ]]; then
echo "Installing PostgreSQL server and support"
apt-get install -qqy postgresql libpq-dev
if [[ -n "$POSTGRESQL_PASS" ]]; then
su - postgres -c "/usr/bin/psql -c \"alter role postgres password '$POSTGRESQL_PASS'\""
fi
echo "Installing pg gems"
gem install pg --no-rdoc --no-ri
echo ""
echo "Installing MySQL server and support"
if [[ -n "$MYSQL_PASS" ]]; then
echo mysql-server-5.1 mysql-server/root_password select $MYSQL_PASS | sudo debconf-set-selections
echo mysql-server-5.1 mysql-server/root_password_again select $MYSQL_PASS | sudo debconf-set-selections
fi
apt-get install -qqy mysql-server ruby-dev libmysql-ruby libmysqlclient-dev
echo "Installing mysql gems"
gem install mysql --no-rdoc --no-ri
echo ""
fi
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
# note: vcap start runs db:migrate on each cloud boot
# no need to run anything during setup
fi
# DEA
if [[ $ALL != true ]]; then
read -p "Should I do a DEA setup (Java, Ruby, Node, etc)? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
DEA=true
fi
fi
if [[ $DEA == true || $ALL == true ]]; then
echo "Setting up for support for DEA"
# lsof support for secure dea monitoring, psmisc is for JeOS, which has killall5, not killall
if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy lsof psmisc
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
# For Ruby
if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy librmagick-ruby
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
# Java
if [[ $PLATFORM == 'Linux' ]]; then
JAVA=`dpkg --get-selections | grep sun-java6`
echo $JAVA
elif [[ $PLATFORM == 'MacOSX' ]]; then
JAVA=`java -version | grep 'build 1.6.0_22'`
fi
if [[ $JAVA == '' ]]; then
echo "Installing Sun Java 1.6"
if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy python-software-properties
add-apt-repository "deb http://archive.canonical.com/ lucid partner"
apt-get -qqy update
echo sun-java6-jdk shared/accepted-sun-dlj-v1-1 boolean true | sudo /usr/bin/debconf-set-selections
echo sun-java6-jre shared/accepted-sun-dlj-v1-1 boolean true | sudo /usr/bin/debconf-set-selections
sudo apt-get install -qqy curl sun-java6-bin sun-java6-jre sun-java6-jdk
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
fi
# Node and Erlang frameworks
pushd .
cd /tmp
NODE_VERSION=0.4.7
if [[ ! `node -v` == 'v'$NODE_VERSION ]]; then
wget http://nodejs.org/dist/node-v$NODE_VERSION.tar.gz
tar -zxf node-v$NODE_VERSION.tar.gz
cd node-v$NODE_VERSION
./configure
make
make install
cd ..
rm node-v$NODE_VERSION.tar.gz
rm -fr node-v$NODE_VERSION
fi
ERLANG_VERSION=R14B02
if [ ! -d "/var/vcap/runtimes/erlang$ERLANG_VERSION" ]; then
if [[ $PLATFORM == 'Linux' ]]; then
apt-get -qqy install build-essential libncurses5-dev openssl libssl-dev
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Install MacOSX dependencies \033[0m"
fi
wget http://erlang.org/download/otp_src_$ERLANG_VERSION.tar.gz
tar zxvf otp_src_$ERLANG_VERSION.tar.gz
cd otp_src_$ERLANG_VERSION
if [[ $PLATFORM == 'Linux' ]]; then
apt-get -qqy install build-essential libncurses5-dev openssl libssl-dev
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Install MacOSX dependencies \033[0m"
fi
./configure --prefix /var/vcap/runtimes/erlang-$ERLANG_VERSION
make
make install
fi
popd
echo "App Platform Support"
echo "===================="
echo -e "\nRuby should now be installed -->"
ruby -v
echo -e "\nJava should now be installed -->"
java -version
echo -e "\nNode should now be installed -->"
node -v
echo ""
echo -e "\nErlang should now be installed -->"
erl -version
echo ""
echo "Setting up Ruby System Gems and Support"
if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy ruby-dev libmysql-ruby libmysqlclient-dev libpq-dev postgresql-client
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
echo "Installing some default system gems"
echo "gem: --no-rdoc --no-ri" > ~/.gemrc
# original code did this in one shot, BUT with the rake issues with 0.9.0 and rails 3
# we hard version the rake gem to 0.8.7 since that is the only one that really works
gem install rack
gem install rake --version '0.8.7'
gem install thin sinatra eventmachine
if [ ! -d '/var/vcap.local' ]; then
echo "Creating directory /var/vcap.local"
mkdir "/var/vcap.local"
chmod 777 "/var/vcap.local"
fi
if [[ $ALL != true ]]; then
read -p "Should I do a production setup and secure this system? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
PROD_SETUP=true
# Setup var directory
echo "Securing directories and permissions"
chmod 755 "/var"
chmod -R 700 "/var/vcap/sys"
chmod -R 700 "/var/vcap/shared"
chmod -R 700 "/var/vcap.local"
chmod -R 711 "/var/vcap.local"
chmod -R 711 "/var/vcap.local/apps"
chmod -R 700 "/tmp"
chmod -R 700 "/var/tmp"
fi
fi
###################
echo ""
echo "Additional Optional Services"
# if you answered no to the production setup
# question than you should answer yes here for sure
X=`which mysqld`
if [ $? != 0 ]; then
if [[ $ALL_SERVICES != true ]]; then
read -p "Should I add MySQL Server? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
MYSQL=true
fi
fi
if [[ $MYSQL == true || $ALL_SERVICES == true ]]; then
echo "Installing MySQL server and support"
if [[ -n "$MYSQL_PASS" && $PLATFORM == "Linux" ]]; then
echo mysql-server-5.1 mysql-server/root_password select $MYSQL_PASS | sudo debconf-set-selections
echo mysql-server-5.1 mysql-server/root_password_again select $MYSQL_PASS | sudo debconf-set-selections
fi
apt-get install -qqy mysql-server ruby-dev libmysql-ruby libmysqlclient-dev
echo "Installing mysql gems"
gem install mysql --no-rdoc --no-ri
echo ""
fi
fi
X=`which psql`
if [ $? != 0 ]; then
if [[ $ALL_SERVICES != true ]]; then
read -p "Should I add PostgreSQL Server? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
POSTGRESQL=true
fi
fi
if [[ $POSTGRESQL == true || $ALL_SERVICES == true ]]; then
echo "Installing PostgreSQL server and support"
apt-get install -qqy postgresql libpq-dev
if [[ -n "$POSTGRESQL_PASS" ]]; then
su - postgres -c "/usr/bin/psql -c \"alter role postgres password '$POSTGRESQL_PASS'\""
fi
echo "Installing pg gems"
gem install pg --no-rdoc --no-ri
echo ""
fi
fi
REDIS_VERSION=2.2.4
redis_current=`redis-server -v | grep $REDIS_VERSION`
if [[ $ALL_SERVICES != true ]]; then
read -p "Should I add Redis Server? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
REDIS=true
fi
fi
if [[ $REDIS == true || $ALL_SERVICES == true ]]; then
echo "Installing Redis (version $REDIS_VERSION)"
pushd .
cd /tmp
wget --no-check-certificate -O redis_master.tgz http://redis.googlecode.com/files/redis-$REDIS_VERSION.tar.gz
tar -zxf redis_master.tgz
cd redis-$REDIS_VERSION/src
make
cp redis-server /usr/bin
cp redis-cli /usr/bin
cd ../..
rm redis_master.tgz
rm -fr redis-$REDIS_VERSION
popd
fi
else
echo "Redis Server (version 2.2.2) is current"
fi
RABBITMQ_VERSION=2.4.0
RABBITMQ_VERSION_FULL=2.4.0-1_all
if [[ $ALL_SERVICES != true ]]; then
read -p "Should I add RabbitMQ Server? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
RABBITMQ=true
fi
fi
if [[ $RABBITMQ == true || $ALL_SERVICES == true ]]; then
echo "Installing RabbitMQ Server (version $RABBITMQ_VERSION)"
apt-get install -qqy erlang-nox
pushd .
cd /tmp
wget http://www.rabbitmq.com/releases/rabbitmq-server/v$RABBITMQ_VERSION/rabbitmq-server_$RABBITMQ_VERSION_FULL.deb
dpkg -i rabbitmq-server_$RABBITMQ_VERSION_FULL.deb
rm rabbitmq-server_$RABBITMQ_VERSION_FULL.deb
popd
fi
MONGODB_VERSION=1.8.1
mongodb_current=`mongod --version | grep $MONGODB_VERSION`
if [[ -z "$mongodb_current" ]]; then
if [[ $ALL_SERVICES != true ]]; then
read -p "Should I add the MongoDB Server? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
MONGODB=true
fi
fi
if [[ $MONGODB == true || $ALL_SERVICES == true ]]; then
echo "Installing MongoDB Server (version $MONGODB_VERSION)"
if [[ `uname -a` =~ "x86_64" ]] ; then
mongodb="mongodb-linux-x86_64-$MONGODB_VERSION"
echo "Installing 64-bit version"
else
mongodb="mongodb-linux-i686-$MONGODB_VERSION"
echo "Installing 32-bit version"
fi
pushd .
cd /tmp
wget http://fastdl.mongodb.org/linux/$mongodb.tgz
tar -zxvf $mongodb.tgz
cp $mongodb/bin/* /usr/bin
rm $mongodb.tgz
rm -fr $mongodb
popd
fi
else
echo "MongoDB Server (version $MONGODB_VERSION) is current"
fi
echo -e "\n\nYou should be good to go!!\n\n"
ruby -v
echo -n "Gem version: "
gem -v
echo -e "\nGem List"
gem list --local
echo -e "\n\nBYE!\n\n"