amiro-blt / setup.sh @ 1446566f
History | View | Annotate | Download (19.742 KB)
1 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
---|---|---|---|
2 | # AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
||
3 | # Robot (AMiRo) platform. # |
||
4 | # Copyright (C) 2016..2017 Thomas Schöpping et al. # |
||
5 | # # |
||
6 | # This program is free software: you can redistribute it and/or modify # |
||
7 | # it under the terms of the GNU General Public License as published by # |
||
8 | # the Free Software Foundation, either version 3 of the License, or # |
||
9 | # (at your option) any later version. # |
||
10 | # # |
||
11 | # This program is distributed in the hope that it will be useful, # |
||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||
14 | # GNU General Public License for more details. # |
||
15 | # # |
||
16 | # You should have received a copy of the GNU General Public License # |
||
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # |
||
18 | # # |
||
19 | # This research/work was supported by the Cluster of Excellence Cognitive # |
||
20 | # Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is # |
||
21 | # funded by the German Research Foundation (DFG). # |
||
22 | ################################################################################ |
||
23 | |||
24 | #!/bin/bash |
||
25 | |||
26 | 1da30dfc | Thomas Schöpping | ################################################################################ |
27 | # GENERIC FUNCTIONS # |
||
28 | ################################################################################ |
||
29 | |||
30 | 0a42f078 | Thomas Schöpping | ### print an error message ##################################################### |
31 | # Prints a error <message> to standard output. |
||
32 | #If variable 'LOG_FILE' is specified, the message is also appended to the given file. |
||
33 | # |
||
34 | # usage: printError <message> |
||
35 | # arguments: <message> |
||
36 | # Message string to print. |
||
37 | # return: n/a |
||
38 | # |
||
39 | 1da30dfc | Thomas Schöpping | function printError { |
40 | local string="ERROR: $1" |
||
41 | # if a log file is specified |
||
42 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
43 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
44 | fi |
||
45 | printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
||
46 | } |
||
47 | |||
48 | 0a42f078 | Thomas Schöpping | ### print a warning message #################################################### |
49 | # Prints a warning <message> to standard output. |
||
50 | #If variable 'LOG_FILE' is specified, the message is also appended to the given file. |
||
51 | # |
||
52 | # usage: printMessage <message> |
||
53 | # arguments: <message> |
||
54 | # Message string to print. |
||
55 | # return: n/a |
||
56 | # |
||
57 | 1da30dfc | Thomas Schöpping | function printWarning { |
58 | local string="WARNING: $1" |
||
59 | # if a log file is specified |
||
60 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
61 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
62 | fi |
||
63 | 0a42f078 | Thomas Schöpping | printf "$(tput setaf 3)>>> $string$(tput sgr 0)" |
64 | 1da30dfc | Thomas Schöpping | } |
65 | |||
66 | 0a42f078 | Thomas Schöpping | ### print an information message ############################################### |
67 | # Prints an information <message> to standard output. |
||
68 | #If variable 'LOG_FILE' is specified, the message is also appended to the given file. |
||
69 | # |
||
70 | # usage: printInfo <message> |
||
71 | # arguments: <message> |
||
72 | # Message string to print. |
||
73 | # return: n/a |
||
74 | # |
||
75 | 1da30dfc | Thomas Schöpping | function printInfo { |
76 | local string="INFO: $1" |
||
77 | # if a log file is specified |
||
78 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
79 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
80 | fi |
||
81 | 0a42f078 | Thomas Schöpping | printf "$(tput setaf 2)>>> $string$(tput sgr 0)" |
82 | 1da30dfc | Thomas Schöpping | } |
83 | |||
84 | 0a42f078 | Thomas Schöpping | ### print a message to file #################################################### |
85 | # Appends a <message> to a log file, specified by the variable 'LOG_FILE'. |
||
86 | # |
||
87 | # usage printLog <message> |
||
88 | # arguments: <message> |
||
89 | # Message string to print. |
||
90 | # return: n/a |
||
91 | # |
||
92 | 1da30dfc | Thomas Schöpping | function printLog { |
93 | local string="LOG: $1" |
||
94 | # if a log file is specified |
||
95 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
96 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
97 | fi |
||
98 | } |
||
99 | |||
100 | 0a42f078 | Thomas Schöpping | ### exit the script normally ################################################### |
101 | # Prints a delimiter and exits the script normally (returns 0). |
||
102 | # |
||
103 | # usage: quitScript |
||
104 | # arguments: n/a |
||
105 | # return: 0 |
||
106 | # No error or warning occurred. |
||
107 | # |
||
108 | 1da30dfc | Thomas Schöpping | function quitScript { |
109 | 3719a40a | Thomas Schöpping | printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n" |
110 | printf "\n" |
||
111 | 1da30dfc | Thomas Schöpping | printf "######################################################################\n" |
112 | exit 0 |
||
113 | } |
||
114 | |||
115 | 0a42f078 | Thomas Schöpping | ### read a user input ########################################################## |
116 | # Reads a single character user input from a set up <options> and stores it in |
||
117 | # a given <return> variable. |
||
118 | # |
||
119 | # usage: readUserInput <options> <return> |
||
120 | # arguments: <options> |
||
121 | # String definiing the set of valid characters. |
||
122 | # If the string is empty, the user can input any character. |
||
123 | # <return> |
||
124 | # Variable to store the selected character to. |
||
125 | # return: n/a |
||
126 | # |
||
127 | 1da30dfc | Thomas Schöpping | function readUserInput { |
128 | 0a42f078 | Thomas Schöpping | local input="" |
129 | 1da30dfc | Thomas Schöpping | # read user input |
130 | 0a42f078 | Thomas Schöpping | while [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); do |
131 | read -p "your selection: " -n 1 -e input |
||
132 | if [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); then |
||
133 | printWarning "[$input] is no valid action\n" |
||
134 | 1da30dfc | Thomas Schöpping | fi |
135 | done |
||
136 | 0a42f078 | Thomas Schöpping | printLog "[$input] has been selected\n" |
137 | eval $2="$input" |
||
138 | 1da30dfc | Thomas Schöpping | } |
139 | |||
140 | 0a42f078 | Thomas Schöpping | ### check whether argument is an option ######################################## |
141 | # Checks a <string> whether it is an option. |
||
142 | # Options are defined to either start with '--' followed by any string, or |
||
143 | # to start with a single '-' followed by a single character, or |
||
144 | # to start with a single '-' followed by a single character, a '=' and any string. |
||
145 | # Examples: '--option', '--option=arg', '-o', '-o=arg', '--' |
||
146 | # |
||
147 | # usage: parseIsOption <string> |
||
148 | # arguments: <string> |
||
149 | # A string to check whether it is an option. |
||
150 | # return: 0 |
||
151 | # <string> is an option. |
||
152 | # -1 |
||
153 | # <string> is not an option. |
||
154 | # |
||
155 | function parseIsOption { |
||
156 | if [[ "$1" =~ ^-(.$|.=.*) ]] || [[ "$1" =~ ^--.* ]]; then |
||
157 | return 0 |
||
158 | else |
||
159 | 1da30dfc | Thomas Schöpping | return -1 |
160 | fi |
||
161 | 0a42f078 | Thomas Schöpping | } |
162 | 1da30dfc | Thomas Schöpping | |
163 | 0a42f078 | Thomas Schöpping | ### set the log file ########################################################### |
164 | # Sets a specified <infile> as log file and checks whether it already exists. |
||
165 | # If so, the log may either be appended to the file, its content can be cleared, |
||
166 | # or no log is generated at all. |
||
167 | # The resulting path is stored in <outvar>. |
||
168 | # |
||
169 | # usage: setLogFile [--option=<option>] [--quiet] <infile> <outvar> |
||
170 | # arguments: --option=<option> |
||
171 | # Select what to do if <file> already exists. |
||
172 | # Possible values are 'a', 'r' and 'n'. |
||
173 | # - a: append |
||
174 | # - r: delete and restart |
||
175 | # - n: no log |
||
176 | # If no option is secified but <file> exists, an interactive selection is provided. |
||
177 | # --quiet |
||
178 | # Suppress all messages. |
||
179 | # <infile> |
||
180 | # Path of the wanted log file. |
||
181 | # <outvar> |
||
182 | # Variable to store the path of the log file to. |
||
183 | # return: 0 |
||
184 | # No error or warning occurred. |
||
185 | # -1 |
||
186 | # Error: invalid input |
||
187 | # |
||
188 | function setLogFile { |
||
189 | local filepath="" |
||
190 | 1da30dfc | Thomas Schöpping | local option="" |
191 | 0a42f078 | Thomas Schöpping | local quiet=false |
192 | |||
193 | # parse arguments |
||
194 | local otherargs=() |
||
195 | while [ $# -gt 0 ]; do |
||
196 | if ( parseIsOption $1 ); then |
||
197 | case "$1" in |
||
198 | -o=*|--option=*) |
||
199 | option=${1#*=}; shift 1;; |
||
200 | -o*|--option*) |
||
201 | option="$2"; shift 2;; |
||
202 | -q|--quiet) |
||
203 | quiet=true; shift 1;; |
||
204 | *) |
||
205 | printError "invalid option: $1\n"; shift 1;; |
||
206 | esac |
||
207 | else |
||
208 | otherargs+=("$1") |
||
209 | shift 1 |
||
210 | fi |
||
211 | 1da30dfc | Thomas Schöpping | done |
212 | 0a42f078 | Thomas Schöpping | filepath=$(realpath ${otherargs[0]}) |
213 | 1da30dfc | Thomas Schöpping | |
214 | # if file already exists |
||
215 | 0a42f078 | Thomas Schöpping | if [ -e $filepath ]; then |
216 | 1da30dfc | Thomas Schöpping | # if no option was specified, ask what to do |
217 | 0a42f078 | Thomas Schöpping | if [ -z "$option" ]; then |
218 | printWarning "log file $filepath already esists\n" |
||
219 | local userinput="" |
||
220 | printf "Select what to do:\n" |
||
221 | 1da30dfc | Thomas Schöpping | printf " [A] - append log\n" |
222 | printf " [R] - restart log (delete existing file)\n" |
||
223 | printf " [N] - no log\n" |
||
224 | 0a42f078 | Thomas Schöpping | readUserInput "AaRrNn" userinput |
225 | 1da30dfc | Thomas Schöpping | option=${userinput,,} |
226 | fi |
||
227 | # evaluate option |
||
228 | 0a42f078 | Thomas Schöpping | case "$option" in |
229 | 1da30dfc | Thomas Schöpping | a) |
230 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
231 | printInfo "appending log to $filepath\n" |
||
232 | fi |
||
233 | printf "\n" >> $filepath |
||
234 | printf "######################################################################\n" >> $filepath |
||
235 | printf "\n" >> $filepath |
||
236 | 1da30dfc | Thomas Schöpping | ;; |
237 | r) |
||
238 | 0a42f078 | Thomas Schöpping | echo -n "" > $filepath |
239 | if [ $quiet = false ]; then |
||
240 | printInfo "content of $filepath wiped\n" |
||
241 | fi |
||
242 | 1da30dfc | Thomas Schöpping | ;; |
243 | n) |
||
244 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
245 | printInfo "no log file will be generated\n" |
||
246 | fi |
||
247 | filepath="" |
||
248 | 1da30dfc | Thomas Schöpping | ;; |
249 | *) # sanity check (return error) |
||
250 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $option\n"; return -1;; |
251 | 1da30dfc | Thomas Schöpping | esac |
252 | else |
||
253 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
254 | printInfo "log file set to $filepath\n" |
||
255 | fi |
||
256 | 1da30dfc | Thomas Schöpping | fi |
257 | 0a42f078 | Thomas Schöpping | |
258 | eval ${otherargs[1]}="$filepath" |
||
259 | |||
260 | return 0 |
||
261 | 1da30dfc | Thomas Schöpping | } |
262 | |||
263 | ################################################################################ |
||
264 | # SPECIFIC FUNCTIONS # |
||
265 | ################################################################################ |
||
266 | |||
267 | 0a42f078 | Thomas Schöpping | ### print welcome text ######################################################### |
268 | # Prints a welcome message to standard out. |
||
269 | # |
||
270 | # usage: printWelcomeText |
||
271 | # arguments: n/a |
||
272 | # return: n/a |
||
273 | # |
||
274 | 1da30dfc | Thomas Schöpping | function printWelcomeText { |
275 | 4cce70a8 | Thomas Schöpping | printf "######################################################################\n" |
276 | printf "# #\n" |
||
277 | printf "# Welcome to the AMiRo-BLT setup! #\n" |
||
278 | printf "# #\n" |
||
279 | printf "######################################################################\n" |
||
280 | printf "# #\n" |
||
281 | printf "# Copyright (c) 2016..2017 Thomas Schöpping #\n" |
||
282 | printf "# #\n" |
||
283 | printf "# This is free software; see the source for copying conditions. #\n" |
||
284 | printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
||
285 | printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
||
286 | printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
||
287 | printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
||
288 | printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
||
289 | printf "# Excellence Initiative. #\n" |
||
290 | printf "# #\n" |
||
291 | printf "######################################################################\n" |
||
292 | 1da30dfc | Thomas Schöpping | } |
293 | |||
294 | 0a42f078 | Thomas Schöpping | ### print help ################################################################# |
295 | # Prints a help text to standard out. |
||
296 | # |
||
297 | # usage: printHelp |
||
298 | # arguments: n/a |
||
299 | # return: n/a |
||
300 | # |
||
301 | 1da30dfc | Thomas Schöpping | function printHelp { |
302 | printInfo "printing help text\n" |
||
303 | 0a42f078 | Thomas Schöpping | printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-f|--stm32flash] [-s|--SerialBoot] [-e|--IDE] [-c|--compiler] [-q|--quit] [--log=<file>]\n" |
304 | printf "\n" |
||
305 | printf "options: -h, --help\n" |
||
306 | printf " Print this help text.\n" |
||
307 | printf " -f, --stm32flash\n" |
||
308 | printf " Run st,32flash tool setup.\n" |
||
309 | printf " -s, --SerialBoot\n" |
||
310 | printf " Run SerialBoot tool setup.\n" |
||
311 | printf " -e, --IDE\n" |
||
312 | printf " Enter IDE setup.\n" |
||
313 | printf " -c, --compiler\n" |
||
314 | printf " Enter compiler setup.\n" |
||
315 | printf " -q, --quit\n" |
||
316 | printf " Quit the script.\n" |
||
317 | printf " --log=<file>\n" |
||
318 | printf " Specify a log file.\n" |
||
319 | 1da30dfc | Thomas Schöpping | } |
320 | |||
321 | 0a42f078 | Thomas Schöpping | ### stm32flash tool setup ###################################################### |
322 | # Fetches the source code for the stm32flash tool and builds the binary. |
||
323 | # If the tool was already initialized, it can be wiped and rebuilt. |
||
324 | # |
||
325 | # usage: stm32flashSetup |
||
326 | # arguments: n/a |
||
327 | # return: 0 |
||
328 | # No error or warning occurred. |
||
329 | # 1 |
||
330 | # Warning: Setup aborted by user. |
||
331 | # -1 |
||
332 | # Error: Unexpected user input. |
||
333 | # |
||
334 | 1da30dfc | Thomas Schöpping | function stm32flashSetup { |
335 | local stm32flashdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/stm32flash/ |
||
336 | 0a42f078 | Thomas Schöpping | local userdir=$(pwd) |
337 | 1da30dfc | Thomas Schöpping | |
338 | # if the stm32flash folder is not empty |
||
339 | if [ ! -z "$(ls -A $stm32flashdir)" ]; then |
||
340 | 0a42f078 | Thomas Schöpping | printWarning "$stm32flashdir is not empty. Delete and reinitialize? [y/n]\n" |
341 | local userinput="" |
||
342 | readUserInput "YyNn" userinput |
||
343 | case "$userinput" in |
||
344 | 1da30dfc | Thomas Schöpping | Y|y) |
345 | 0a42f078 | Thomas Schöpping | printInfo "wiping ${stm32flashdir}...\n" |
346 | # checkout base commit and delete all local branches |
||
347 | git submodule update --force --checkout $stm32flashdir | tee -a $LOG_FILE |
||
348 | cd $stm32flashdir |
||
349 | local git_branches=($(git for-each-ref --format="%(refname)")) |
||
350 | for branch in $git_branches ; do |
||
351 | if [[ $branch = *"heads/"* ]]; then |
||
352 | git branch -D ${branch##*/} | tee -a $LOG_FILE |
||
353 | fi |
||
354 | done |
||
355 | cd $userdir |
||
356 | # deinit stm32flash submodule and delete any remaining files |
||
357 | 1da30dfc | Thomas Schöpping | git submodule deinit -f $stm32flashdir 2>&1 | tee -a $LOG_FILE |
358 | 0a42f078 | Thomas Schöpping | rm -rf $stm32flashdir/* |
359 | 1da30dfc | Thomas Schöpping | ;; |
360 | N|n) |
||
361 | printWarning "stm32flash setup aborted by user\n" |
||
362 | return 1 |
||
363 | ;; |
||
364 | *) # sanity check (return error) |
||
365 | printError "unexpected input: $userinput\n"; |
||
366 | return -1 |
||
367 | ;; |
||
368 | esac |
||
369 | fi |
||
370 | |||
371 | # initialize submodule |
||
372 | 0a42f078 | Thomas Schöpping | printInfo "initializing stm32flash submodule...\n" |
373 | 1da30dfc | Thomas Schöpping | git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE |
374 | |||
375 | # build the stm32flash tool |
||
376 | printInfo "compiling stm32flash\n" |
||
377 | userdir=${PWD} |
||
378 | cd "$stm32flashdir" |
||
379 | make 2>&1 | tee -a $LOG_FILE |
||
380 | cd "$userdir" |
||
381 | |||
382 | return 0 |
||
383 | } |
||
384 | |||
385 | 0a42f078 | Thomas Schöpping | ### SerialBoot tool setup ###################################################### |
386 | # Builds the SerialBoot tool. |
||
387 | # If the tool was built before, it can be deleted and rebuilt. |
||
388 | # |
||
389 | # usage: serialBootSetup |
||
390 | # arguments: n/a |
||
391 | # return: 0 |
||
392 | # No errort or warning occurred. |
||
393 | # 1 |
||
394 | # Warning: Setup aborted by user. |
||
395 | # -1 |
||
396 | # Error: Unexpected user input. |
||
397 | # |
||
398 | 1da30dfc | Thomas Schöpping | function serialBootSetup { |
399 | local serialbootdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/SerialBoot/ |
||
400 | 0a42f078 | Thomas Schöpping | local userdir=$(pwd) |
401 | 1da30dfc | Thomas Schöpping | |
402 | # if a build folder already exists |
||
403 | if [ -d "${serialbootdir}/build/" ]; then |
||
404 | printWarning "SerialBoot has been built before. Delete and rebuild? [y/n]\n" |
||
405 | 0a42f078 | Thomas Schöpping | local userinput="" |
406 | readUserInput "YyNn" userinput |
||
407 | case "$userinput" in |
||
408 | 1da30dfc | Thomas Schöpping | Y|y) |
409 | 0a42f078 | Thomas Schöpping | printInfo "deleting ${serialbootdir}build/...\n" |
410 | 1da30dfc | Thomas Schöpping | rm -rf "${serialbootdir}build/" |
411 | ;; |
||
412 | N|n) |
||
413 | printWarning "SerialBoot setup aborted by user\n" |
||
414 | return 1 |
||
415 | ;; |
||
416 | *) # sanity check (return error) |
||
417 | printError "unexpected input: $userinput\n"; |
||
418 | return -1 |
||
419 | ;; |
||
420 | esac |
||
421 | fi |
||
422 | |||
423 | # build SerialBoot |
||
424 | 0a42f078 | Thomas Schöpping | printInfo "compiling SerialBoot...\n" |
425 | mkdir ${serialbootdir}build/ |
||
426 | cd ${serialbootdir}build/ |
||
427 | 1da30dfc | Thomas Schöpping | cmake .. 2>&1 | tee -a $LOG_FILE |
428 | make 2>&1 | tee -a $LOG_FILE |
||
429 | 0a42f078 | Thomas Schöpping | cd $userdir |
430 | 1da30dfc | Thomas Schöpping | |
431 | return 0 |
||
432 | } |
||
433 | |||
434 | 0a42f078 | Thomas Schöpping | ### IDE setup ################################################################## |
435 | # Enter the IDE setup. |
||
436 | # |
||
437 | # usage: ideSetup |
||
438 | # arguments: n/a |
||
439 | # return: n/a |
||
440 | # |
||
441 | 1da30dfc | Thomas Schöpping | function ideSetup { |
442 | 0a42f078 | Thomas Schöpping | printInfo "entering IDE setup\n" |
443 | 4cce70a8 | Thomas Schöpping | printf "\n" |
444 | 0a42f078 | Thomas Schöpping | if [ -z "$LOG_FILE" ]; then |
445 | $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/idesetup.sh --noinfo |
||
446 | 1da30dfc | Thomas Schöpping | else |
447 | 0a42f078 | Thomas Schöpping | $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/idesetup.sh --LOG="$LOG_FILE" --noinfo |
448 | 1da30dfc | Thomas Schöpping | fi |
449 | } |
||
450 | 4cce70a8 | Thomas Schöpping | |
451 | 0a42f078 | Thomas Schöpping | ### compiler setup ############################################################# |
452 | # Enter the compiler setup. |
||
453 | # |
||
454 | # usage: compilerSetup |
||
455 | # arguments: n/a |
||
456 | # return: n/a |
||
457 | # |
||
458 | function compilerSetup { |
||
459 | printInfo "entering IDE setup\n" |
||
460 | printf "\n" |
||
461 | if [ -z "$LOG_FILE" ]; then |
||
462 | $(dirname $(realpath ${BASH_SOURCE[0]}))/compiler/compilersetup.sh --noinfo |
||
463 | else |
||
464 | $(dirname $(realpath ${BASH_SOURCE[0]}))/compiler/compilersetup.sh --LOG="$LOG_FILE" --noinfo |
||
465 | 1da30dfc | Thomas Schöpping | fi |
466 | 0a42f078 | Thomas Schöpping | } |
467 | 4cce70a8 | Thomas Schöpping | |
468 | 0a42f078 | Thomas Schöpping | ### main function of this script ############################################### |
469 | # A setup to initialize dependencies, setup IDE projects and configure the |
||
470 | # compiler setup. |
||
471 | # |
||
472 | # usage: see function printHelp |
||
473 | # arguments: see function printHelp |
||
474 | # return: 0 |
||
475 | # No error or warning occurred. |
||
476 | # |
||
477 | function main { |
||
478 | 5bd3a15e | Thomas Schöpping | local userdir=$(pwd) |
479 | cd $(realpath $(dirname ${BASH_SOURCE[0]})) |
||
480 | |||
481 | 1da30dfc | Thomas Schöpping | # print welcome/info text if not suppressed |
482 | if [[ $@ != *"--noinfo"* ]]; then |
||
483 | printWelcomeText |
||
484 | else |
||
485 | printf "######################################################################\n" |
||
486 | fi |
||
487 | 4cce70a8 | Thomas Schöpping | printf "\n" |
488 | 1da30dfc | Thomas Schöpping | |
489 | 1446566f | Thomas Schöpping | # if --help or -h was specified, print the help text and exit |
490 | if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
||
491 | printHelp |
||
492 | printf "\n" |
||
493 | cd $userdir |
||
494 | quitScript |
||
495 | fi |
||
496 | |||
497 | 1da30dfc | Thomas Schöpping | # set log file if specified |
498 | 0a42f078 | Thomas Schöpping | if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
499 | 1da30dfc | Thomas Schöpping | # get the parameter (file name) |
500 | local cmdidx=1 |
||
501 | 0a42f078 | Thomas Schöpping | while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
502 | 1da30dfc | Thomas Schöpping | cmdidx=$[cmdidx + 1] |
503 | 4cce70a8 | Thomas Schöpping | done |
504 | 0a42f078 | Thomas Schöpping | local cmd="${!cmdidx}" |
505 | local logfile="" |
||
506 | if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
||
507 | logfile=${cmd#*=} |
||
508 | else |
||
509 | local filenameidx=$((cmdidx + 1)) |
||
510 | logfile="${!filenameidx}" |
||
511 | fi |
||
512 | 1da30dfc | Thomas Schöpping | # optionally force silent appending |
513 | 0a42f078 | Thomas Schöpping | if [[ "$cmd" = "--LOG"* ]]; then |
514 | setLogFile --option=a --quiet "$logfile" LOG_FILE |
||
515 | 1da30dfc | Thomas Schöpping | else |
516 | 0a42f078 | Thomas Schöpping | setLogFile "$logfile" LOG_FILE |
517 | 1da30dfc | Thomas Schöpping | printf "\n" |
518 | fi |
||
519 | fi |
||
520 | # log script name |
||
521 | printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
||
522 | |||
523 | 0a42f078 | Thomas Schöpping | # parse arguments |
524 | local otherargs=() |
||
525 | while [ $# -gt 0 ]; do |
||
526 | if ( parseIsOption $1 ); then |
||
527 | case "$1" in |
||
528 | -h|--help) # already handled; ignore |
||
529 | shift 1;; |
||
530 | -f|--stm32flash) |
||
531 | stm32flashSetup; printf "\n"; shift 1;; |
||
532 | -s|--SerialBoot) |
||
533 | serialBootSetup; printf "\n"; shift 1;; |
||
534 | -e|--IDE) |
||
535 | ideSetup; printf "\n"; shift 1;; |
||
536 | -c|--compiler) |
||
537 | compilerSetup; printf "\n"; shift 1;; |
||
538 | -q|--quit) |
||
539 | 5bd3a15e | Thomas Schöpping | cd $userdir; quitScript; shift 1;; |
540 | 0a42f078 | Thomas Schöpping | --log=*|--LOG=*) # already handled; ignore |
541 | shift 1;; |
||
542 | --log|--LOG) # already handled; ignore |
||
543 | shift 2;; |
||
544 | --noinfo) # already handled; ignore |
||
545 | shift 1;; |
||
546 | *) |
||
547 | printError "invalid option: $1\n"; shift 1;; |
||
548 | esac |
||
549 | else |
||
550 | otherargs+=("$1") |
||
551 | shift 1 |
||
552 | fi |
||
553 | 1da30dfc | Thomas Schöpping | done |
554 | 6886c3b6 | Thomas Schöpping | |
555 | 1da30dfc | Thomas Schöpping | # interactive menu |
556 | 0a42f078 | Thomas Schöpping | while ( true ); do |
557 | 1da30dfc | Thomas Schöpping | # main menu info prompt and selection |
558 | 0a42f078 | Thomas Schöpping | printInfo "AMiRo-BLT setup main menu\n" |
559 | 1da30dfc | Thomas Schöpping | printf "Please select one of the following actions:\n" |
560 | printf " [F] - get and build stm32flash tool\n" |
||
561 | printf " [S] - build SerialBoot tool\n" |
||
562 | printf " [E] - IDE project setup\n" |
||
563 | 0a42f078 | Thomas Schöpping | printf " [C] - enter compiler setup\n" |
564 | 1da30dfc | Thomas Schöpping | printf " [Q] - quit this setup\n" |
565 | 0a42f078 | Thomas Schöpping | local userinput="" |
566 | readUserInput "FfSsEeCcQq" userinput |
||
567 | 1da30dfc | Thomas Schöpping | printf "\n" |
568 | 6886c3b6 | Thomas Schöpping | |
569 | 1da30dfc | Thomas Schöpping | # evaluate user selection |
570 | 0a42f078 | Thomas Schöpping | case "$userinput" in |
571 | 1da30dfc | Thomas Schöpping | F|f) |
572 | 0a42f078 | Thomas Schöpping | stm32flashSetup; printf "\n";; |
573 | 1da30dfc | Thomas Schöpping | S|s) |
574 | 0a42f078 | Thomas Schöpping | serialBootSetup; printf "\n";; |
575 | 1da30dfc | Thomas Schöpping | E|e) |
576 | 0a42f078 | Thomas Schöpping | ideSetup; printf "\n";; |
577 | C|c) |
||
578 | compilerSetup; printf "\n";; |
||
579 | 1da30dfc | Thomas Schöpping | Q|q) |
580 | 5bd3a15e | Thomas Schöpping | cd $userdir; quitScript;; |
581 | 1da30dfc | Thomas Schöpping | *) # sanity check (exit with error) |
582 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $userinput\n";; |
583 | 1da30dfc | Thomas Schöpping | esac |
584 | done |
||
585 | 4cce70a8 | Thomas Schöpping | |
586 | 5bd3a15e | Thomas Schöpping | cd $USER_DIR |
587 | 1da30dfc | Thomas Schöpping | exit 0 |
588 | } |
||
589 | 4cce70a8 | Thomas Schöpping | |
590 | 1da30dfc | Thomas Schöpping | ################################################################################ |
591 | # SCRIPT ENTRY POINT # |
||
592 | ################################################################################ |
||
593 | 4cce70a8 | Thomas Schöpping | |
594 | 1da30dfc | Thomas Schöpping | main "$@" |