amiro-blt / setup.sh @ 1da30dfc
History | View | Annotate | Download (21.575 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 | ### 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 {
|
||
| 277 | 4cce70a8 | Thomas Schöpping | printf "######################################################################\n" |
| 278 | printf "# #\n" |
||
| 279 | printf "# Welcome to the AMiRo-BLT setup! #\n" |
||
| 280 | printf "# #\n" |
||
| 281 | printf "######################################################################\n" |
||
| 282 | printf "# #\n" |
||
| 283 | printf "# Copyright (c) 2016..2017 Thomas Schöpping #\n" |
||
| 284 | printf "# #\n" |
||
| 285 | printf "# This is free software; see the source for copying conditions. #\n" |
||
| 286 | printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
||
| 287 | printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
||
| 288 | printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
||
| 289 | printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
||
| 290 | printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
||
| 291 | printf "# Excellence Initiative. #\n" |
||
| 292 | printf "# #\n" |
||
| 293 | printf "######################################################################\n" |
||
| 294 | 1da30dfc | Thomas Schöpping | } |
| 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" |
||
| 400 | 4cce70a8 | Thomas Schöpping | printf "\n" |
| 401 | 1da30dfc | Thomas Schöpping | 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 | } |
||
| 407 | 4cce70a8 | Thomas Schöpping | |
| 408 | 1da30dfc | Thomas Schöpping | ################################################################################ |
| 409 | # SCRIPT MAIN FUNCTION # |
||
| 410 | ################################################################################ |
||
| 411 | 4cce70a8 | Thomas Schöpping | |
| 412 | 1da30dfc | Thomas Schöpping | ### 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" |
||
| 426 | 4cce70a8 | Thomas Schöpping | |
| 427 | 1da30dfc | Thomas Schöpping | # print welcome/info text if not suppressed |
| 428 | if [[ $@ != *"--noinfo"* ]]; then |
||
| 429 | printWelcomeText |
||
| 430 | else |
||
| 431 | printf "######################################################################\n" |
||
| 432 | fi |
||
| 433 | 4cce70a8 | Thomas Schöpping | printf "\n" |
| 434 | 1da30dfc | Thomas Schöpping | |
| 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] |
||
| 441 | 4cce70a8 | Thomas Schöpping | done |
| 442 | 1da30dfc | Thomas Schöpping | 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 |
||
| 451 | 4cce70a8 | Thomas Schöpping | |
| 452 | 1da30dfc | Thomas Schöpping | # 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 |
||
| 458 | 4cce70a8 | Thomas Schöpping | printf "\n" |
| 459 | 1da30dfc | Thomas Schöpping | exitScript |
| 460 | 4cce70a8 | Thomas Schöpping | fi |
| 461 | |||
| 462 | 1da30dfc | Thomas Schöpping | # 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 |
||
| 494 | 6886c3b6 | Thomas Schöpping | |
| 495 | 1da30dfc | Thomas Schöpping | # 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" |
||
| 506 | 6886c3b6 | Thomas Schöpping | |
| 507 | 1da30dfc | Thomas Schöpping | # 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 |
||
| 529 | 4cce70a8 | Thomas Schöpping | |
| 530 | 1da30dfc | Thomas Schöpping | exit 0 |
| 531 | } |
||
| 532 | 4cce70a8 | Thomas Schöpping | |
| 533 | 1da30dfc | Thomas Schöpping | ################################################################################ |
| 534 | # SCRIPT ENTRY POINT # |
||
| 535 | ################################################################################ |
||
| 536 | 4cce70a8 | Thomas Schöpping | |
| 537 | 1da30dfc | Thomas Schöpping | main "$@" |
| 538 | 4cce70a8 | Thomas Schöpping | |
| 539 | |||
| 540 | 1da30dfc | Thomas Schöpping | ## 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 |