-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDevBash.command
executable file
·471 lines (301 loc) · 14.1 KB
/
DevBash.command
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
#!/bin/bash
# Created by Elie Kassouf
# December 25th, 2019
##### CONFIGURATION #####
# Enable xpg_echo (allows escape-sequences with \n)
shopt -s xpg_echo
# Text Color NC = No Color
# https://stackoverflow.com/questions/5947742/
greenC='\033[1;32m'
nC='\033[0m'
# Emojis to add some color to the script
blueArrow="➡️ "
blueInfo="ℹ️ "
greenCheck="✅ "
redCross="❌ "
whiteQuestion="❔ "
redDoubleEx="‼️ "
##### CONFIGURATION #####
##### START OF HOMEBREW #####
# Need to make sure homebrew is properly configured because
# our development environments require it and some of its packages
# Postgres and Cask are required to setup my environment.
# Setup your own required flags here
postgresInstalled=false
caskInstalled=false
caskTapped=false
# Function to update brew we will have to use later
homebrewUpdated=false
updateHomebrew () {
# Don't run if it already has
if [[ $homebrewUpdated = false ]] ; then
echo "${blueArrow}Running Homebrew update and doctor before installing package: ${1}"
brew update
brew doctor
echo "${greenCheck}Homebrew update and doctor complete!"
homebrewUpdated=true
fi
}
# Function to setup homebrew packages after they are installed
setupHomebrewPackage() {
# Setup Cask (Will be used to install GUI Apps after homebrew packages are installed first)
if [[ $1 == "cask" ]]; then
echo "${blueArrow}Setting up cask. -> Tapping the Caskroom/Cask repository from Github using HTTPS."
brew tap caskroom/cask
caskTapped=true
caskInstalled=true
echo "${greenCheck}Cask is now setup!"
# Setup default postgres database
elif [[ $1 == "postgresql" ]]; then
echo "${blueArrow}Setting up postgresql..."
echo "${blueArrow}Starting postgresql..."
# Restart postgres
brew services restart postgres
postgresVersion=`postgres -V`
echo "${blueInfo}Postgres version: ${postgresVersion}"
# Create new database table
echo "${blueArrow}Initializing new database 'postgres'..."
initdb /usr/local/var/postgres -E utf8
# TODO: allow this script to create the default user and pass for the db
# Shutdown db
brew services stop postgres
postgresInstalled=true;
# Complete
echo "${greenCheck}Postgresql setup!\n${redDoubleEx}Don't forget to setup a user and password if you haven't already done so${redDoubleEx}"
else
echo "${blueInfo}${1} does NOT require setup! -> Skipping!"
fi
}
echo "\n${blueArrow}Verifying prerequisites..."
# Check if homebrew exists and install it if it doesn't
echo "\n${blueArrow}Checking if Homebrew is installed..."
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
echo "${redCross}Homebrew is NOT installed!"
echo "${blueArrow}Installing Homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "${greenCheck}Homebrew is installed!\n"
else
echo "${greenCheck}Homebrew is already installed!\n"
fi
# Install the required packages if they don't exist
echo "${blueArrow}Checking if required homebrew packages are installed\n"
# Required packages array.
# Add packages to the list.
# Make sure packages are on a newline or seperated by a space
requiredHomebrewPackages=(
"cask"
"postgresql"
"geoip"
"wget"
"jenv"
"heroku"
"python"
"sbt"
"imagemagick"
)
# Iterate and check if the package exists -> if not -> install it!
homebrewPackageExists=false
for i in "${requiredHomebrewPackages[@]}"; do
if brew ls --versions $i > /dev/null; then
echo "${greenCheck}${i} is already installed!"
homebrewPackageExists=true
# Check if cask and postgres are installed and set flag.
# Will be required later
if [[ $i == "cask" ]]; then
caskInstalled=true
elif [[ $i == "postgresql" ]]; then
postgresInstalled=true
fi
else
echo "${redCross}${i} is NOT installed!"
echo "${blueArrow}Installing ${i}..."
updateHomebrew "${i}"
brew install ${i}
setupHomebrewPackage "${i}"
echo "${greenCheck}${i} is now installed!"
fi
done
# If at least one package exists prompt the user if they want to update
homebrewUpgraded=false
if [[ $homebrewPackageExists = true ]]; then
outdatedBrewPackages=`brew outdated`
if [ -z "$outdatedBrewPackages" ]; then
echo "\n${greenCheck}Homebrew upgrade not required. -> All packages are up to date!\n"
else
# Propmt the user if they want to upgrade
echo "\n${blueInfo}One or more homebrew packages require an update:\n${outdatedBrewPackages}\n"
read -n1 -p "${whiteQuestion}Run Homebrew Upgrade? [Y/n] " userBrewUpgradeInput
echo "\n"
if [[ $userBrewUpgradeInput =~ ^[Yy]$ ]]; then
echo "\n${blueArrow}Upgrading Homebrew..."
brew upgrade
homebrewUpgraded=true
echo "${greenCheck}Homebrew upgrade completed."
fi
fi
fi
if [[ $caskInstalled = true ]]; then
echo "${blueArrow}Homebrew cask is intalled. -> Verifying required casks...\n"
# Requires Cask to be installed (see requiredHomebrewPackages above ^)
requiresHomebrewCasks=(
"alfred"
"expressvpn"
"iterm2"
"lastpass"
"vlc"
"db-browser-for-sqlite"
"grammarly"
"jetbrains-toolbox"
"slack"
)
# Iterate and check if the cask exists -> if not -> install it!
for i in "${requiresHomebrewCasks[@]}"; do
if brew cask ls --versions $i > /dev/null; then
echo "${greenCheck}${i} cask is already installed!"
else
echo "${redCross}${i} is NOT installed!"
# Tap caskroom/cask if not done already
if [[ $caskTapped = false ]]; then
echo "${blueArrow}Tapping the Caskroom/Cask repository from Github using HTTPS."
brew tap caskroom/cask
caskTapped=true
echo "${greenCheck}Tapping successful!"
fi
echo "${blueArrow}Installing cask: ${i}..."
brew cask install ${i}
echo "${greenCheck}${i} cask is now installed!"
fi
done
else
echo "${blueArrow}Homebrew cask is NOT intalled. -> Skipping cask verification and install"
fi
echo "\n"
# If homebrew was updated, run cleanup!
if [[ $homebrewUpdated = true ]] || [[ $homebrewUpgraded = true ]] ; then
echo "\n${blueArrow}Cleaning up homebrew..."
brew cleanup
echo "${greenCheck}Homebrew cleanup completed.\n\n"
fi
##### END OF HOMEBREW #####
##### START OF USER GREETING #####
# Greet the user with a custom greeting
timeOfDay=`date +%H`
# Fixes error with 08
# https://stackoverflow.com/a/37092657
timeOfDay=`expr $timeOfDay + 0`
if [[ $timeOfDay -lt 12 ]]; then
echo -e "Good morning ${greenC}${USER}${nC}!"
elif [[ $timeOfDay -lt 18 ]]; then
echo -e "Good afternoon ${greenC}${USER}${nC}!"
else
echo -e "Good evening ${greenC}${USER}${nC}!"
fi
echo "What are you working on this fine day?\n"
##### END OF USER GREETING #####
##### START OF ENVIRONMENT SETUP ######
# TODO: Clean up this section. Options below should be stored in a array. Seems like a lot of repetitive code..
# Here we can take advantage of starting specific services and
# setting up the required environment the user wants to work within.
# Configure the selectable environments to prompt
envA='Project 1 (API)'
envB='Project 1 (APP)'
envC='Project 1 (APP and API)'
envD='Project 2'
envE='Upgrade all casks (--greedy) *use cautiously*'
promptEnvironmentSelection () {
# Display the selectable environments
echo "a) ${envA}"
echo "b) ${envB}"
echo "c) ${envC}"
echo "d) ${envD}"
echo "e) ${envE}"
echo "\n${blueInfo}'x' will exit this process\n"
# Prompting: -p and specifying 1-character-input -n1 allows to insert option without ENTER key.
read -n1 -p "${whiteQuestion}Option: " userEnvironmentInput
# Add a line break to make it visually pleasing
echo "\n"
# All environments require postgres running so make sure it's up and running
if [[ $userEnvironmentInput =~ ^[AaBbCcDd]$ ]]; then
if [[ $postgresInstalled = true ]] ; then
echo "${blueArrow}Firing up postgresql..."
brew services restart postgres
echo "${greenCheck}Postgres is up and running!\n"
else
echo "${redCross}ERROR! -> Postgres is NOT installed!\n"
fi
fi
# Check what environement the user wants to setup
if [[ $userEnvironmentInput =~ ^[Aa]$ ]]; then
echo "${blueArrow}Setting up environment for: ${envA}...\n"
echo "\n${blueArrow}Opening required applications..."
open "/Applications/Google Chrome.app"
# TODO: There needs to be a better way to open IntellIJ for now replace '193.5662.53' with your own version number
# Note: JetBrains keeps 2 copies of the IDE if installed via toolbox so you can easily roll back.
# You can specify the previous version below as well if required
cd ~/Library/Application\ Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/ && open "IntelliJ IDEA.app"
echo "\n${greenCheck}Environment for: ${envA} is now setup.\n${blueArrow}Please review the log above for other details"
# Launch Iterm and Open a new tab with a predefined profile
# In this case this will auto launch my web service
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) LOCALHOST"' -e 'end tell';
# Launch NGROK Profile in iTerm to make my web service open to the public over HTTPS
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) NGROK"' -e 'end tell';
elif [[ $userEnvironmentInput =~ ^[Bb]$ ]]; then
echo "${blueArrow}Setting up environment for: ${envB}...\n"
echo "\n${blueArrow}Opening required applications..."
open "/Applications/Atom.app"
open "/Applications/Google Chrome.app"
open "/Applications/Dash.app"
# Launch Iterm and Open a new tab with a predefined profile
# In this case this will auto launch my web service
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) LOCALHOST"' -e 'end tell';
# Launch NGROK Profile in iTerm to make my web service open to the public over HTTPS
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) NGROK"' -e 'end tell';
echo "\n${greenCheck}Environment for: ${envB} is now setup.\n${blueArrow}Please review the log above for other details"
elif [[ $userEnvironmentInput =~ ^[Cc]$ ]]; then
echo "${blueArrow}Setting up environment for: ${envC}...\n"
echo "\n${blueArrow}Opening required applications..."
open "/Applications/Atom.app"
open "/Applications/Google Chrome.app"
open "/Applications/Dash.app"
cd ~/Library/Application\ Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/ && open "IntelliJ IDEA.app"
# Launch Iterm and Open a new tab with a predefined profile
# In this case this will auto launch my web service
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) LOCALHOST"' -e 'end tell';
# Launch NGROK Profile in iTerm to make my web service open to the public over HTTPS
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) NGROK"' -e 'end tell';
echo "\n${greenCheck}Environment for: ${envC} is now setup.\n${blueArrow}Please review the log above for other details"
elif [[ $userEnvironmentInput =~ ^[Dd]$ ]]; then
echo "${blueArrow}Setting up environment for: ${envD}...\n"
echo "\n${blueArrow}Opening required applications..."
open "/Applications/iTerm.app"
open "/Applications/Google Chrome.app"
cd ~/Library/Application\ Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/193.5662.53/ && open "IntelliJ IDEA.app"
# Launch Iterm and Open a new tab with a predefined profile
# In this case this will auto launch my web service
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) LOCALHOST"' -e 'end tell';
# Launch NGROK Profile in iTerm to make my web service open to the public over HTTPS
#osascript -e 'tell application "iTerm"' -e 'activate' -e 'tell current window to set tb to create tab with profile "Project 1 (API) NGROK"' -e 'end tell';
echo "\n${greenCheck}Environment for: ${envD} is now setup.\n${blueArrow}Please review the log above for other details"
elif [[ $userEnvironmentInput =~ ^[Ee]$ ]]; then
#Upgrade
echo "${blueArrow}Upgrading all casks..."
#https://apple.stackexchange.com/a/326894
brew cask upgrade --greedy
echo "${greenCheck}Upgraded all casks!.\n"
# Re-prompt the user
promptEnvironmentSelection
elif [[ $userEnvironmentInput =~ ^[Xx]$ ]]; then
echo "Exiting...\n"
else
echo "${redCross}${userEnvironmentInput} is not a valid entry. Please try again...\n"
# Re-prompt the user
promptEnvironmentSelection
fi
}
# Prompt the user
promptEnvironmentSelection
##### END OF ENVIRONMENT SETUP ######
# Allow the terminal to close itself after completion
#osascript -e 'tell app "Terminal"' -e 'close (every window whose name contains ".command")' -e 'if number of windows = 0 then quit' -e 'end tell' & exit;