commit 1da30dfceaecb44356c737ecc7cf25e801a1ea9a
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Tue Sep 26 17:02:05 2017 +0200

    Bash scripts enhanced.

diff --git a/setup.sh b/setup.sh
index a737815..65d73c4 100755
--- a/setup.sh
+++ b/setup.sh
@@ -23,8 +23,257 @@
 
 #!/bin/bash
 
-# initial info text (can be disabled with 'no_info' as last argument)
-if [[ ! ${!#} = "no_info" ]]; then
+################################################################################
+# GENERIC FUNCTIONS                                                            #
+################################################################################
+
+### print an error
+# arguments:
+#   - error string [required]
+# return: n/a
+function printError {
+  local string="ERROR:   $1"
+
+  # if a log file is specified
+  if [ ! -z $LOG_FILE ]; then
+    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
+  fi
+  printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2
+}
+
+### print a warning
+# arguments:
+#   - warning string [required]
+# return: n/a
+function printWarning {
+  local string="WARNING: $1"
+
+  # if a log file is specified
+  if [ ! -z $LOG_FILE ]; then
+    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
+  fi
+  printf "$(tput setaf 3)>>> $string$(tput sgr 0)" 1>&2
+}
+
+### print an information text
+# arguments:
+#   - information string [required]
+# return: n/a
+function printInfo {
+  local string="INFO:    $1"
+
+  # if a log file is specified
+  if [ ! -z $LOG_FILE ]; then
+    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
+  fi
+  printf "$(tput setaf 2)>>> $string$(tput sgr 0)" 1>&2
+}
+
+### print a message to the log file
+# arguments:
+#   - information string [required]
+# return: n/a
+function printLog {
+  local string="LOG:     $1"
+
+  # if a log file is specified
+  if [ ! -z $LOG_FILE ]; then
+    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
+  fi
+}
+
+### exit the script normally
+# arguments: n/a
+# return: 0 (success)
+function quitScript {
+  printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n"
+  printf "\n"
+  printf "######################################################################\n"
+
+  exit 0
+}
+
+### read a user input
+# arguments:
+#   --numchars, -n  maximum number of characters to read
+#   --options, -o   possible chacters to select (only applies if numchars=1)
+#   --out, -e       output variable to store the user input to
+# return: error code
+#   -  0: no error
+#   - -1: error: invalid arguments
+function readUserInput {
+  # parse arguments
+  local arguments=$(getopt -l num-chars:,options:,out: -o n:o:e: -- "$@")
+  if [ $? != 0 ]; then
+    printError "could not interprete arguments."
+    return -1
+  fi
+  eval set -- "$arguments"
+
+  # evaluate arguments
+  local numchars=1
+  local options=""
+  local outvar=""
+  while [ true ]; do
+    case "$1" in
+      --num-chars|-n)
+        numchars=$2; shift 2
+        ;;
+      --options|-o)
+        options="$2"; shift 2
+        ;;
+      --out|-e)
+        outvar=$2; shift 2
+        ;;
+      --) # end of options reached
+        shift; break
+        ;;
+      *) # sanity check (return error)
+        printError "unexpected argument: $1\n"; return -1
+        ;;
+    esac
+  done
+
+  # read user input
+  local _userinput=""
+  while [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); do
+    read -p "your selection: " -n $numchars -e _userinput
+    if [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); then
+      printWarning "[$_userinput] is no valid action\n"
+    fi
+  done
+  printLog "[$_userinput] has been selected\n"
+  if [ ! -z "$outvar" ]; then
+    eval $outvar="$_userinput"
+  fi
+
+  return 0
+}
+
+### set the log file
+# arguments:
+#   --file, -f    name of file [required]
+#   --option, -o  option if file already exists [optional]
+#                 a: append
+#                 r: delete and restart
+#                 n: disable log
+#                 A: silent append (no message in the log file)
+# return: error code
+#   -  0: no error
+#   -  1: warning: file already exists
+#   -  2: warning: no file specified
+#   - -1: error: invalid arguments
+function setLogFile {
+  # parse arguments
+  local arguments=$(getopt -l file:,option: -o f:o: -- "$@")
+  if [ $? != 0 ]; then
+    printError "could not interprete arguments."
+    return -1
+  fi
+  eval set -- "$arguments"
+
+  # evaluate arguments
+  local fname=""
+  local option=""
+  while [ true ]; do
+    case "$1" in
+      --file|f)
+        if [ ! -z $2 ]; then
+          fname="$(dirname $2)/$(basename $2)"
+        else
+          fname=""
+        fi
+        shift 2
+        ;;
+      --option|-o)
+        case $2 in
+          A)
+            option="A"
+            ;;
+          a)
+            option="a"
+            ;;
+          r)
+            option="r"
+            ;;
+          n)
+            option="n"
+            ;;
+          *) # sanity check (return error)
+            printError "unexpected argument: $1\n"; return -1
+            ;;
+        esac
+        shift 2
+        ;;
+      --) # end of options reached
+        shift; break
+        ;;
+      *) # sanity check (return error)
+        printError "unexpected argument: $1\n"; return -1
+        ;;
+    esac
+  done
+
+  # if no log file was specified
+  if [ -z $fname ]; then
+    printWarning "no log file specified (no log will be genreated)\n"
+    LOG_FILE=""
+    return 2
+  # if file already exists
+  elif [ -f $fname ]; then
+    # if no option was specified, ask what to do
+    if [ -z $option ]; then
+      printWarning "log file ${fname} already esists\n"
+      printf "Options:\n"
+      printf "  [A] - append log\n"
+      printf "  [R] - restart log (delete existing file)\n"
+      printf "  [N] - no log\n"
+      readUserInput --num-chars=1 --options="AaRrNn" --out=userinput
+      option=${userinput,,}
+    fi
+
+    # evaluate option
+    case $option in
+      A)
+        LOG_FILE=$(realpath $fname)
+        ;;
+      a)
+        printInfo "appending log to existing file\n"
+        LOG_FILE=$(realpath $fname)
+        printf "\n" >> $LOG_FILE
+        printf "######################################################################\n" >> $LOG_FILE
+        printf "\n" >> $LOG_FILE
+        ;;
+      r)
+        printInfo "old log file deleted, starting clean\n"
+        LOG_FILE=$(realpath $fname)
+        rm $LOG_FILE
+        ;;
+      n)
+        printInfo "no log file will be generated\n"
+        LOG_FILE=""
+        ;;
+      *) # sanity check (return error)
+        printError "unexpected argument: $1\n"; return -1
+        ;;
+    esac
+
+    return 1
+  else
+    printInfo "log file set to $(realpath $fname)\n"
+    LOG_FILE=$(realpath $fname)
+    return 0
+  fi
+}
+
+################################################################################
+# SPECIFIC FUNCTIONS                                                           #
+################################################################################
+
+### print welcome text
+# arguments: n/a
+# return: n/a
+function printWelcomeText {
   printf "######################################################################\n"
   printf "#                                                                    #\n"
   printf "#                  Welcome to the AMiRo-BLT setup!                   #\n"
@@ -42,146 +291,411 @@ if [[ ! ${!#} = "no_info" ]]; then
   printf "# Excellence Initiative.                                             #\n"
   printf "#                                                                    #\n"
   printf "######################################################################\n"
+}
+
+### print help text
+# arguments: n/a
+# return: n/a
+function printHelp {
+  printInfo "printing help text\n"
+  printf "usage:  $(basename ${BASH_SOURCE[0]}) [options]\n"
+  printf "options:\n"
+  printf "  --help, -h        Print this help text.\n"
+  printf "  --stm32flash, -f  Run stm32flash tool setup.\n"
+  printf "  --SerialBoot, -s  Run SerialBoot tool setup.\n"
+  printf "  --IDE, -e         Enter IDE setup.\n"
+  printf "  --quit, -q        Quit the script.\n"
+  printf "  --log=<file>      Specify a log file.\n"
+}
+
+### enter bootloader setup
+# arguments n/a
+# return:
+#  -  0: no error
+#  -  1: warning: function aborted by user
+#  - -1: error: unexpected user input
+function stm32flashSetup {
+  local stm32flashdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/stm32flash/
+
+  # if the stm32flash folder is not empty
+  if [ ! -z "$(ls -A $stm32flashdir)" ]; then
+    printWarning "$(realpath $stm32flashdir) is not empty. Delete and reinitialize? [y/n]\n"
+    readUserInput --num-chars=1 --options="YyNn" --out=userinput
+    case $userinput in
+      Y|y)
+        printInfo "wiping $stm32flashdir\n"
+        git submodule deinit -f $stm32flashdir 2>&1 | tee -a $LOG_FILE
+        ;;
+      N|n)
+        printWarning "stm32flash setup aborted by user\n"
+        return 1
+        ;;
+      *) # sanity check (return error)
+        printError "unexpected input: $userinput\n";
+        return -1
+        ;;
+    esac
+  fi
+
+  # initialize submodule
+  printInfo "initializing stm32flash submodule\n"
+  git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE
+
+  # build the stm32flash tool
+  printInfo "compiling stm32flash\n"
+  userdir=${PWD}
+  cd "$stm32flashdir"
+  make 2>&1 | tee -a $LOG_FILE
+  cd "$userdir"
+
+  return 0
+}
+
+### enter SerialBoot setup
+# arguments n/a
+# return:
+#  -  0: no error
+#  -  1: warning: function aborted by user
+#  - -1: error: unexpected user input
+function serialBootSetup {
+  local serialbootdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/SerialBoot/
+
+  # if a build folder already exists
+  if [ -d "${serialbootdir}/build/" ]; then
+    printWarning "SerialBoot has been built before. Delete and rebuild? [y/n]\n"
+    readUserInput --num-chars=1 --options="YyNn" --out=userinput
+    case $userinput in
+      Y|y)
+        printInfo "deleting ${serialbootdir}build/\n"
+        rm -rf "${serialbootdir}build/"
+        ;;
+      N|n)
+        printWarning "SerialBoot setup aborted by user\n"
+        return 1
+        ;;
+      *) # sanity check (return error)
+        printError "unexpected input: $userinput\n";
+        return -1
+        ;;
+    esac
+  fi
+
+  # build SerialBoot
+  printInfo "compiling SerialBoot\n"
+  local userdir=${PWD}
+  mkdir "${serialbootdir}build/"
+  cd "${serialbootdir}build/"
+  cmake .. 2>&1 | tee -a $LOG_FILE
+  make 2>&1 | tee -a $LOG_FILE
+  cd "$userdir"
+
+  return 0
+}
+
+### enter IDE setup
+# arguments n/a
+# return: n/a
+function ideSetup {
+  printInfo "entering ideSetup setup\n"
   printf "\n"
-fi
+  if [ -z $LOG_FILE ]; then
+    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/setup_IDE.sh --noinfo
+  else
+    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/setup_IDE.sh --LOG="$LOG_FILE" --noinfo
+  fi
+}
 
