-
Notifications
You must be signed in to change notification settings - Fork 19
/
setup-mac.sh
executable file
·469 lines (409 loc) · 12 KB
/
setup-mac.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
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
#!/bin/bash
set -e
git=0
cf=1
jdk=2
maven=3
nodejs=4
python2=5
python3=6
uaac=7
jq=8
predixcli=9
mobilecli=10
androidstudio=11
docker=12
vmware=13
declare -a install
function prefix_to_path() {
if [[ ":$PATH:" != *":$1:"* ]]; then
echo 'export PATH="$1${PATH:+":$PATH"}"' >> ~/.bash_profile
source ~/.bash_profile
fi
}
function check_internet() {
set +e
echo ""
echo "Checking internet connection..."
curl "http://github.com" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Unable to connect to internet, make sure you are connected to a network and check your proxy settings if behind a corporate proxy. Please read this tutorial for detailed info about setting your proxy https://www.predix.io/resources/tutorials/tutorial-details.html?tutorial_id=1565"
echo ""
exit 1
fi
echo "OK"
echo ""
set -e
}
function check_bash_profile() {
# Ensure bash profile exists
if [ ! -e ~/.bash_profile ]; then
printf "#!/bin/bash\n" >> ~/.bash_profile
fi
# This is required for brew to work
prefix_to_path /usr/local/bin
}
function get_proxy_scripts() {
VERIFY_PROXY_URL=https://raw.githubusercontent.com/PredixDev/predix-scripts/master/bash/common/proxy/verify-proxy.sh
TOGGLE_PROXY_URL=https://raw.githubusercontent.com/PredixDev/predix-scripts/master/bash/common/proxy/toggle-proxy.sh
ENABLE_XSL_URL=https://raw.githubusercontent.com/PredixDev/predix-scripts/master/bash/common/proxy/enable-proxy.xsl
DISABLE_XSL_URL=https://raw.githubusercontent.com/PredixDev/predix-scripts/master/bash/common/proxy/disable-proxy.xsl
if [ -f "verify-proxy.sh" ]; then
rm verify-proxy.sh
fi
if [ -f "toggle-proxy.sh" ]; then
rm toggle-proxy.sh
fi
if [ -f "enable-proxy.xsl" ]; then
rm enable-proxy.xsl
fi
if [ -f "disable-proxy.xsl" ]; then
rm disable-proxy.xsl
fi
if [ ! -f "verify-proxy.sh" ]; then
curl -s -O $VERIFY_PROXY_URL
fi
if [ ! -f "toggle-proxy.sh" ]; then
curl -s -O $TOGGLE_PROXY_URL
fi
if [ ! -f "enable-proxy.xsl" ]; then
curl -s -O $ENABLE_XSL_URL
fi
if [ ! -f "disable-proxy.xsl" ]; then
curl -s -O $DISABLE_XSL_URL
fi
}
function install_brew_cask() {
# Install brew and cask
if which brew > /dev/null; then
echo "brew already installed, tapping cask, this may take a full minute"
else
echo "Installing brew and cask, this may take a few minutes"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
brew tap caskroom/cask
}
function brew_install() {
echo "--------------------------------------------------------------"
TOOL=$1
COMMAND=$1
if [ $# -eq 2 ]; then
COMMAND=$2
fi
if which $COMMAND > /dev/null; then
echo "$TOOL already installed"
else
echo "Installing $TOOL"
brew install $TOOL
# Adding validation to check for installation failures
STATUS=$?
check_status
fi
}
function brew_cask_install() {
echo "--------------------------------------------------------------"
TOOL=$1
if brew cask list | grep $TOOL > /dev/null; then
echo "$TOOL already installed"
else
echo "Installing $TOOL"
brew cask install $TOOL
fi
}
function install_everything() {
install[git]=1
install[cf]=1
install[jdk]=1
install[maven]=1
install[nodejs]=1
install[python2]=1
install[python3]=1
install[uaac]=0 # Install UAAC only if the --uaac flag is provided
install[jq]=1
install[yq]=1
install[predixcli]=1
install[mobilecli]=1
install[androidstudio]=0 # Install Android Studio only if --androidstudio flag is provided
install[docker]=1
install[vmware]=0 # Install Android Studio only if --vmware flag is provided
}
function install_nothing() {
install[git]=0
install[cf]=0
install[jdk]=0
install[maven]=0
install[nodejs]=0
install[python2]=0
install[python3]=0
install[uaac]=0
install[jq]=0
install[yq]=0
install[predixcli]=0
install[mobilecli]=0
install[androidstudio]=0
install[docker]=0
install[vmware]=0
}
function install_git() {
brew_install git
git --version
}
function install_cf() {
brew tap cloudfoundry/tap
brew_install cf-cli cf
cf -v
}
function install_jdk() {
brew_cask_install java
javac -version
}
function install_maven() {
brew_install maven mvn
mvn -v
}
function install_android_studio() {
echo "--------------------------------------------------------------"
echo "Android Studio will require Maven, Ant, and Gradle"
# Install tools used by Android Studio
install_maven
brew_install ant
brew_install gradle
# Install Android Studio dependencies
brew_cask_install android-studio
brew cask install android-platform-tools
}
function install_docker() {
# Install Docker dependencies
brew_cask_install docker
echo "Run the Docker app found in the Applications folder and docker CLI commands will also be available."
}
function install_vmware() {
brew_cask_install vmware-fusion
echo "Run the VMWare app found in the Applications folder"
}
function install_nodejs() {
brew_install node
node -v
echo -ne "\nnpm "
npm -v
type bower > /dev/null || npm install -g bower
echo -ne "\nbower "
bower -v
type grunt > /dev/null || npm install -g grunt-cli
grunt --version
type gulp > /dev/null || npm install -g gulp-cli
echo -ne "\ngulp "
gulp --version
echo "node install complete"
}
function install_python3() {
brew_install python3
python3 --version
sudo easy_install pip
}
function install_python2() {
brew_install python2
python2 --version
sudo easy_install pip
}
function install_jq() {
brew_install jq
jq --version
}
function install_yq() {
brew_install yq
yq --version
}
function install_uaac() {
# Install tools for managing ruby
brew_install rbenv
brew_install ruby-build
# Add rbenv to bash
grep -q -F 'rbenv init' ~/.bash_profile || echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile && eval "$(rbenv init -)"
# Install latest ruby
RUBY_VERSION=`egrep "^\s+\d+\.\d+\.\d+$" <(rbenv install -l) | tail -1 | tr -d '[[:space:]]'`
echo "--------------------------------------------------------------"
if grep -q "$RUBY_VERSION" <(ruby -v); then
echo "Already running latest version of ruby"
else
echo "Installing latest ruby"
rbenv install $RUBY_VERSION
rbenv global $RUBY_VERSION
fi
ruby -v
# Install UAAC
echo "--------------------------------------------------------------"
echo "Installing UAAC gem"
gem install cf-uaac
}
function install_predixcli() {
export DYLD_INSERT_LIBRARIES=;
if which predix > /dev/null; then
echo "Predix CLI already installed."
predix -v
PREDIX_VERSION=$(predix -v | awk -F" " '{print $3}')
update_predixcli $PREDIX_VERSION
else
cli_url=$(curl -s -L https://api.github.com/repos/PredixDev/predix-cli/releases | jq -r ".[0].assets[0].browser_download_url")
echo "Downloading latest Predix CLI: $cli_url"
curl -L -O "$cli_url"
mkdir -p predix-cli && tar -xf predix-cli.tar.gz -C predix-cli
if [ -e predix-cli ]; then
#tar -C is supposed to change directory but it doesn't sometimes
cd predix-cli
fi
./install
fi
}
function update_predixcli() {
#echo "Predix CLI updgrade"$1
existing_version=$1
cli_version_name=$(curl -s -L https://api.github.com/repos/PredixDev/predix-cli/releases | jq -r ".[0].tag_name")
cli_version_name=${cli_version_name:1}
echo "Predix CLI already installed version."$existing_version
echo "Predix CLI new installed version."$cli_version_name
echo "checking for upgrade"
if [[ "$existing_version" != *"$cli_version_name"* ]]; then
echo "Upgrading Predix CLI to version" $cli_version_name
cli_url=$(curl -s -L https://api.github.com/repos/PredixDev/predix-cli/releases | jq -r ".[0].assets[0].browser_download_url")
echo "Downloading latest Predix CLI: $cli_url"
curl -L -O "$cli_url"
mkdir -p predix-cli && tar -xf predix-cli.tar.gz -C predix-cli
if [ -e predix-cli ]; then
#tar -C is supposed to change directory but it doesn't sometimes
cd predix-cli
fi
./install
fi
}
function install_mobilecli() {
if which pm > /dev/null; then
echo "Predix Mobile CLI already installed."
pm
else
#cli_url=$(curl -g -s -L https://api.github.com/repos/PredixDev/predix-mobile-cli/releases | jq -r '.' )
cli_url=$(curl -g -s -L https://api.github.com/repos/PredixDev/predix-mobile-cli/releases | jq -r '[ .[] | select(.prerelease==false) ] | .[0].assets[] | select(.name | contains("Mac")) | .browser_download_url' )
cli_install_url="https://raw.githubusercontent.com/PredixDev/local-setup/master/mobile-cli-install"
cli_install_root_url="https://raw.githubusercontent.com/PredixDev/local-setup/master/mobile-cli-root-install"
#cli_install_url="https://raw.githubusercontent.com/PredixDev/local-setup/develop/mobile-cli-install.sh"
echo "Downloading latest Predix Mobile CLI: $cli_url"
curl -L "$cli_url" -o pm.zip
mkdir -p mobile-cli && tar -xf pm.zip -C mobile-cli
cd mobile-cli
echo $cli_install_url
curl -L -O "$cli_install_url"
echo $cli_install_root_url
curl -L -O "$cli_install_root_url"
chmod +x mobile-cli-install
chmod +x mobile-cli-root-install
./mobile-cli-install
fi
}
function run_setup() {
echo "--------------------------------------------------------------"
echo "This script will install tools required for Predix development"
echo "You may be asked to provide your password during the installation process"
echo "--------------------------------------------------------------"
echo ""
if [ -z "$1" ]; then
echo "Installing all the tools..."
install_everything
else
echo "Installing only tools specified in parameters..."
install_nothing
while [ ! -z "$1" ]; do
[ "$1" == "--git" ] && install[git]=1
[ "$1" == "--cf" ] && install[cf]=1
[ "$1" == "--jdk" ] && install[jdk]=1
[ "$1" == "--maven" ] && install[maven]=1
[ "$1" == "--nodejs" ] && install[nodejs]=1
[ "$1" == "--python2" ] && install[python2]=1
[ "$1" == "--python3" ] && install[python3]=1
[ "$1" == "--uaac" ] && install[uaac]=1
[ "$1" == "--jq" ] && install[jq]=1
[ "$1" == "--yq" ] && install[yq]=1
[ "$1" == "--predixcli" ] && install[predixcli]=1
[ "$1" == "--mobilecli" ] && install[mobilecli]=1
[ "$1" == "--androidstudio" ] && install[androidstudio]=1
[ "$1" == "--docker" ] && install[docker]=1
[ "$1" == "--vmware" ] && install[vmware]=1
shift
done
install[jq]=1
fi
check_internet
check_bash_profile
install_brew_cask
if [ ${install[jq]} -eq 1 ]; then
install_jq
fi
if [ ${install[yq]} -eq 1 ]; then
install_yq
fi
if [ ${install[git]} -eq 1 ]; then
install_git
fi
if [ ${install[cf]} -eq 1 ]; then
install_cf
fi
if [ ${install[jdk]} -eq 1 ]; then
install_jdk
fi
if [ ${install[maven]} -eq 1 ]; then
install_maven
fi
if [ ${install[nodejs]} -eq 1 ]; then
install_nodejs
fi
if [ ${install[python3]} -eq 1 ]; then
install_python3
fi
if [ ${install[python2]} -eq 1 ]; then
install_python2
fi
if [ ${install[uaac]} -eq 1 ]; then
install_uaac
fi
if [ ${install[predixcli]} -eq 1 ]; then
install_predixcli
fi
if [ ${install[mobilecli]} -eq 1 ]; then
install_mobilecli
fi
if [ ${install[androidstudio]} -eq 1 ]; then
install_android_studio
fi
if [ ${install[docker]} -eq 1 ]; then
install_docker
fi
if [ ${install[vmware]} -eq 1 ]; then
install_vmware
fi
}
function check_status() {
if [ $STATUS != 0 ]; then
echo
echo "brew install for $TOOL failed"
read -p "Would you like to keep going? (y/n) > " -t 300 answer
if [[ -z $answer ]]; then
echo -n "Specify (yes/no)> "
read answer
fi
if [[ ${answer:0:1} == "y" ]] || [[ ${answer:0:1} == "Y" ]]; then
echo
echo "Continuing to next tool installation"
else
echo
echo "Exiting ..."
exit 1
fi
fi
}
run_setup $@
# Running Proxy Scripts
echo
echo "Pulling proxy scripts from predix-scripts"
get_proxy_scripts
echo
echo "Running verify-proxy.sh"
source verify-proxy.sh