Statistics
| Branch: | Tag: | Revision:

amiro-blt / setup.sh @ 0a42f078

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