-# initialization of variables
-ARG_IDX=1
-USER_INPUT=${!ARG_IDX}
+################################################################################
+# SCRIPT MAIN FUNCTION                                                         #
+################################################################################
 
-while [[ ! $USER_INPUT =~ ^[Ee]$ ]]; do
+### main function of this script
+# arguments: see help text
+# return: error code
+#   - 0: no error
+#   - 1: error
+function main {
+
+  # parse arguments
+  local arguments=$(getopt -l help,stm32flash,SerialBoot,IDE,quit,log:,LOG:,noinfo -o hfseq -- "$@")
+  if [ $? != 0 ]; then
+    printError "could not interprete arguments."
+    exit 1
+  fi
+  eval set -- "$arguments"
 
-  # main menu info prompt and selection
-  printf "AMiRo-BLT setup\n"
-  printf "===============\n"
+  # print welcome/info text if not suppressed
+  if [[ $@ != *"--noinfo"* ]]; then
+    printWelcomeText
+  else
+    printf "######################################################################\n"
+  fi
   printf "\n"
-  if [[ -z $USER_INPUT || $USER_INPUT == "no_info" ]]; then
-    printf "Please select one of the following actions:\n"
-    printf "    [F] - stm32flash flashing tool setup\n"
-    printf "    [S] - SerialBoot flashing tool setup\n"
-    printf "    [Q] - setup QtCreator projects\n"
-    printf "    [E] - exit this setup\n"
-
-    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
-      read -p "your selection: " -n 1 -e USER_INPUT
-      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
-        printf "[%s] is no valid action. \n" $USER_INPUT
-      fi
+
+  # set log file if specified
+  if [[ $@ == *--log* || $@ == *--LOG* ]]; then
+    # get the parameter (file name)
+    local cmdidx=1
+    while [ "${!cmdidx}" != "--log" ] && [ "${!cmdidx}" != "--LOG" ]; do
+      cmdidx=$[cmdidx + 1]
     done
+    local filenameidx=$[cmdidx + 1]
+    # optionally force silent appending
+    if [ "${!cmdidx}" == "--LOG" ]; then
+      setLogFile --file="${!filenameidx}" --option=A
+    else
+      setLogFile --file="${!filenameidx}"
+      printf "\n"
+    fi
+  fi
 
+  # log script name
+  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
+
+  # if --help or -h was specified, print the help text and exit
+  if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then
+    printHelp
     printf "\n"
-    printf "######################################################################\n"
-    printf "\n"
+    exitScript
   fi
 
-  # action selection
-  case $USER_INPUT in
-
-    # stm32flash setup
-    F|f)
-      USER_DIR=${PWD}
-      cd $(dirname ${BASH_SOURCE[0]})
-
-      # initialize submodule
-      git submodule update --init ./Host/Source/stm32flash/
-
-      cd ./Host/Source/stm32flash/
-      BUILD_STM32FLASH=true
-
-      # test for existing bonary
-      if [ -f stm32flash ]; then
-        printf "WARNING: stm32flash binary already exists.\n"
-        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
-        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
-          BUILD_STM32FLASH=true
-          make clean
-        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
-          BUILD_STM32FLASH=false
-          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
-        else
-          BUILD_STM32FLASH=false
-        fi
-     fi
-
-      # build the tool if required
-      if [ $BUILD_STM32FLASH = true ]; then
-       make
-      fi
+  # handle command line arguments
+  while [ true ]; do
+    case $1 in
+      --help|-h) # already handled; ignore
+        shift 1;
+        ;;
+      --stm32flash|-f)
+        stm32flashSetup; printf "\n"; shift 1
+        ;;
+      --SerialBoot|-s)
+        serialBootSetup; printf "\n"; shift 1
+        ;;
+      --IDE|-e)
+        IdeSetup; printf "\n"; shift 1;
+        ;;
+      --quit|-q)
+        quitScript
+        ;;
+      --log|--LOG) # already handled; ignore
+        shift 2
+        ;;
+      --noinfo) # already processed; ignore
+        shift 1
+        ;;
+      --) # end of options reached
+        shift; break
+        ;;
+      *) # sanity check (exit with error)
+        printError "unexpected argument: $1\n"; exit -1
+        ;;
+    esac
+  done
 
