-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_mac_beta.sh
executable file
·331 lines (305 loc) · 12.7 KB
/
setup_mac_beta.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
#! /bin/bash
set -e
default_env_name=$(basename $PWD)
function create_env_file() {
sample_env=".env.sample"
env_file=".env"
if [ -f "$env_file" ]; then
echo -e "·· \033[33mFile \033[32m$env_file\033[33m already exist\033[0m ··"
echo -e "\n·· Do you want to recopy \033[32m$sample_env\033[0m file data to \033[32m$env_file\033[0m file? [y/n] (Default is \033[31mn\033[0m): \c"
read recopy_dot_env_file
recopy_dot_env_file=${recopy_dot_env_file:-"n"}
if [ "${recopy_dot_env_file}" != "y" -a "${recopy_dot_env_file}" != "Y" ]; then
return 0
fi
fi
if [ -f "$sample_env" ]; then
cp $sample_env $env_file
echo -e "\n·· copied \033[32m$sample_env\033[0m file data to \033[32m$env_file\033[0m file ··"
echo -e "\n·· Do you want to modify \033[32m$env_file\033[0m file now? [y/n] (Default is \033[32my\033[0m): \c"
read modify_dot_env_file
modify_dot_env_file=${modify_dot_env_file:-"y"}
if [ "${modify_dot_env_file}" == "y" -o "${modify_dot_env_file}" == "Y" ]; then
vi $env_file
fi
else
echo -e "·· \033[31mFailed to create \033[4m$env_file\033[0m\033[31m file, because \033[4m$sample_env\033[0m\033[31m file is not present\033[0m ··"
fi
}
function check_homebrew() {
if command -v brew &>/dev/null; then
echo -e "\n·· \033[32mFound Homebrew in your system\033[0m ··\n\n"
else
echo -e "\n>>>> \033[31mPlease install \033[4mHomebrew\033[0m\033[31m and try again...\033[0m <<<<"
homebrew_menu
fi
}
function install_homebrew() {
if [[ $(command -v brew) == "" ]]; then
# Install Homebrew
echo -e "\n·· \033[32mInstalling Homebrew in your system\033[0m ··\n\n"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
brew update
fi
}
function check_python3() {
if command -v python3 &>/dev/null; then
echo -e "\n·· \033[32mFound $(python3 --version) in your system\033[0m ··\n\n"
else
echo -e "\n>>>> \033[31mPlease install \033[4mPython 3\033[0m\033[31m and try again...\033[0m <<<<"
python_menu
fi
}
function install_python3() {
check_homebrew
brew install python3
export PATH=/usr/local/bin:$PATH
check_python3
}
function check_openssl() {
if command -v openssl &>/dev/null; then
echo -e "\n·· \033[32mFound $(openssl version) in your system\033[0m ··\n\n"
echo -e "\n·· Exporting OpenSSL path ··\n\n"
OPENSSL_FULL_PATH="$(which openssl)"
OPENSSL_PATH="${OPENSSL_FULL_PATH%%bin*}"
export PATH="${OPENSSL_PATH}bin:$PATH"
export LDFLAGS="-L${OPENSSL_PATH}lib"
export CPPFLAGS="-I${OPENSSL_PATH}include"
else
echo -e "\n>>>> \033[31mAbsence of \033[4mOpenSSL\033[0m\033[31m may cause some requirement installation issue...\033[0m <<<<\n"
echo -e "\n>>>> \033[31mIn case of any error/issue please check Troubleshooting at \033[4mhttps://github.com/TuxEducation/django_rest_scaffolding#troubleshooting\033[0m <<<<\n"
fi
}
function check_virtualenvwrapper() {
echo -e "\n·· Checking for \033[32mvirtualenvwrapper.sh\033[0m file ··"
export VIRTUALENVWRAPPER_PYTHON="$(which python3)"
virtualenvwrapper_file='/usr/local/bin/virtualenvwrapper.sh'
while :; do
if [ -f "$virtualenvwrapper_file" -a "$(basename $virtualenvwrapper_file)" == "virtualenvwrapper.sh" ]; then
echo -e "\n·· \033[32mSuccessfully located \033[4mvirtualenvwrapper.sh\033[0m \033[32mfile\033[0m ··"
source $virtualenvwrapper_file
return 0
else
echo -e "\n·· \033[31mFailed to locate \033[4mvirtualenvwrapper.sh\033[0m\033[31m file at path $virtualenvwrapper_file\033[0m ··"
# echo -e "\npress \033[31mCTRL+C\033[0m to terminate OR enter \033[32mvirtualenvwrapper.sh\033[0m file path: \c"
echo -e "\n>>>> \033[31mPlease install \033[4mvirtualenvwrapper\033[0m\033[31m and try again...\033[0m <<<<"
# read virtualenvwrapper_file
python_menu
fi
done
}
function install_virtualenvwrapper() {
if command -v pip3 &>/dev/null; then
echo -e "\n·· \033[32mFound $(pip3 --version) in your system\033[0m ··\n\n"
echo -e "\n·· Installing \033[32mvirtualenv\033[0m ··\n\n"
pip3 install virtualenv
echo -e "\n·· Installing \033[32mvirtualenvwrapper\033[0m ··\n\n"
pip3 install virtualenvwrapper
touch ~/.bashrc
# TODO - Refactor below given code. (Everytime it is appending same line in bashrc file)
echo VIRTUALENVWRAPPER_PYTHON=`which python3` >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
echo "WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc
mkdir -p ~/.virtualenvs
source ~/.bashrc
echo -e "\n·· \033[32mSuccessfully installed virtual env wrapper \033[4mvirtualenvwrapper.sh\033[0m \033[32mfile\033[0m ··"
else
echo -e "\n>>>> \033[31mPlease install \033[4mPython 3\033[0m\033[31m and try again...\033[0m <<<<"
python_menu
fi
}
function remove_virtual_env() {
check_virtualenvwrapper
rmvirtualenv $1
}
function create_virtual_env() {
check_python3
check_openssl
echo '·······························································································'
echo -e '·· \033[33mPlease make sure that \033[4mVirtual Environment Wrapper\033[0m\033[33m is install before continuing this step\033[0m ··'
echo '·······························································································'
echo -e "\nDo you want to continue? [y/n] (Default is \033[32my\033[0m): \c"
read user_choice
user_choice=${user_choice:-"y"}
if [ "${user_choice}" != "y" -a "${user_choice}" != "Y" ]; then
echo -e "\n\033[31mExiting...\033[0m"
exit 0
fi
check_virtualenvwrapper
echo -e "\nVirtual Environment Name (Default is \033[32m\033[1m$default_env_name\033[0m]): \c"
read env_name
env_name=${env_name:-$default_env_name}
env_name="${env_name// /-}"
default_env_name=$env_name
echo -e "\nDo you want to install requirements? [y/n] (Default is \033[31mn\033[0m): \c"
read install_requirements_approval
install_requirements_approval=${install_requirements_approval:-"n"}
echo -e '\n\n·· creating virtual environment >>>> \033[32m'$env_name'\033[0m ··'
if [ "${install_requirements_approval}" == "y" -o "${install_requirements_approval}" == "Y" ]; then
cmd='mkvirtualenv --python='$(which python3)' '$env_name' -r requirements.pip'
else
cmd='mkvirtualenv --python='$(which python3)' '$env_name
fi
echo -e "\n\033[32m$cmd\033[0m\n"
$cmd || true # TODO: Find out why script is terminating at this point (Applied Hack to fix)
deactivate
echo -e "\n\033[32mSuccessfully created python virtual environment\033[0m\n"
}
function main() {
create_env_file
create_virtual_env
}
function install_requirements() {
check_virtualenvwrapper
check_openssl
echo -e "\nEnter Virtual Environment Name (Default is \033[32m\033[1m$default_env_name\033[0m]): \c"
read env_name
env_name=${env_name:-$default_env_name}
env_name="${env_name// /-}"
default_env_name=$env_name
workon $env_name || true # TODO: Find out why script is terminating at this point (Applied Hack to fix)
echo -e "Activated virtual enviroment : \033[32m$env_name\033[0m"
pip install -r requirements.pip
deactivate
}
function menu() {
while :; do
clear
echo '········································'
echo -e '·· \033[32mMENU\033[0m ··'
echo '········································'
echo '·· ··'
echo '·· 1. Run Steps [2,4,5] ··'
echo '·· 2. Create Virtual Env ··'
echo '·· 3. Remove Virtual Env ··'
echo '·· 4. Create .env file ··'
echo '·· 5. Install Requirements ··'
echo '·· 6. Install Python ··'
echo '·· 7. Install/Update Homebrew ··'
echo '·· 8. Exit ··'
echo '·· ··'
echo '········································'
echo -e 'Enter Your Choice : \c'
read menu_option
case $menu_option in
1)
echo "Initial Setup"
main
;;
2)
echo "Create Virtual Env"
create_virtual_env
;;
3)
echo "Remove Virtual Env"
echo -e "\nVirtual Environment Name (Default is \033[32m\033[1m$default_env_name\033[0m]): \c"
read env_name
env_name=${env_name:-$default_env_name}
env_name="${env_name// /-}"
echo -e '\n\nRemoving Virtual Environment >>>> \033[32m'$env_name'\033[0m'
echo -e '\nDo you want to continue? [y/n] (default is \033[32my\033[0m): \c'
read approval
approval=${approval:-"y"}
if [ "${approval}" == "y" -o "${approval}" == "Y" ]; then
remove_virtual_env $env_name
fi
;;
4)
echo "Create .env file"
create_env_file
;;
5)
echo "Install Requirements"
install_requirements
;;
6)
echo "Install Python"
install_python3
;;
7)
echo "Install Homebrew"
install_homebrew
;;
8)
echo "Exit"
exit 0
;;
*)
echo -e "\n\033[31mSorry, I don't understand\033[0m\n"
;;
esac
read -n 1 -s -r -p "Press any key to continue..."
done
}
function homebrew_menu() {
while :; do
echo '········································'
echo -e '·· \033[32mHOMEBREW\033[0m ··'
echo '········································'
echo '·· ··'
echo '·· 1. Install Homebrew ··'
echo '·· 2. Main Menu ··'
echo '·· 3. Exit ··'
echo '·· ··'
echo '········································'
echo -e 'Enter Your Choice : \c'
read menu_option
case $menu_option in
1)
echo "Install Homebrew"
install_homebrew
;;
2)
menu
;;
3)
echo "Exit"
exit 0
;;
*)
echo -e "\n\033[31mSorry, I don't understand\033[0m\n"
;;
esac
read -n 1 -s -r -p "Press any key to continue..."
clear
done
}
function python_menu() {
while :; do
echo '········································'
echo -e '·· \033[32mPYTHNN\033[0m ··'
echo '········································'
echo '·· ··'
echo '·· 1. Install Python ··'
echo '·· 2. Install Virtual Env Wrapper ··'
echo '·· 3. Main Menu ··'
echo '·· 4. Exit ··'
echo '·· ··'
echo '········································'
echo -e 'Enter Your Choice : \c'
read menu_option
case $menu_option in
1)
echo "Install Python"
install_python3
;;
2)
install_virtualenvwrapper
;;
3)
menu
;;
4)
echo "Exit"
exit 0
;;
*)
echo -e "\n\033[31mSorry, I don't understand\033[0m\n"
;;
esac
read -n 1 -s -r -p "Press any key to continue..."
clear
done
}
menu