Revision 1da30dfc setup.sh

View differences:

setup.sh
23 23

  
24 24
#!/bin/bash
25 25

  
26
# initial info text (can be disabled with 'no_info' as last argument)
27
if [[ ! ${!#} = "no_info" ]]; then
26
################################################################################
27
# GENERIC FUNCTIONS                                                            #
28
################################################################################
29

  
30
### print an error
31
# arguments:
32
#   - error string [required]
33
# return: n/a
34
function printError {
35
  local string="ERROR:   $1"
36

  
37
  # if a log file is specified
38
  if [ ! -z $LOG_FILE ]; then
39
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
40
  fi
41
  printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2
42
}
43

  
44
### print a warning
45
# arguments:
46
#   - warning string [required]
47
# return: n/a
48
function printWarning {
49
  local string="WARNING: $1"
50

  
51
  # if a log file is specified
52
  if [ ! -z $LOG_FILE ]; then
53
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
54
  fi
55
  printf "$(tput setaf 3)>>> $string$(tput sgr 0)" 1>&2
56
}
57

  
58
### print an information text
59
# arguments:
60
#   - information string [required]
61
# return: n/a
62
function printInfo {
63
  local string="INFO:    $1"
64

  
65
  # if a log file is specified
66
  if [ ! -z $LOG_FILE ]; then
67
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
68
  fi
69
  printf "$(tput setaf 2)>>> $string$(tput sgr 0)" 1>&2
70
}
71

  
72
### print a message to the log file
73
# arguments:
74
#   - information string [required]
75
# return: n/a
76
function printLog {
77
  local string="LOG:     $1"
78

  
79
  # if a log file is specified
80
  if [ ! -z $LOG_FILE ]; then
81
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
82
  fi
83
}
84

  
85
### exit the script normally
86
# arguments: n/a
87
# return: 0 (success)
88
function quitScript {
89
  printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n"
90
  printf "\n"
91
  printf "######################################################################\n"
92

  
93
  exit 0
94
}
95

  
96
### read a user input
97
# arguments:
98
#   --numchars, -n  maximum number of characters to read
99
#   --options, -o   possible chacters to select (only applies if numchars=1)
100
#   --out, -e       output variable to store the user input to
101
# return: error code
102
#   -  0: no error
103
#   - -1: error: invalid arguments
104
function readUserInput {
105
  # parse arguments
106
  local arguments=$(getopt -l num-chars:,options:,out: -o n:o:e: -- "$@")
107
  if [ $? != 0 ]; then
108
    printError "could not interprete arguments."
109
    return -1
110
  fi
111
  eval set -- "$arguments"
112

  
113
  # evaluate arguments
114
  local numchars=1
115
  local options=""
116
  local outvar=""
117
  while [ true ]; do
118
    case "$1" in
119
      --num-chars|-n)
120
        numchars=$2; shift 2
121
        ;;
122
      --options|-o)
123
        options="$2"; shift 2
124
        ;;
125
      --out|-e)
126
        outvar=$2; shift 2
127
        ;;
128
      --) # end of options reached
129
        shift; break
130
        ;;
131
      *) # sanity check (return error)
132
        printError "unexpected argument: $1\n"; return -1
133
        ;;
134
    esac
135
  done
136

  
137
  # read user input
138
  local _userinput=""
139
  while [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); do
140
    read -p "your selection: " -n $numchars -e _userinput
141
    if [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); then
142
      printWarning "[$_userinput] is no valid action\n"
143
    fi
144
  done
145
  printLog "[$_userinput] has been selected\n"
146
  if [ ! -z "$outvar" ]; then
147
    eval $outvar="$_userinput"
148
  fi
149

  
150
  return 0
151
}
152

  
153
### set the log file
154
# arguments:
155
#   --file, -f    name of file [required]
156
#   --option, -o  option if file already exists [optional]
157
#                 a: append
158
#                 r: delete and restart
159
#                 n: disable log
160
#                 A: silent append (no message in the log file)
161
# return: error code
162
#   -  0: no error
163
#   -  1: warning: file already exists
164
#   -  2: warning: no file specified
165
#   - -1: error: invalid arguments
166
function setLogFile {
167
  # parse arguments
168
  local arguments=$(getopt -l file:,option: -o f:o: -- "$@")
169
  if [ $? != 0 ]; then
170
    printError "could not interprete arguments."
171
    return -1
172
  fi
173
  eval set -- "$arguments"
174

  
175
  # evaluate arguments
176
  local fname=""
177
  local option=""
178
  while [ true ]; do
179
    case "$1" in
180
      --file|f)
