-
Notifications
You must be signed in to change notification settings - Fork 63
/
setup
executable file
·348 lines (310 loc) · 14.8 KB
/
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
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
#!/bin/bash
####################
# Global Variables #
####################
# Get base path
BASE=$(dirname "$0")
BASE=$(
cd $BASE
pwd -P
)
# Stash the tool directory
TOOLDIR=$BASE/tools
# Get System Architecture
ARCH=$(uname -m)
# Get System Operating System
OS=$(uname -s)
# Define name of the arm version we are downloading
BASE_URL="https://github.com/SJSU-Dev2"
PREREQUISITES=1
TOOL_BUNDLE=1
PYTHON_TOOLS=1
NXPPROG=1
LOCATION_FILE=1
LINK_PROJECTS=1
# Import SJSU-Dev2 common shell script functions
. $BASE/tools/common.sh
function print_status() {
if [ $1 -ne 0 ]; then
printf "$BOLD_RED"
printf "✘"
else
printf "$BOLD_GREEN"
printf "✔"
fi
printf "$RESET\n"
}
function print_status_nl() {
if [ $1 -ne 0 ]; then
printf "$BOLD_RED"
printf "✘ - failure"
else
printf "$BOLD_GREEN"
printf "✔ - success"
fi
printf "$RESET\n"
}
# Make sure only non-root users can run our script
function quit_if_script_was_run_as_root() {
if [[ $EUID -eq 0 ]]; then
echo "SJSU-DEV installer script must NOT be run as root! " 1>&2
exit 1
fi
}
function request_sudo_privileges() {
echo " ──────────────────────────────────────────────────┐"
echo " Acquiring sudo privileges "
echo "└────────────────────────────────────────────────── "
sudo echo "" || exit 1
}
function install_linux_prerequisites() {
echo " ──────────────────────────────────────────────────┐"
echo ""
echo " Installing Linux Prerequisites "
echo ""
echo "└────────────────────────────────────────────────── "
echo " ───────────────────────────────────────────────────┐"
echo " Updating Apt "
echo "└─────────────────────────────────────────────────── "
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt update
local apt_update=$?
print_status_nl $apt_update
echo " ────────────────────────────────────────────────────────┐"
echo " Installing git, make, python3 + pip, curl, tar, g++9 "
echo "└──────────────────────────────────────────────────────── "
sudo apt install -y git make curl tar tree g++-9 \
python3 python3-pip python3-setuptools
local apt_install=$?
print_status_nl $apt_install
echo " ──────────────────────────────────────────────────┐"
echo " Adding current user to 'dialout' group "
echo "└────────────────────────────────────────────────── "
sudo adduser $USER dialout
sudo udevadm control --reload-rules && sudo udevadm trigger
return $(($apt_update + $apt_install))
}
function install_mac_osx_prerequisites() {
echo " ──────────────────────────────────────────────────┐"
echo ""
echo " Installing Mac OSX Prerequisites "
echo ""
echo "└────────────────────────────────────────────────── "
echo " ───────────────────────────────────────────────────┐"
echo " Installing Homebrew "
echo "└─────────────────────────────────────────────────── "
local brew_install=0
which -s brew
if [[ $? -ne "0" ]]; then
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew_install=$?
fi
print_status_nl $brew_install
echo " ───────────────────────────────────────────────────┐"
echo " Prompt Git installer by invoking it "
echo "└─────────────────────────────────────────────────── "
git --version
local git_status=$?
print_status_nl $git_status
echo " ───────────────────────────────────────────────────┐"
echo " Brew Install Python@3 "
echo "└─────────────────────────────────────────────────── "
brew install python@3
echo " ───────────────────────────────────────────────────┐"
echo " Brew Installing gcc "
echo "└─────────────────────────────────────────────────── "
brew install gcc@10
brew link --overwrite gcc@10
return $(($git_status + $brew_install))
}
function install_python_tools() {
echo " ───────────────────────────────────────────────────┐"
echo " Upgrading PIP "
echo "└─────────────────────────────────────────────────── "
sudo -H python3 -m pip install --upgrade pip
local pip_status=$?
print_status_nl $pip_status
echo " ───────────────────────────────────────────────────┐"
echo " Installing Gcovr "
echo "└─────────────────────────────────────────────────── "
sudo -H python3 -m pip install --upgrade gcovr
local gcovr_status=$?
print_status_nl $gcovr_status
echo " ───────────────────────────────────────────────────┐"
echo " Installing/Upgrading Virtualenv "
echo "└─────────────────────────────────────────────────── "
sudo -H python3 -m pip install --upgrade virtualenv
local virtualenv_status=$?
print_status_nl $virtualenv_status
return $(($pip_status + $gcovr_status + $virtualenv_status))
}
function download_tools_bundle() {
cd "$TOOLDIR"
echo " ───────────────────────────────────────────────────┐"
echo " Downloading Build Tools "
echo "└─────────────────────────────────────────────────── "
rm -rf "gcc-arm-none-eabi-nano-exceptions/"
git clone --single-branch --branch "gcc9-2020-q2-update" \
"$BASE_URL/gcc-arm-none-eabi-nano-exceptions.git"
local git_clone=$?
print_status_nl $git_clone
return $(($git_clone))
}
function install_nxpprog() {
cd "$TOOLDIR"
echo " ───────────────────────────────────────────────────┐"
echo " Setting Up nxpprog "
echo "└─────────────────────────────────────────────────── "
rm -rf "nxpprog/"
git clone "$BASE_URL/nxpprog.git" "nxpprog/"
local git_clone=$?
print_status_nl $git_clone
cd "nxpprog/"
git checkout --quiet ea28bd0
local git_checkout=$?
printf "Verify nxpprog commit checkout... "
print_status_nl $git_checkout
./setup
local setup_status=$?
printf "Verify nxpprog setup... "
print_status_nl $setup_status
return $(($git_clone + $setup_status + $git_checkout))
}
function generate_location_file() {
echo " ───────────────────────────────────────────────────┐"
echo " Generating SJSU-Dev2 Location File "
echo "└─────────────────────────────────────────────────── "
local SETUP_VERSION=$(cat $BASE/setup_version.txt)
cat >~/.sjsu_dev2.mk <<EOL
# Location of SJSU-Dev2 folder
SJSU_DEV2_BASE = $BASE
PREVIOUS_SETUP_VERSION = $SETUP_VERSION
ifeq (,\$(wildcard \$(SJSU_DEV2_BASE)/))
\$(info +-------------- SJSU-Dev2 Folder Not Found Error ---------------+)
\$(info | |)
\$(info | To update the location of SJSU-Dev2's folder run ./setup |)
\$(info | |)
\$(info +---------------------------------------------------------------+)
\$(error )
endif
EOL
printf "Verify location file generation was successful... "
local generation_successful=$?
print_status_nl $generation_successful
return $generation_successful
}
function final_install_check() {
local prerequisites="$(print_status $PREREQUISITES)"
local tool_bundle="$(print_status $TOOL_BUNDLE)"
local python_tools="$(print_status $PYTHON_TOOLS)"
local nxpprog="$(print_status $NXPPROG)"
local install_was_successful=$(($PREREQUISITES + $TOOL_BUNDLE + $PYTHON_TOOLS + $NXPPROG))
if [[ $install_was_successful -ne "0" ]]; then
printf "\e[0;31m"
echo " =========================== "
echo "| Something went wrong! |"
echo "| |"
echo "| (╯°□ °)╯︵ ┻━┻ |"
printf "\e[0;31m"
echo "| |"
echo "| Prerequisites Install . %b |" $prerequisites
printf "\n"
echo "| Tools Install ......... %b |" $tool_bundle
printf "\n"
echo "| Python Tools .......... %b |" $python_tools
printf "\n"
echo "| Setup nxpprog ......... %b |" $nxpprog
printf "\n"
echo "| |"
echo " =========================== "
printf "\e[0m\n"
exit 1
else
printf "\e[0;32m"
echo " =========================== "
echo "| |"
printf "| Prerequisites Install . %b " $prerequisites
printf "\e[0;32m|\n"
printf "| Tools Install ......... %b " $tool_bundle
printf "\e[0;32m|\n"
printf "| Python Tools .......... %b " $python_tools
printf "\e[0;32m|\n"
printf "| Setup nxpprog ......... %b " $nxpprog
printf "\e[0;32m|\n"
echo "| |"
printf "| (•_•) |\r"
sleep .5
printf "| ( •_•)>⌐▪-▪ |\r"
sleep .5
printf "| (⌐▪_▪) |\n"
sleep .5
echo "| |"
echo "| SETUP COMPLETE! |"
echo "| |"
printf " =========================== "
printf "\e[0m\n"
generate_location_file
exit 0
fi
}
###############
# Setup Start #
###############
quit_if_script_was_run_as_root
if [[ "$1" == "--generate-location-file" ]]; then
echo " Generating Location File..."
generate_location_file
exit 0
fi
echo " ──────────────────────────────────────────────────┐"
echo " List of software installed globally: "
echo " 1) Python3 "
echo " 2) pip (Python3 package manager) "
echo " 3) Curl "
echo " 4) Git "
echo " 5) Gcovr "
echo " 6) XCode CLI tools (OSX Only) "
echo "└────────────────────────────────────────────────── "
request_sudo_privileges
echo " ──────────────────────────────────────────────────┐"
echo ""
echo " Starting SJSU-Dev2 Environment Setup Script "
echo ""
echo "└────────────────────────────────────────────────── "
if [[ "$OS" == "Linux" ]]; then # Linux
echo "Operating System: Linux"
TOOLS_BUNDLE_URL=$TOOLS_BUNDLE_URL_LINUX
install_linux_prerequisites
PREREQUISITES=$?
elif [[ "$OS" == "Darwin" ]]; then # Mac OSX
echo "Operating System: Mac OSX Darvin"
TOOLS_BUNDLE_URL=$TOOLS_BUNDLE_URL_OSX
install_mac_osx_prerequisites
PREREQUISITES=$?
else
# Default if Operating System other than Mac or Linux
echo -n "Only Linux or OSX systems are supported! Exiting..."
exit 1
fi
if [ "$PREREQUISITES" -ne "0" ]; then
printf "\e[0;31m"
printf " ─────────────────────────────────────────────────────────┐"
echo ""
printf " Prequisite Install Failed. "
echo ""
echo " Make sure: "
echo " - You are connected to the internet "
echo ""
printf "└───────────────────────────────────────────────────────── "
printf "\e[0m\n"
exit 1
fi
download_tools_bundle
TOOL_BUNDLE=$?
install_python_tools
PYTHON_TOOLS=$?
install_nxpprog
NXPPROG=$?
echo ""
final_install_check