-      cd $USER_DIR
-      ;;
+  # interactive menu
+  while [ true ]; do
+    # main menu info prompt and selection
+    printInfo "AMiRo-BLT main menu\n"
+    printf "Please select one of the following actions:\n"
+    printf "  [F] - get and build stm32flash tool\n"
+    printf "  [S] - build SerialBoot tool\n"
+    printf "  [E] - IDE project setup\n"
+    printf "  [Q] - quit this setup\n"
+    readUserInput --num-chars=1 --options="FfSsEeQq" --out=userinput
+    printf "\n"
 
-    # SerailBoot setup
-    S|s)
-      # print setup header
-      printf "SerialBoot setup\n"
-      printf "================\n"
-      printf "\n"
+    # evaluate user selection
+    case $userinput in
+      I|i)
+        projectInitialization; printf "\n"
+        ;;
+      F|f)
+        stm32flashSetup; printf "\n"
+        ;;
+      S|s)
+        serialBootSetup; printf "\n"
+        ;;
+      E|e)
+        ideSetup; printf "\n"
+        ;;
+      Q|q)
+        quitScript
+        ;;
+      *) # sanity check (exit with error)
+        printError "unexpected argument: $userinput\n"; exit -1
+        ;;
+    esac
+  done
 
-      USER_DIR=${PWD}
-      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot/
-      BUILD_SERIALBOOT=true
-
-      # test for existing binary
-      if [ -f build/SerialBoot ]; then
-        printf "WARNING: SerialBoot binary already exists.\n"
-        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
-        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
-          BUILD_SERIALBOOT=true
-          rm -rf build/
-        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
-          BUILD_SERIALBOOT=false
-          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
-        else
-          BUILD_SERIALBOOT=false
-        fi
-      fi
-
-      # build the tool if requested
-      if [ $BUILD_SERIALBOOT = true ]; then
-        mkdir build
-        cd build
-        cmake ..
-        make
-      fi
-
-      cd $USER_DIR
-      ;;
-
-    # QtCreator setup
-    Q|q)
-      # calling the script with no arguments prints the help and returns
-      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info
-      printf "\n"
-      # set deafult arguments and call the script again
-      USER_INPUT="clean all"
-      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
-      printf "\n"
-      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info $USER_INPUT
-      ;;
-
-    # exit
-    E|e)
-      break;
-      ;;
-
-    # sanity check
-    *)
-      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
-      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
-      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
-      printf "\n"
-      exit
-      ;;
+  exit 0
+}
 