181
        if [ ! -z $2 ]; then
182
          fname="$(dirname $2)/$(basename $2)"
183
        else
184
          fname=""
185
        fi
186
        shift 2
187
        ;;
188
      --option|-o)
189
        case $2 in
190
          A)
191
            option="A"
192
            ;;
193
          a)
194
            option="a"
195
            ;;
196
          r)
197
            option="r"
198
            ;;
199
          n)
200
            option="n"
201
            ;;
202
          *) # sanity check (return error)
203
            printError "unexpected argument: $1\n"; return -1
204
            ;;
205
        esac
206
        shift 2
207
        ;;
208
      --) # end of options reached
209
        shift; break
210
        ;;
211
      *) # sanity check (return error)
212
        printError "unexpected argument: $1\n"; return -1
213
        ;;
214
    esac
215
  done
216

  
217
  # if no log file was specified
218
  if [ -z $fname ]; then
219
    printWarning "no log file specified (no log will be genreated)\n"
220
    LOG_FILE=""
221
    return 2
222
  # if file already exists
223
  elif [ -f $fname ]; then
224
    # if no option was specified, ask what to do
225
    if [ -z $option ]; then
226
      printWarning "log file ${fname} already esists\n"
227
      printf "Options:\n"
228
      printf "  [A] - append log\n"
229
      printf "  [R] - restart log (delete existing file)\n"
230
      printf "  [N] - no log\n"
231
      readUserInput --num-chars=1 --options="AaRrNn" --out=userinput
232
      option=${userinput,,}
233
    fi
234

  
235
    # evaluate option
236
    case $option in
237
      A)
238
        LOG_FILE=$(realpath $fname)
239
        ;;
240
      a)
241
        printInfo "appending log to existing file\n"
242
        LOG_FILE=$(realpath $fname)
243
        printf "\n" >> $LOG_FILE
244
        printf "######################################################################\n" >> $LOG_FILE
245
        printf "\n" >> $LOG_FILE
246
        ;;
247
      r)
248
        printInfo "old log file deleted, starting clean\n"
249
        LOG_FILE=$(realpath $fname)
250
        rm $LOG_FILE
251
        ;;
252
      n)
253
        printInfo "no log file will be generated\n"
254
        LOG_FILE=""
255
        ;;
256
      *) # sanity check (return error)
257
        printError "unexpected argument: $1\n"; return -1
258
        ;;
259
    esac
260

  
261
    return 1
262
  else
263
    printInfo "log file set to $(realpath $fname)\n"
264
    LOG_FILE=$(realpath $fname)
265
    return 0
266
  fi
267
}
268

  
269
################################################################################
270
# SPECIFIC FUNCTIONS                                                           #
271
################################################################################
272

  
273
### print welcome text
274
# arguments: n/a
275
# return: n/a
276
function printWelcomeText {
28 277
  printf "######################################################################\n"
29 278
  printf "#                                                                    #\n"
30 279
  printf "#                  Welcome to the AMiRo-BLT setup!                   #\n"
......
42 291
  printf "# Excellence Initiative.                                             #\n"
43 292
  printf "#                                                                    #\n"
44 293
  printf "######################################################################\n"
294
}
295

  
296
### print help text
297
# arguments: n/a
298
# return: n/a
299
function printHelp {
300
  printInfo "printing help text\n"
301
  printf "usage:  $(basename ${BASH_SOURCE[0]}) [options]\n"
302
  printf "options:\n"
303
  printf "  --help, -h        Print this help text.\n"
304
  printf "  --stm32flash, -f  Run stm32flash tool setup.\n"
305
  printf "  --SerialBoot, -s  Run SerialBoot tool setup.\n"
306
  printf "  --IDE, -e         Enter IDE setup.\n"
307
  printf "  --quit, -q        Quit the script.\n"
308
  printf "  --log=<file>      Specify a log file.\n"
309
}
310

  
311
### enter bootloader setup
312
# arguments n/a
313
# return:
314
#  -  0: no error
315
#  -  1: warning: function aborted by user
316
#  - -1: error: unexpected user input
317
function stm32flashSetup {
318
  local stm32flashdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/stm32flash/
319

  
320
  # if the stm32flash folder is not empty
321
  if [ ! -z "$(ls -A $stm32flashdir)" ]; then
322
    printWarning "$(realpath $stm32flashdir) is not empty. Delete and reinitialize? [y/n]\n"
323
    readUserInput --num-chars=1 --options="YyNn" --out=userinput
324
    case $userinput in
325
      Y|y)
