This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
/
vcap_dev_setup
executable file
·129 lines (112 loc) · 3.03 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
#!/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
-r cloud foundry repo
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:r:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
a)
ALL=true
;;
c)
CONFIG_FILE=$OPTARG
;;
d)
CLOUDFOUNDRY_HOME=$OPTARG
;;
r)
VCAP_REPO=$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 "$VCAP_REPO" ]; then
VCAP_REPO=https://github.com/cloudfoundry/vcap.git
fi
function run_cmd () {
if [ -z "$PROXY" ]; then
sudo $*
else
sudo env http_proxy=$PROXY $*
fi
}
# Check if we have access to the web
which wget > /dev/null
if [ $? == 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 [ $? != 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 required.
which chef-solo
if [ $? != 0 ]; then
if [[ $ALL != true ]]; then
read -p "chef-solo is required, should I install it? [Y/n]"
if [[ $REPLY =~ ^[nN]$ ]]; then
exit 0
fi
fi
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | sudo tee /etc/apt/sources.list.d/opscode.list
wget -qO - http://apt.opscode.com/packages@opscode.com.gpg.key | sudo apt-key add -
echo chef chef/chef_server_url select none | sudo /usr/bin/debconf-set-selections
run_cmd apt-get $APT_CONFIG update
run_cmd apt-get $APT_CONFIG install -qym chef
else
run_cmd apt-get $APT_CONFIG update
fi
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)
if [ $? != 0 ]; then
echo "Unable to clone cloudfoundry repo."
exit 1
fi
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 "$CONFIG_FILE" ]; then
ARGS="$ARGS -c $CONFIG_FILE"
fi
$CLOUDFOUNDRY_HOME/vcap/dev_setup/lib/chefsolo_launch.rb $ARGS