amiro-blt / setup.sh @ 6aa90377
History | View | Annotate | Download (20.4 KB)
1 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
---|---|---|---|
2 | # AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
||
3 | # Robot (AMiRo) platform. # |
||
4 | 4f07e80a | Thomas Schöpping | # Copyright (C) 2016..2018 Thomas Schöpping et al. # |
5 | 4cce70a8 | Thomas Schöpping | # # |
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 | 0dc9f2f9 | Thomas Schöpping | # Possible values are 'a', 'c', 'r' and 'n'. |
173 | # - a: append (starts with a separator) |
||
174 | # - c: continue (does not insert a seperator) |
||
175 | 0a42f078 | Thomas Schöpping | # - r: delete and restart |
176 | # - n: no log |
||
177 | # If no option is secified but <file> exists, an interactive selection is provided. |
||
178 | # --quiet |
||
179 | # Suppress all messages. |
||
180 | # <infile> |
||
181 | # Path of the wanted log file. |
||
182 | # <outvar> |
||
183 | # Variable to store the path of the log file to. |
||
184 | # return: 0 |
||
185 | # No error or warning occurred. |
||
186 | # -1 |
||
187 | # Error: invalid input |
||
188 | # |
||
189 | function setLogFile { |
||
190 | local filepath="" |
||
191 | 1da30dfc | Thomas Schöpping | local option="" |
192 | 0a42f078 | Thomas Schöpping | local quiet=false |
193 | |||
194 | # parse arguments |
||
195 | local otherargs=() |
||
196 | while [ $# -gt 0 ]; do |
||
197 | if ( parseIsOption $1 ); then |
||
198 | case "$1" in |
||
199 | -o=*|--option=*) |
||
200 | option=${1#*=}; shift 1;; |
||
201 | -o*|--option*) |
||
202 | option="$2"; shift 2;; |
||
203 | -q|--quiet) |
||
204 | quiet=true; shift 1;; |
||
205 | *) |
||
206 | printError "invalid option: $1\n"; shift 1;; |
||
207 | esac |
||
208 | else |
||
209 | otherargs+=("$1") |
||
210 | shift 1 |
||
211 | fi |
||
212 | 1da30dfc | Thomas Schöpping | done |
213 | 0a42f078 | Thomas Schöpping | filepath=$(realpath ${otherargs[0]}) |
214 | 1da30dfc | Thomas Schöpping | |
215 | # if file already exists |
||
216 | 0a42f078 | Thomas Schöpping | if [ -e $filepath ]; then |
217 | 1da30dfc | Thomas Schöpping | # if no option was specified, ask what to do |
218 | 0a42f078 | Thomas Schöpping | if [ -z "$option" ]; then |
219 | printWarning "log file $filepath already esists\n" |
||
220 | local userinput="" |
||
221 | printf "Select what to do:\n" |
||
222 | 1da30dfc | Thomas Schöpping | printf " [A] - append log\n" |
223 | printf " [R] - restart log (delete existing file)\n" |
||
224 | printf " [N] - no log\n" |
||
225 | 0a42f078 | Thomas Schöpping | readUserInput "AaRrNn" userinput |
226 | 1da30dfc | Thomas Schöpping | option=${userinput,,} |
227 | fi |
||
228 | # evaluate option |
||
229 | 0a42f078 | Thomas Schöpping | case "$option" in |
230 | 0dc9f2f9 | Thomas Schöpping | a|c) |
231 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
232 | printInfo "appending log to $filepath\n" |
||
233 | fi |
||
234 | 0dc9f2f9 | Thomas Schöpping | if [ $option != c ]; then |
235 | printf "\n" >> $filepath |
||
236 | printf "######################################################################\n" >> $filepath |
||
237 | printf "\n" >> $filepath |
||
238 | fi |
||
239 | 1da30dfc | Thomas Schöpping | ;; |
240 | r) |
||
241 | 0a42f078 | Thomas Schöpping | echo -n "" > $filepath |
242 | if [ $quiet = false ]; then |
||
243 | printInfo "content of $filepath wiped\n" |
||
244 | fi |
||
245 | 1da30dfc | Thomas Schöpping | ;; |
246 | n) |
||
247 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
248 | printInfo "no log file will be generated\n" |
||
249 | fi |
||
250 | filepath="" |
||
251 | 1da30dfc | Thomas Schöpping | ;; |
252 | *) # sanity check (return error) |
||
253 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $option\n"; return -1;; |
254 | 1da30dfc | Thomas Schöpping | esac |
255 | else |
||
256 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
257 | printInfo "log file set to $filepath\n" |
||
258 | fi |
||
259 | 1da30dfc | Thomas Schöpping | fi |
260 | 0a42f078 | Thomas Schöpping | |
261 | eval ${otherargs[1]}="$filepath" |
||
262 | |||
263 | return 0 |
||
264 | 1da30dfc | Thomas Schöpping | } |
265 | |||
266 | ################################################################################ |
||
267 | # SPECIFIC FUNCTIONS # |
||
268 | ################################################################################ |
||
269 | |||
270 | 0a42f078 | Thomas Schöpping | ### print welcome text ######################################################### |
271 | # Prints a welcome message to standard out. |
||
272 | # |
||
273 | # usage: printWelcomeText |
||
274 | # arguments: n/a |
||
275 | # return: n/a |
||
276 | # |
||
277 | 1da30dfc | Thomas Schöpping | function printWelcomeText { |
278 | 4cce70a8 | Thomas Schöpping | printf "######################################################################\n" |
279 | printf "# #\n" |
||
280 | printf "# Welcome to the AMiRo-BLT setup! #\n" |
||
281 | printf "# #\n" |
||
282 | printf "######################################################################\n" |
||
283 | printf "# #\n" |
||
284 | 4f07e80a | Thomas Schöpping | printf "# Copyright (c) 2016..2018 Thomas Schöpping #\n" |
285 | 4cce70a8 | Thomas Schöpping | printf "# #\n" |
286 | printf "# This is free software; see the source for copying conditions. #\n" |
||
287 | printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
||
288 | printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
||
289 | printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
||
290 | printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
||
291 | printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
||
292 | printf "# Excellence Initiative. #\n" |
||
293 | printf "# #\n" |
||
294 | printf "######################################################################\n" |
||
295 | 1da30dfc | Thomas Schöpping | } |
296 | |||
297 | 0a42f078 | Thomas Schöpping | ### print help ################################################################# |
298 | # Prints a help text to standard out. |
||
299 | # |
||
300 | # usage: printHelp |
||
301 | # arguments: n/a |
||
302 | # return: n/a |
||
303 | # |
||
304 | 1da30dfc | Thomas Schöpping | function printHelp { |
305 | printInfo "printing help text\n" |
||
306 | 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" |
307 | printf "\n" |
||
308 | printf "options: -h, --help\n" |
||
309 | printf " Print this help text.\n" |
||
310 | printf " -f, --stm32flash\n" |
||
311 | printf " Run st,32flash tool setup.\n" |
||
312 | printf " -s, --SerialBoot\n" |
||
313 | printf " Run SerialBoot tool setup.\n" |
||
314 | printf " -e, --IDE\n" |
||
315 | printf " Enter IDE setup.\n" |
||
316 | printf " -c, --compiler\n" |
||
317 | printf " Enter compiler setup.\n" |
||
318 | printf " -q, --quit\n" |
||
319 | printf " Quit the script.\n" |
||
320 | printf " --log=<file>\n" |
||
321 | printf " Specify a log file.\n" |
||
322 | 1da30dfc | Thomas Schöpping | } |
323 | |||
324 | 0a42f078 | Thomas Schöpping | ### stm32flash tool setup ###################################################### |
325 | # Fetches the source code for the stm32flash tool and builds the binary. |
||
326 | # If the tool was already initialized, it can be wiped and rebuilt. |
||
327 | # |
||
328 | # usage: stm32flashSetup |
||
329 | # arguments: n/a |
||
330 | # return: 0 |
||
331 | # No error or warning occurred. |
||
332 | # 1 |
||
333 | # Warning: Setup aborted by user. |
||
334 | # -1 |
||
335 | # Error: Unexpected user input. |
||
336 | # |
||
337 | 1da30dfc | Thomas Schöpping | function stm32flashSetup { |
338 | 5690d84c | Thomas Schöpping | local amirobltdir=$(dirname $(realpath ${BASH_SOURCE[0]})) |
339 | 214352ae | Thomas Schöpping | local stm32flashdir=${amirobltdir}/Host/Source/stm32flash |
340 | 0a42f078 | Thomas Schöpping | local userdir=$(pwd) |
341 | 1da30dfc | Thomas Schöpping | |
342 | # if the stm32flash folder is not empty |
||
343 | if [ ! -z "$(ls -A $stm32flashdir)" ]; then |
||
344 | 0a42f078 | Thomas Schöpping | printWarning "$stm32flashdir is not empty. Delete and reinitialize? [y/n]\n" |
345 | local userinput="" |
||
346 | readUserInput "YyNn" userinput |
||
347 | case "$userinput" in |
||
348 | 1da30dfc | Thomas Schöpping | Y|y) |
349 | 0a42f078 | Thomas Schöpping | printInfo "wiping ${stm32flashdir}...\n" |
350 | # checkout base commit and delete all local branches |
||
351 | 5690d84c | Thomas Schöpping | cd $amirobltdir |
352 | 0a42f078 | Thomas Schöpping | git submodule update --force --checkout $stm32flashdir | tee -a $LOG_FILE |
353 | cd $stm32flashdir |
||
354 | local git_branches=($(git for-each-ref --format="%(refname)")) |
||
355 | for branch in $git_branches ; do |
||
356 | if [[ $branch = *"heads/"* ]]; then |
||
357 | git branch -D ${branch##*/} | tee -a $LOG_FILE |
||
358 | fi |
||
359 | done |
||
360 | 5690d84c | Thomas Schöpping | cd $amirobltdir |
361 | 0a42f078 | Thomas Schöpping | # deinit stm32flash submodule and delete any remaining files |
362 | 1da30dfc | Thomas Schöpping | git submodule deinit -f $stm32flashdir 2>&1 | tee -a $LOG_FILE |
363 | 0a42f078 | Thomas Schöpping | rm -rf $stm32flashdir/* |
364 | 5690d84c | Thomas Schöpping | cd $userdir |
365 | 1da30dfc | Thomas Schöpping | ;; |
366 | N|n) |
||
367 | printWarning "stm32flash setup aborted by user\n" |
||
368 | return 1 |
||
369 | ;; |
||
370 | *) # sanity check (return error) |
||
371 | printError "unexpected input: $userinput\n"; |
||
372 | return -1 |
||
373 | ;; |
||
374 | esac |
||
375 | fi |
||
376 | |||
377 | # initialize submodule |
||
378 | 0a42f078 | Thomas Schöpping | printInfo "initializing stm32flash submodule...\n" |
379 | 5690d84c | Thomas Schöpping | cd $amirobltdir |
380 | 1da30dfc | Thomas Schöpping | git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE |
381 | 66984f56 | Thomas Schöpping | while [ ${PIPESTATUS[0]} -ne 0 ]; do |
382 | printWarning "initialitaion failed. Retry? [y/n]\n" |
||
383 | local userinput="" |
||
384 | readUserInput "YyNn" userinput |
||
385 | case "$userinput" in |
||
386 | Y|y) |
||
387 | git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE;; |
||
388 | N|n) |
||
389 | printWarning "stm32flash initialization aborted by user\n" |
||
390 | 5690d84c | Thomas Schöpping | cd $userdir |
391 | 66984f56 | Thomas Schöpping | return 1 |
392 | ;; |
||
393 | *) # sanity check (return error) |
||
394 | printError "unexpected input: $userinput\n"; return -1;; |
||
395 | esac |
||
396 | done |
||
397 | 5690d84c | Thomas Schöpping | cd $userdir |
398 | 1da30dfc | Thomas Schöpping | |
399 | # build the stm32flash tool |
||
400 | printInfo "compiling stm32flash\n" |
||
401 | 214352ae | Thomas Schöpping | cd $stm32flashdir |
402 | 1da30dfc | Thomas Schöpping | make 2>&1 | tee -a $LOG_FILE |
403 | 214352ae | Thomas Schöpping | cd $userdir |
404 | 1da30dfc | Thomas Schöpping | |
405 | return 0 |
||
406 | } |
||
407 | |||
408 | 0a42f078 | Thomas Schöpping | ### SerialBoot tool setup ###################################################### |
409 | # Builds the SerialBoot tool. |
||
410 | # If the tool was built before, it can be deleted and rebuilt. |
||
411 | # |
||
412 | # usage: serialBootSetup |
||
413 | # arguments: n/a |
||
414 | # return: 0 |
||
415 | # No errort or warning occurred. |
||
416 | # 1 |
||
417 | # Warning: Setup aborted by user. |
||
418 | # -1 |
||
419 | # Error: Unexpected user input. |
||
420 | # |
||
421 | 1da30dfc | Thomas Schöpping | function serialBootSetup { |
422 | 214352ae | Thomas Schöpping | local amirobltdir=$(dirname $(realpath ${BASH_SOURCE[0]})) |
423 | local serialbootdir=${amirobltdir}/Host/Source/SerialBoot |
||
424 | 0a42f078 | Thomas Schöpping | local userdir=$(pwd) |
425 | 1da30dfc | Thomas Schöpping | |
426 | # if a build folder already exists |
||
427 | if [ -d "${serialbootdir}/build/" ]; then |
||
428 | printWarning "SerialBoot has been built before. Delete and rebuild? [y/n]\n" |
||
429 | 0a42f078 | Thomas Schöpping | local userinput="" |
430 | readUserInput "YyNn" userinput |
||
431 | case "$userinput" in |
||
432 | 1da30dfc | Thomas Schöpping | Y|y) |
433 | 6aa90377 | Thomas Schöpping | printInfo "deleting ${serialbootdir}/build/...\n" |
434 | rm -rf "${serialbootdir}/build/" |
||
435 | 1da30dfc | Thomas Schöpping | ;; |
436 | N|n) |
||
437 | printWarning "SerialBoot setup aborted by user\n" |
||
438 | return 1 |
||
439 | ;; |
||
440 | *) # sanity check (return error) |
||
441 | printError "unexpected input: $userinput\n"; |
||
442 | return -1 |
||
443 | ;; |
||
444 | esac |
||
445 | fi |
||
446 | |||
447 | # build SerialBoot |
||
448 | 0a42f078 | Thomas Schöpping | printInfo "compiling SerialBoot...\n" |
449 | 214352ae | Thomas Schöpping | mkdir ${serialbootdir}/build |
450 | cd ${serialbootdir}/build |
||
451 | 1da30dfc | Thomas Schöpping | cmake .. 2>&1 | tee -a $LOG_FILE |
452 | make 2>&1 | tee -a $LOG_FILE |
||
453 | 0a42f078 | Thomas Schöpping | cd $userdir |
454 | 1da30dfc | Thomas Schöpping | |
455 | return 0 |
||
456 | } |
||
457 | |||
458 | 0a42f078 | Thomas Schöpping | ### IDE setup ################################################################## |
459 | # Enter the IDE setup. |
||
460 | # |
||
461 | # usage: ideSetup |
||
462 | # arguments: n/a |
||
463 | # return: n/a |
||
464 | # |
||
465 | 1da30dfc | Thomas Schöpping | function ideSetup { |
466 | 0a42f078 | Thomas Schöpping | printInfo "entering IDE setup\n" |
467 | 4cce70a8 | Thomas Schöpping | printf "\n" |
468 | 0a42f078 | Thomas Schöpping | if [ -z "$LOG_FILE" ]; then |
469 | 9085c3a0 | Thomas Schöpping | $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --noinfo |
470 | 1da30dfc | Thomas Schöpping | else |
471 | 9085c3a0 | Thomas Schöpping | $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --LOG="$LOG_FILE" --noinfo |
472 | 1da30dfc | Thomas Schöpping | fi |
473 | } |
||
474 | 4cce70a8 | Thomas Schöpping | |
475 | 0a42f078 | Thomas Schöpping | ### compiler setup ############################################################# |
476 | # Enter the compiler setup. |
||
477 | # |
||
478 | # usage: compilerSetup |
||
479 | # arguments: n/a |
||
480 | # return: n/a |
||
481 | # |
||
482 | function compilerSetup { |
||
483 | printInfo "entering IDE setup\n" |
||
484 | printf "\n" |
||
485 | if [ -z "$LOG_FILE" ]; then |
||
486 | 9085c3a0 | Thomas Schöpping | $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/compiler/compilersetup.sh --noinfo |
487 | 0a42f078 | Thomas Schöpping | else |
488 | 9085c3a0 | Thomas Schöpping | $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/compiler/compilersetup.sh --LOG="$LOG_FILE" --noinfo |
489 | 1da30dfc | Thomas Schöpping | fi |
490 | 0a42f078 | Thomas Schöpping | } |
491 | 4cce70a8 | Thomas Schöpping | |
492 | 0a42f078 | Thomas Schöpping | ### main function of this script ############################################### |
493 | # A setup to initialize dependencies, setup IDE projects and configure the |
||
494 | # compiler setup. |
||
495 | # |
||
496 | # usage: see function printHelp |
||
497 | # arguments: see function printHelp |
||
498 | # return: 0 |
||
499 | # No error or warning occurred. |
||
500 | # |
||
501 | function main { |
||
502 | 1da30dfc | Thomas Schöpping | # print welcome/info text if not suppressed |
503 | if [[ $@ != *"--noinfo"* ]]; then |
||
504 | printWelcomeText |
||
505 | else |
||
506 | printf "######################################################################\n" |
||
507 | fi |
||
508 | 4cce70a8 | Thomas Schöpping | printf "\n" |
509 | 1da30dfc | Thomas Schöpping | |
510 | 1446566f | Thomas Schöpping | # if --help or -h was specified, print the help text and exit |
511 | if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
||
512 | printHelp |
||
513 | printf "\n" |
||
514 | quitScript |
||
515 | fi |
||
516 | |||
517 | 1da30dfc | Thomas Schöpping | # set log file if specified |
518 | 0a42f078 | Thomas Schöpping | if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
519 | 1da30dfc | Thomas Schöpping | # get the parameter (file name) |
520 | local cmdidx=1 |
||
521 | 0a42f078 | Thomas Schöpping | while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
522 | 1da30dfc | Thomas Schöpping | cmdidx=$[cmdidx + 1] |
523 | 4cce70a8 | Thomas Schöpping | done |
524 | 0a42f078 | Thomas Schöpping | local cmd="${!cmdidx}" |
525 | local logfile="" |
||
526 | if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
||
527 | logfile=${cmd#*=} |
||
528 | else |
||
529 | local filenameidx=$((cmdidx + 1)) |
||
530 | logfile="${!filenameidx}" |
||
531 | fi |
||
532 | 1da30dfc | Thomas Schöpping | # optionally force silent appending |
533 | 0a42f078 | Thomas Schöpping | if [[ "$cmd" = "--LOG"* ]]; then |
534 | 0dc9f2f9 | Thomas Schöpping | setLogFile --option=c --quiet "$logfile" LOG_FILE |
535 | 1da30dfc | Thomas Schöpping | else |
536 | 0a42f078 | Thomas Schöpping | setLogFile "$logfile" LOG_FILE |
537 | 1da30dfc | Thomas Schöpping | printf "\n" |
538 | fi |
||
539 | fi |
||
540 | # log script name |
||
541 | printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
||
542 | |||
543 | 0a42f078 | Thomas Schöpping | # parse arguments |
544 | local otherargs=() |
||
545 | while [ $# -gt 0 ]; do |
||
546 | if ( parseIsOption $1 ); then |
||
547 | case "$1" in |
||
548 | -h|--help) # already handled; ignore |
||
549 | shift 1;; |
||
550 | -f|--stm32flash) |
||
551 | stm32flashSetup; printf "\n"; shift 1;; |
||
552 | -s|--SerialBoot) |
||
553 | serialBootSetup; printf "\n"; shift 1;; |
||
554 | -e|--IDE) |
||
555 | ideSetup; printf "\n"; shift 1;; |
||
556 | -c|--compiler) |
||
557 | compilerSetup; printf "\n"; shift 1;; |
||
558 | -q|--quit) |
||
559 | 5690d84c | Thomas Schöpping | quitScript; shift 1;; |
560 | 0a42f078 | Thomas Schöpping | --log=*|--LOG=*) # already handled; ignore |
561 | shift 1;; |
||
562 | --log|--LOG) # already handled; ignore |
||
563 | shift 2;; |
||
564 | --noinfo) # already handled; ignore |
||
565 | shift 1;; |
||
566 | *) |
||
567 | printError "invalid option: $1\n"; shift 1;; |
||
568 | esac |
||
569 | else |
||
570 | otherargs+=("$1") |
||
571 | shift 1 |
||
572 | fi |
||
573 | 1da30dfc | Thomas Schöpping | done |
574 | 6886c3b6 | Thomas Schöpping | |
575 | 1da30dfc | Thomas Schöpping | # interactive menu |
576 | 0a42f078 | Thomas Schöpping | while ( true ); do |
577 | 1da30dfc | Thomas Schöpping | # main menu info prompt and selection |
578 | 0a42f078 | Thomas Schöpping | printInfo "AMiRo-BLT setup main menu\n" |
579 | 1da30dfc | Thomas Schöpping | printf "Please select one of the following actions:\n" |
580 | printf " [F] - get and build stm32flash tool\n" |
||
581 | printf " [S] - build SerialBoot tool\n" |
||
582 | printf " [E] - IDE project setup\n" |
||
583 | 0a42f078 | Thomas Schöpping | printf " [C] - enter compiler setup\n" |
584 | 1da30dfc | Thomas Schöpping | printf " [Q] - quit this setup\n" |
585 | 0a42f078 | Thomas Schöpping | local userinput="" |
586 | readUserInput "FfSsEeCcQq" userinput |
||
587 | 1da30dfc | Thomas Schöpping | printf "\n" |
588 | 6886c3b6 | Thomas Schöpping | |
589 | 1da30dfc | Thomas Schöpping | # evaluate user selection |
590 | 0a42f078 | Thomas Schöpping | case "$userinput" in |
591 | 1da30dfc | Thomas Schöpping | F|f) |
592 | 0a42f078 | Thomas Schöpping | stm32flashSetup; printf "\n";; |
593 | 1da30dfc | Thomas Schöpping | S|s) |
594 | 0a42f078 | Thomas Schöpping | serialBootSetup; printf "\n";; |
595 | 1da30dfc | Thomas Schöpping | E|e) |
596 | 0a42f078 | Thomas Schöpping | ideSetup; printf "\n";; |
597 | C|c) |
||
598 | compilerSetup; printf "\n";; |
||
599 | 1da30dfc | Thomas Schöpping | Q|q) |
600 | 5690d84c | Thomas Schöpping | quitScript;; |
601 | 1da30dfc | Thomas Schöpping | *) # sanity check (exit with error) |
602 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $userinput\n";; |
603 | 1da30dfc | Thomas Schöpping | esac |
604 | done |
||
605 | 4cce70a8 | Thomas Schöpping | |
606 | 1da30dfc | Thomas Schöpping | exit 0 |
607 | } |
||
608 | 4cce70a8 | Thomas Schöpping | |
609 | 1da30dfc | Thomas Schöpping | ################################################################################ |
610 | # SCRIPT ENTRY POINT # |
||
611 | ################################################################################ |
||
612 | 4cce70a8 | Thomas Schöpping | |
613 | 1da30dfc | Thomas Schöpping | main "$@" |