326
        printInfo "wiping $stm32flashdir\n"
327
        git submodule deinit -f $stm32flashdir 2>&1 | tee -a $LOG_FILE
328
        ;;
329
      N|n)
330
        printWarning "stm32flash setup aborted by user\n"
331
        return 1
332
        ;;
333
      *) # sanity check (return error)
334
        printError "unexpected input: $userinput\n";
335
        return -1
336
        ;;
337
    esac
338
  fi
339

  
340
  # initialize submodule
341
  printInfo "initializing stm32flash submodule\n"
342
  git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE
343

  
344
  # build the stm32flash tool
345
  printInfo "compiling stm32flash\n"
346
  userdir=${PWD}
347
  cd "$stm32flashdir"
348
  make 2>&1 | tee -a $LOG_FILE
349
  cd "$userdir"
350

  
351
  return 0
352
}
353

  
354
### enter SerialBoot setup
355
# arguments n/a
356
# return:
357
#  -  0: no error
358
#  -  1: warning: function aborted by user
359
#  - -1: error: unexpected user input
360
function serialBootSetup {
361
  local serialbootdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/SerialBoot/
362

  
363
  # if a build folder already exists
364
  if [ -d "${serialbootdir}/build/" ]; then
365
    printWarning "SerialBoot has been built before. Delete and rebuild? [y/n]\n"
366
    readUserInput --num-chars=1 --options="YyNn" --out=userinput
367
    case $userinput in
368
      Y|y)
369
        printInfo "deleting ${serialbootdir}build/\n"
370
        rm -rf "${serialbootdir}build/"
371
        ;;
372
      N|n)
373
        printWarning "SerialBoot setup aborted by user\n"
374
        return 1
375
        ;;
376
      *) # sanity check (return error)
377
        printError "unexpected input: $userinput\n";
378
        return -1
379
        ;;
380
    esac
381
  fi
382

  
383
  # build SerialBoot
384
  printInfo "compiling SerialBoot\n"
385
  local userdir=${PWD}
386
  mkdir "${serialbootdir}build/"
387
  cd "${serialbootdir}build/"
388
  cmake .. 2>&1 | tee -a $LOG_FILE
389
  make 2>&1 | tee -a $LOG_FILE
390
  cd "$userdir"
391

  
392
  return 0
