This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
/
vcap_dev_setup
executable file
·192 lines (164 loc) · 4.71 KB
/
vcap_dev_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
#!/bin/bash
# Copyright (c) 2012 VMware, Inc.
# Install vcap components on Ubuntu systems.
set -o errexit
usage() {
cat <<EOF
usage: $0 options
OPTIONS:
-h Show this message
-a Answer yes to all questions
-p http proxy i.e. -p http://username:password@host:port/
-c deployment config
-d cloudfoundry home
-D cloudfoundry domain (default: vcap.me)
-r cloud foundry repo base
-b cloud foundry repo branch/tag/SHA
EOF
}
function run_cmd () {
if [ -z "$PROXY" ]; then
sudo $*
else
sudo env http_proxy=$PROXY $*
fi
}
function clear_bundler_settings () {
[ $# -ge 1 ] || return 1
local DIR=$1
# Do we have a Bundler problem?
find $DIR -type d -name .bundle | grep -Fq .bundle || return 0
if [ "$ALL" != true ]; then
read -p "Remembered Bundler options could cause you troubles, do you want me to clear them for you? [Y/n]"
[[ $REPLY =~ ^[nN] ]] && return 0
fi
(cd $DIR && find -type d -name .bundle -prune -exec rm -r {} \; )
}
RUBY="/usr/bin/ruby"
GEM="/usr/bin/gem"
APT_CONFIG="-o Acquire::http::No-Cache=True -o Acquire::BrokenProxy=true -o Acquire::Retries=3"
if [ -n "$http_proxy" ]; then
if [ -z "$https_proxy" ]; then
echo "Please set https_proxy env variable."
exit 1
fi
PROXY=$http_proxy
fi
while getopts "had:p:c:D:r:b:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
a)
ALL=true
;;
c)
CONFIG_FILE=$OPTARG
;;
d)
CLOUDFOUNDRY_HOME=$OPTARG
;;
D)
CLOUDFOUNDRY_DOMAIN=$OPTARG
;;
r)
VCAP_REPO_BASE=$OPTARG
;;
b)
VCAP_REPO_BRANCH=$OPTARG
;;
p)
PROXY=$OPTARG
export http_proxy=$PROXY
export https_proxy=$PROXY
esac
done
if [ -z "$CLOUDFOUNDRY_HOME" ]; then
CLOUDFOUNDRY_HOME=~/cloudfoundry
fi
if [ -z "$CLOUDFOUNDRY_DOMAIN" ]; then
CLOUDFOUNDRY_DOMAIN=vcap.me
fi
if [ -z "$VCAP_REPO_BASE" ]; then
VCAP_REPO_BASE=https://github.com/cloudfoundry
fi
if [ -z "$VCAP_REPO_BRANCH" ]; then
VCAP_REPO_BRANCH=master
fi
# Check if we have access to the web
echo "Installing wget..."
if ! run_cmd apt-get $APT_CONFIG install -qym wget; then
echo "Can't install prerequisite: wget"
exit 1
fi
echo "Checking web connectivity."
if ! wget -q -T 2 -t 2 -O - http://api.cloudfoundry.com/info | grep "Cloud Application Platform" > /dev/null; then
echo "Giving up. Cannot connect to the web. Check your proxy settings if you are behind a proxy."
exit 1
fi
# Install chef
readonly PREREQUISITES=(ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential ssl-cert)
echo "Installing prerequisites..."
run_cmd apt-get $APT_CONFIG install -qym "${PREREQUISITES[@]}"
if [ ! -f ${GEM} ] || [ `${GEM} -v` \< "1.3.6" ]; then
# Blobstore_client requires gem >= 1.3.6
echo "Installing rubygems..."
CWD=`pwd`
cd /tmp
wget -q http://production.cf.rubygems.org/rubygems/rubygems-1.3.6.tgz
tar zxf rubygems-1.3.6.tgz
cd rubygems-1.3.6
sudo ${RUBY} setup.rb --no-format-executable > /dev/null
cd ${CWD}
fi
# FIXME: at some point you will want a version spec like "~> 10.12.0" here
echo "Installing chef..."
${GEM} list -i chef || sudo ${GEM} install chef -q --no-ri --no-rdoc > /dev/null
# Install blobstore_client
echo "Installing blobstore_client..."
${GEM} list -i blobstore_client || sudo ${GEM} install blobstore_client -q --no-ri --no-rdoc > /dev/null
# Install rake
echo "Installing rake..."
${GEM} list -i rake -i || sudo ${GEM} install rake -q --no-ri --no-rdoc > /dev/null
# Clone cloudfoundry repo
echo "Installing git..."
run_cmd apt-get $APT_CONFIG install -qym git-core
readonly CORE_REPOS=(cloud_controller dea router stager)
[ -d $CLOUDFOUNDRY_HOME ] || mkdir $CLOUDFOUNDRY_HOME
for REPO in vcap "${CORE_REPOS[@]}"; do
if [ ! -d $CLOUDFOUNDRY_HOME/$REPO ]; then
if ! (cd $CLOUDFOUNDRY_HOME
git clone --no-checkout $VCAP_REPO_BASE/$REPO
cd $REPO
git checkout $VCAP_REPO_BRANCH
git submodule update --recursive --init
); then
echo "Unable to clone cloudfoundry $REPO repo."
exit 1
fi
else
clear_bundler_settings $CLOUDFOUNDRY_HOME/$REPO
fi
done
# Our deployment code needs this gem. Using bundler seems like an overkill for
# the deployment code. So for now just manually install the required gem.
if ! gem list rake -i > /dev/null; then
gem install rake -q --no-ri --no-rdoc > /dev/null 2>&1
fi
# Launch chef
ARGS=""
if [ -n "$CLOUDFOUNDRY_HOME" ]; then
ARGS="-d $CLOUDFOUNDRY_HOME"
fi
if [ -n "$CLOUDFOUNDRY_DOMAIN" ]; then
ARGS="$ARGS -D $CLOUDFOUNDRY_DOMAIN"
fi
if [ -n "$CONFIG_FILE" ]; then
ARGS="$ARGS -c $CONFIG_FILE"
fi
echo ""
echo "Lanching chef..."
sleep 3
$CLOUDFOUNDRY_HOME/vcap/dev_setup/lib/chefsolo_launch.rb $ARGS