This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
/
vcap_dev_setup
executable file
·157 lines (136 loc) · 3.82 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
#!/bin/bash
# Copyright (c) 2011 VMware, Inc.
# Install vcap components on Ubuntu systems.
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
-b cloud foundry repo branch/tag/SHA
EOF
}
if [ -n "$http_proxy" ]; then
if [ -z "$https_proxy" ]; then
echo "Please set https_proxy env variable."
exit 1
fi
PROXY=$http_proxy
fi
APT_CONFIG="-o Acquire::http::No-Cache=True -o Acquire::BrokenProxy=true -o Acquire::Retries=3"
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=$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" ]; then
VCAP_REPO=https://github.com/cloudfoundry/vcap.git
fi
if [ -z "$VCAP_REPO_BRANCH" ]; then
VCAP_REPO_BRANCH=master
fi
function run_cmd () {
if [ -z "$PROXY" ]; then
sudo $*
else
sudo env http_proxy=$PROXY $*
fi
}
function clear_bundler_settings () {
# Do we have a Bundler problem?
find $CLOUDFOUNDRY_HOME/vcap -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 $CLOUDFOUNDRY_HOME/vcap && find -type d -name .bundle -prune -exec rm -r {} \; )
}
# Check if we have access to the web
run_cmd apt-get $APT_CONFIG install -qym wget
if [ $? -ne 0 ]; then
echo "Can't install prerequisite: wget"
exit 1
fi
which wget > /dev/null
if [ $? -eq 0 ]; then
echo "Checking web connectivity."
wget -q -T 2 -t 2 -O - http://api.cloudfoundry.com/info | grep "Cloud Application Platform" > /dev/null
if [ $? -ne 0 ]; then
echo "Giving up. Cannot connect to the web. Check your proxy settings if you are behind a proxy."
exit 1
fi
fi
# Install chef
if ! (apt-cache policy | grep opscode); then
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 83EF826A
echo chef chef/chef_server_url select none | sudo /usr/bin/debconf-set-selections
fi
run_cmd apt-get $APT_CONFIG update -qq
run_cmd apt-get $APT_CONFIG install -qym chef
run_cmd apt-get $APT_CONFIG install -qym git-core
[ -d $CLOUDFOUNDRY_HOME ] || mkdir $CLOUDFOUNDRY_HOME
if [ ! -d $CLOUDFOUNDRY_HOME/vcap ]; then
(cd $CLOUDFOUNDRY_HOME && git clone $VCAP_REPO && cd vcap && git submodule update --init && git checkout $VCAP_REPO_BRANCH)
if [ $? != 0 ]; then
echo "Unable to clone cloudfoundry repo."
exit 1
fi
else
clear_bundler_settings
fi
# 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.
gem list rake -i > /dev/null
if [ $? != 0 ]; 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
$CLOUDFOUNDRY_HOME/vcap/dev_setup/lib/chefsolo_launch.rb $ARGS