393
}
394

  
395
### enter IDE setup
396
# arguments n/a
397
# return: n/a
398
function ideSetup {
399
  printInfo "entering ideSetup setup\n"
45 400
  printf "\n"
46
fi
401
  if [ -z $LOG_FILE ]; then
402
    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/setup_IDE.sh --noinfo
403
  else
404
    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/setup_IDE.sh --LOG="$LOG_FILE" --noinfo
405
  fi
406
}
47 407

  
48
# initialization of variables
49
ARG_IDX=1
50
USER_INPUT=${!ARG_IDX}
408
################################################################################
409
# SCRIPT MAIN FUNCTION                                                         #
410
################################################################################
51 411

  
52
while [[ ! $USER_INPUT =~ ^[Ee]$ ]]; do
412
### main function of this script
413
# arguments: see help text
414
# return: error code
415
#   - 0: no error
416
#   - 1: error
417
function main {
418

  
419
  # parse arguments
420
  local arguments=$(getopt -l help,stm32flash,SerialBoot,IDE,quit,log:,LOG:,noinfo -o hfseq -- "$@")
421
  if [ $? != 0 ]; then
422
    printError "could not interprete arguments."
423
    exit 1
424
  fi
425
  eval set -- "$arguments"
53 426

  
54
  # main menu info prompt and selection
55
  printf "AMiRo-BLT setup\n"
56
  printf "===============\n"
427
  # print welcome/info text if not suppressed
428
  if [[ $@ != *"--noinfo"* ]]; then
429
    printWelcomeText
430
  else
431
    printf "######################################################################\n"
432
  fi
57 433
  printf "\n"
58
  if [[ -z $USER_INPUT || $USER_INPUT == "no_info" ]]; then
59
    printf "Please select one of the following actions:\n"
60
    printf "    [F] - stm32flash flashing tool setup\n"
61
    printf "    [S] - SerialBoot flashing tool setup\n"
62
    printf "    [Q] - setup QtCreator projects\n"
63
    printf "    [E] - exit this setup\n"
64

  
65
    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
66
      read -p "your selection: " -n 1 -e USER_INPUT
67
      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
68
        printf "[%s] is no valid action. \n" $USER_INPUT
69
      fi
434

  
435
  # set log file if specified
436
  if [[ $@ == *--log* || $@ == *--LOG* ]]; then
437
    # get the parameter (file name)
438
    local cmdidx=1
439
    while [ "${!cmdidx}" != "--log" ] && [ "${!cmdidx}" != "--LOG" ]; do
440
      cmdidx=$[cmdidx + 1]
70 441
    done
442
    local filenameidx=$[cmdidx + 1]
443
    # optionally force silent appending
444
    if [ "${!cmdidx}" == "--LOG" ]; then
445
      setLogFile --file="${!filenameidx}" --option=A
446
    else
447
      setLogFile --file="${!filenameidx}"
448
      printf "\n"
449
    fi
450
  fi
71 451

  
452
  # log script name
453
  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
454

  
455
  # if --help or -h was specified, print the help text and exit
456
  if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then
457
    printHelp
72 458
    printf "\n"
73
    printf "######################################################################\n"
74
    printf "\n"
459
    exitScript
75 460
  fi
76 461

  
77
  # action selection
78
  case $USER_INPUT in
79

  
80
    # stm32flash setup
81
    F|f)
82
      USER_DIR=${PWD}
83
      cd $(dirname ${BASH_SOURCE[0]})
84

  
85
      # initialize submodule
86
      git submodule update --init ./Host/Source/stm32flash/
87

  
88
      cd ./Host/Source/stm32flash/
89
      BUILD_STM32FLASH=true
90

  
91
      # test for existing bonary
92
      if [ -f stm32flash ]; then
93
        printf "WARNING: stm32flash binary already exists.\n"
94
        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
95
        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
96
          BUILD_STM32FLASH=true
97
          make clean
98
        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
99
          BUILD_STM32FLASH=false
100
          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
101
        else
102
          BUILD_STM32FLASH=false
103
        fi
104
     fi
105

  
106
      # build the tool if required
107
      if [ $BUILD_STM32FLASH = true ]; then
108
       make
109
      fi
462
  # handle command line arguments
463
  while [ true ]; do
464
    case $1 in
465
      --help|-h) # already handled; ignore
466
        shift 1;
467
        ;;
468
      --stm32flash|-f)
469
        stm32flashSetup; printf "\n"; shift 1
470
        ;;
471
      --SerialBoot|-s)
472
        serialBootSetup; printf "\n"; shift 1
473
        ;;
474
      --IDE|-e)
475
        IdeSetup; printf "\n"; shift 1;
476
        ;;
477
      --quit|-q)
478
        quitScript
479
        ;;
480
      --log|--LOG) # already handled; ignore
481
        shift 2
482
        ;;
483
      --noinfo) # already processed; ignore
484
        shift 1
485
        ;;
486
      --) # end of options reached
487
        shift; break
488
        ;;
489
      *) # sanity check (exit with error)
490
        printError "unexpected argument: $1\n"; exit -1
491
        ;;
492
    esac
493
  done