-  esac
+################################################################################
+# SCRIPT ENTRY POINT                                                           #
+################################################################################
 
-  printf "\n"
-  printf "######################################################################\n"
-  printf "\n"
+main "$@"
 
-  let ARG_IDX++
-  USER_INPUT=${!ARG_IDX}
 
-done
+## initial info text (can be disabled with 'no_info' as last argument)
+#if [[ ! ${!#} = "no_info" ]]; then
+#  printf "######################################################################\n"
+#  printf "#                                                                    #\n"
+#  printf "#                  Welcome to the AMiRo-BLT setup!                   #\n"
+#  printf "#                                                                    #\n"
+#  printf "######################################################################\n"
+#  printf "#                                                                    #\n"
+#  printf "# Copyright (c) 2016..2017  Thomas Schöpping                         #\n"
+#  printf "#                                                                    #\n"
+#  printf "# This is free software; see the source for copying conditions.      #\n"
+#  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
+#  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
+#  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
+#  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
+#  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
+#  printf "# Excellence Initiative.                                             #\n"
+#  printf "#                                                                    #\n"
+#  printf "######################################################################\n"
+#  printf "\n"
+#fi
+#
+## initialization of variables
+#ARG_IDX=1
+#USER_INPUT=${!ARG_IDX}
+#
+#while [[ ! $USER_INPUT =~ ^[Ee]$ ]]; do
+#
+#  # main menu info prompt and selection
+#  printf "AMiRo-BLT setup\n"
+#  printf "===============\n"
+#  printf "\n"
+#  if [[ -z $USER_INPUT || $USER_INPUT == "no_info" ]]; then
+#    printf "Please select one of the following actions:\n"
+#    printf "    [F] - stm32flash flashing tool setup\n"
+#    printf "    [S] - SerialBoot flashing tool setup\n"
+#    printf "    [Q] - setup QtCreator projects\n"
+#    printf "    [E] - exit this setup\n"
+#
+#    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
+#      read -p "your selection: " -n 1 -e USER_INPUT
+#      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
+#        printf "[%s] is no valid action. \n" $USER_INPUT
+#      fi
+#    done
+#
+#    printf "\n"
+#    printf "######################################################################\n"
+#    printf "\n"
+#  fi
+#
+#  # action selection
+#  case $USER_INPUT in
+#
+#    # stm32flash setup
+#    F|f)
+#      USER_DIR=${PWD}
+#      cd $(dirname ${BASH_SOURCE[0]})
+#
+#      # initialize submodule
+#      git submodule update --init ./Host/Source/stm32flash/
+#
+#      cd ./Host/Source/stm32flash/
+#      BUILD_STM32FLASH=true
+#
+#      # test for existing bonary
+#      if [ -f stm32flash ]; then
+#        printf "WARNING: stm32flash binary already exists.\n"
+#        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
+#        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
+#          BUILD_STM32FLASH=true
+#          make clean
+#        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
+#          BUILD_STM32FLASH=false
+#          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
+#        else
+#          BUILD_STM32FLASH=false
+#        fi
+#     fi
+#
+#      # build the tool if required
+#      if [ $BUILD_STM32FLASH = true ]; then
+#       make
+#      fi
+#
+#      cd $USER_DIR
+#      ;;
+#
+#    # SerailBoot setup
+#    S|s)
+#      # print setup header
+#      printf "SerialBoot setup\n"
+#      printf "================\n"
+#      printf "\n"
+#
+#      USER_DIR=${PWD}
+#      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot/
+#      BUILD_SERIALBOOT=true
+#
+#      # test for existing binary
+#      if [ -f build/SerialBoot ]; then
+#        printf "WARNING: SerialBoot binary already exists.\n"
+#        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
+#        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
+#          BUILD_SERIALBOOT=true
+#          rm -rf build/
+#        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
+#          BUILD_SERIALBOOT=false
+#          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
+#        else
+#          BUILD_SERIALBOOT=false
+#        fi
+#      fi
+#
+#      # build the tool if requested
+#      if [ $BUILD_SERIALBOOT = true ]; then
+#        mkdir build
+#        cd build
+#        cmake ..
+#        make
+#      fi
+#
+#      cd $USER_DIR
+#      ;;
+#
+#    # QtCreator setup
+#    Q|q)
+#      # calling the script with no arguments prints the help and returns
+#      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info
+#      printf "\n"
+#      # set deafult arguments and call the script again
+#      USER_INPUT="clean all"
+#      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
+#      printf "\n"
+#      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info $USER_INPUT
+#      ;;
+#
+#    # exit
+#    E|e)
+#      break;
+#      ;;
+#
+#    # sanity check
+#    *)
+#      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
+#      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
+#      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
+#      printf "\n"
+#      exit
+#      ;;
+#
+#  esac
+#
+#  printf "\n"
+#  printf "######################################################################\n"
+#  printf "\n"
+#
+#  let ARG_IDX++
+#  USER_INPUT=${!ARG_IDX}
+#
+#done
 