110 494

  
111
      cd $USER_DIR
112
      ;;
495
  # interactive menu
496
  while [ true ]; do
497
    # main menu info prompt and selection
498
    printInfo "AMiRo-BLT main menu\n"
499
    printf "Please select one of the following actions:\n"
500
    printf "  [F] - get and build stm32flash tool\n"
501
    printf "  [S] - build SerialBoot tool\n"
502
    printf "  [E] - IDE project setup\n"
503
    printf "  [Q] - quit this setup\n"
504
    readUserInput --num-chars=1 --options="FfSsEeQq" --out=userinput
505
    printf "\n"
113 506

  
114
    # SerailBoot setup
115
    S|s)
116
      # print setup header
117
      printf "SerialBoot setup\n"
118
      printf "================\n"
119
      printf "\n"
507
    # evaluate user selection
508
    case $userinput in
509
      I|i)
510
        projectInitialization; printf "\n"
511
        ;;
512
      F|f)
513
        stm32flashSetup; printf "\n"
514
        ;;
515
      S|s)
516
        serialBootSetup; printf "\n"
517
        ;;
518
      E|e)
519
        ideSetup; printf "\n"
520
        ;;
521
      Q|q)
522
        quitScript
523
        ;;
524
      *) # sanity check (exit with error)
525
        printError "unexpected argument: $userinput\n"; exit -1
526
        ;;
527
    esac
528
  done
120 529

  
121
      USER_DIR=${PWD}
122
      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot/
123
      BUILD_SERIALBOOT=true
124

  
125
      # test for existing binary
126
      if [ -f build/SerialBoot ]; then
127
        printf "WARNING: SerialBoot binary already exists.\n"
128
        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
129
        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
130
          BUILD_SERIALBOOT=true
131
          rm -rf build/
132
        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
133
          BUILD_SERIALBOOT=false
134
          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
135
        else
136
          BUILD_SERIALBOOT=false
137
        fi
138
      fi
139

  
140
      # build the tool if requested
141
      if [ $BUILD_SERIALBOOT = true ]; then
142
        mkdir build
143
        cd build
144
        cmake ..
145
        make
146
      fi
147

  
148
      cd $USER_DIR
149
      ;;
150

  
151
    # QtCreator setup
152
    Q|q)
153
      # calling the script with no arguments prints the help and returns
154
      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info
155
      printf "\n"
156
      # set deafult arguments and call the script again
157
      USER_INPUT="clean all"
158
      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
159
      printf "\n"
160
      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info $USER_INPUT
161
      ;;
162

  
163
    # exit
164
    E|e)
165
      break;
166
      ;;
167

  
168
    # sanity check
169
    *)
170
      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
171
      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
172
      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
173
      printf "\n"
174
      exit
175
      ;;
530
  exit 0
531
}
176 532

  
177
  esac
533
################################################################################
534
# SCRIPT ENTRY POINT                                                           #
535
################################################################################
178 536

  
179
  printf "\n"
180
  printf "######################################################################\n"
181
  printf "\n"
537
main "$@"
182 538

  
183
  let ARG_IDX++
184
  USER_INPUT=${!ARG_IDX}
185 539

  
186
done
540
## initial info text (can be disabled with 'no_info' as last argument)
541
#if [[ ! ${!#} = "no_info" ]]; then
542
#  printf "######################################################################\n"
543
#  printf "#                                                                    #\n"
544
#  printf "#                  Welcome to the AMiRo-BLT setup!                   #\n"
545
#  printf "#                                                                    #\n"
546
#  printf "######################################################################\n"
547
#  printf "#                                                                    #\n"
548
#  printf "# Copyright (c) 2016..2017  Thomas Schöpping                         #\n"
549
#  printf "#                                                                    #\n"
550
#  printf "# This is free software; see the source for copying conditions.      #\n"
551
#  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
552
#  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
553
#  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
554
#  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
555
#  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
556
#  printf "# Excellence Initiative.                                             #\n"
557
#  printf "#                                                                    #\n"
558
#  printf "######################################################################\n"
559
#  printf "\n"
560
#fi
561
#
562
## initialization of variables
563
#ARG_IDX=1
564
#USER_INPUT=${!ARG_IDX}
565
#
566
#while [[ ! $USER_INPUT =~ ^[Ee]$ ]]; do
567
#
568
#  # main menu info prompt and selection
569
#  printf "AMiRo-BLT setup\n"
570
#  printf "===============\n"
571
#  printf "\n"
572
#  if [[ -z $USER_INPUT || $USER_INPUT == "no_info" ]]; then
573
#    printf "Please select one of the following actions:\n"
574
#    printf "    [F] - stm32flash flashing tool setup\n"
575
#    printf "    [S] - SerialBoot flashing tool setup\n"
576
#    printf "    [Q] - setup QtCreator projects\n"
577
#    printf "    [E] - exit this setup\n"
578
#
579
#    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
580
#      read -p "your selection: " -n 1 -e USER_INPUT
581
#      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
582
#        printf "[%s] is no valid action. \n" $USER_INPUT
583
#      fi
584
#    done
585
#
586
#    printf "\n"
587
#    printf "######################################################################\n"
588
#    printf "\n"
589
#  fi
590
#
591
#  # action selection
592
#  case $USER_INPUT in
593
#
594
#    # stm32flash setup
595
#    F|f)
596
#      USER_DIR=${PWD}
597
#      cd $(dirname ${BASH_SOURCE[0]})
598
#
599
#      # initialize submodule
600
#      git submodule update --init ./Host/Source/stm32flash/
601
#
602
#      cd ./Host/Source/stm32flash/
603
#      BUILD_STM32FLASH=true
604
#
605
#      # test for existing bonary
606
#      if [ -f stm32flash ]; then
607
#        printf "WARNING: stm32flash binary already exists.\n"
608
#        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
609
#        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
610
#          BUILD_STM32FLASH=true
611
#          make clean
612
#        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
613
#          BUILD_STM32FLASH=false
614
#          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
615
#        else
616
#          BUILD_STM32FLASH=false
617
#        fi
618
#     fi
619
#
620
#      # build the tool if required
621
#      if [ $BUILD_STM32FLASH = true ]; then
622
#       make
623
#      fi
624
#
625
#      cd $USER_DIR
626
#      ;;
627
#
628
#    # SerailBoot setup
629
#    S|s)
630
#      # print setup header
631
#      printf "SerialBoot setup\n"
632
#      printf "================\n"
633
#      printf "\n"
634
#
635
#      USER_DIR=${PWD}
636
#      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot/
637
#      BUILD_SERIALBOOT=true
638
#
639
#      # test for existing binary
640
#      if [ -f build/SerialBoot ]; then
641
#        printf "WARNING: SerialBoot binary already exists.\n"
642
#        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
643
#        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
644
#          BUILD_SERIALBOOT=true
645
#          rm -rf build/
646
#        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
647
#          BUILD_SERIALBOOT=false
648
#          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
649
#        else
650
#          BUILD_SERIALBOOT=false
651
#        fi
652
#      fi
653
#
654
#      # build the tool if requested
655
#      if [ $BUILD_SERIALBOOT = true ]; then
656
#        mkdir build
657
#        cd build
658
#        cmake ..
659
#        make
660
#      fi
661
#
662
#      cd $USER_DIR
663
#      ;;
664
#
665
#    # QtCreator setup
666
#    Q|q)
667
#      # calling the script with no arguments prints the help and returns
668
#      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info
669
#      printf "\n"
670
#      # set deafult arguments and call the script again
671
#      USER_INPUT="clean all"
672
#      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
673
#      printf "\n"
674
#      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info $USER_INPUT
675
#      ;;
676
#
677
#    # exit
678
#    E|e)
679
#      break;
680
#      ;;
681
#
682
#    # sanity check
683
#    *)
684
#      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
685
#      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
686
#      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
687
#      printf "\n"
688
#      exit
689
#      ;;
690
#
691
#  esac
692
#
693
#  printf "\n"
694
#  printf "######################################################################\n"
695
#  printf "\n"
696
#
697
#  let ARG_IDX++
698
#  USER_INPUT=${!ARG_IDX}
699
#
700
#done
187 701

  

Also available in: Unified diff