commit 8516dad61397e93e0f4dad42764112f0a9f9544a
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Tue Jan 21 14:03:16 2020 +0100

    Bash scripts: centralized all 'library' functions in a single file

diff --git a/tools/ide/idesetup.sh b/tools/ide/idesetup.sh
index 584c577..b2abedb 100755
--- a/tools/ide/idesetup.sh
+++ b/tools/ide/idesetup.sh
@@ -23,283 +23,8 @@
 
 #!/bin/bash
 
-################################################################################
-# GENERIC FUNCTIONS                                                            #
-################################################################################
-
-### print an error message #####################################################
-# Prints a error <message> to standard output.
-#If variable 'LOG_FILE' is specified, the message is also appended to the given file.
-#
-# usage:      printError <message>
-# arguments:  <message>
-#                 Message string to print.
-# return:     n/a
-#
-function printError {
-  local string="ERROR:   $1"
-  # if a log file is specified
-  if [ -n "$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 message ####################################################
-# Prints a warning <message> to standard output.
-#If variable 'LOG_FILE' is specified, the message is also appended to the given file.
-#
-# usage:      printMessage <message>
-# arguments:  <message>
-#                 Message string to print.
-# return:     n/a
-#
-function printWarning {
-  local string="WARNING: $1"
-  # if a log file is specified
-  if [ -n "$LOG_FILE" ]; then
-    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
-  fi
-  printf "$(tput setaf 3)>>> $string$(tput sgr 0)"
-}
-
-### print an information message ###############################################
-# Prints an information <message> to standard output.
-#If variable 'LOG_FILE' is specified, the message is also appended to the given file.
-#
-# usage:      printInfo <message>
-# arguments:  <message>
-#                 Message string to print.
-# return:     n/a
-#
-function printInfo {
-  local string="INFO:    $1"
-  # if a log file is specified
-  if [ -n "$LOG_FILE" ]; then
-    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
-  fi
-  printf "$(tput setaf 2)>>> $string$(tput sgr 0)"
-}
-
-### print a message to file ####################################################
-# Appends a <message> to a log file, specified by the variable 'LOG_FILE'.
-#
-# usage       printLog <message>
-# arguments:  <message>
-#                 Message string to print.
-# return:     n/a
-#
-function printLog {
-  local string="LOG:     $1"
-  # if a log file is specified
-  if [ -n "$LOG_FILE" ]; then
-    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
-  fi
-}
-
-### exit the script normally ###################################################
-# Prints a delimiter and exits the script normally (returns 0).
-#
-# usage:      quitScript
-# arguments:  n/a
-# return:     0
-#                 No error or warning occurred.
-#
-function quitScript {
-  printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n"
-  printf "\n"
-  printf "######################################################################\n"
-  exit 0
-}
-
-### read a user input ##########################################################
-# Reads a single character user input from a set up <options> and stores it in
-# a given <return> variable.
-#
-# usage:      readUserInput <options> <return>
-# arguments:  <options>
-#                 String definiing the set of valid characters.
-#                 If the string is empty, the user can input any character.
-#             <return>
-#                 Variable to store the selected character to.
-# return:     n/a
-#
-function readUserInput {
-  local input=""
-  # read user input
-  while [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); do
-    read -p "your selection: " -n 1 -e input
-    if [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); then
-      printWarning "[$input] is no valid action\n"
-    fi
-  done
-  printLog "[$input] has been selected\n"
-  eval $2="$input"
-}
-
-### check whether argument is an option ########################################
-# Checks a <string> whether it is an option.
-# Options are defined to either start with '--' followed by any string, or
-# to start with a single '-' followed by a single character, or
-# to start with a single '-' followed by a single character, a '=' and any string.
-# Examples: '--option', '--option=arg', '-o', '-o=arg', '--'
-#
-# usage:      parseIsOption <string>
-# arguments:  <string>
-#                 A string to check whether it is an option.
-# return:     0
-#                 <string> is an option.
-#             -1
-#                 <string> is not an option.
-#
-function parseIsOption {
-  if [[ "$1" =~ ^-(.$|.=.*) ]] || [[ "$1" =~ ^--.* ]]; then
-    return 0
-  else
-    return -1
-  fi
-}
-
-### set the log file ###########################################################
-# Sets a specified <infile> as log file and checks whether it already exists.
-# If so, the log may either be appended to the file, its content can be cleared,
-# or no log is generated at all.
-# The resulting path is stored in <outvar>.
-#
-# usage:      setLogFile [--option=<option>] [--quiet] <infile> <outvar>
-# arguments:  --option=<option>
-#                 Select what to do if <file> already exists.
-#                 Possible values are 'a', 'c', 'r' and 'n'.
-#                 - a: append (starts with a separator)
-#                 - c: continue (does not insert a seperator)
-#                 - r: delete and restart
-#                 - n: no log
-#                 If no option is secified but <file> exists, an interactive selection is provided.
-#             --quiet
-#                 Suppress all messages.
-#             <infile>
-#                 Path of the wanted log file.
-#             <outvar>
-#                 Variable to store the path of the log file to.
-# return:     0
-#                 No error or warning occurred.
-#             -1
-#                 Error: invalid input
-#
-function setLogFile {
-  local filepath=""
-  local option=""
-  local quiet=false
-
-  # parse arguments
-  local otherargs=()
-  while [ $# -gt 0 ]; do
-    if ( parseIsOption $1 ); then
-      case "$1" in
-        -o=*|--option=*)
-          option=${1#*=}; shift 1;;
-        -o*|--option*)
-          option="$2"; shift 2;;
-        -q|--quiet)
-          quiet=true; shift 1;;
-        *)
-          printError "invalid option: $1\n"; shift 1;;
-      esac
-    else
-      otherargs+=("$1")
-      shift 1
-    fi
-  done
-  filepath=$(realpath ${otherargs[0]})
-
-  # if file already exists
-  if [ -e $filepath ]; then
-    # if no option was specified, ask what to do
-    if [ -z "$option" ]; then
-      printWarning "log file $filepath already esists\n"
-      local userinput=""
-      printf "Select what to do:\n"
-      printf "  [A] - append log\n"
-      printf "  [R] - restart log (delete existing file)\n"
-      printf "  [N] - no log\n"
-      readUserInput "AaRrNn" userinput
-      option=${userinput,,}
-    fi
-    # evaluate option
-    case "$option" in
-      a|c)
-        if [ $quiet = false ]; then
-          printInfo "appending log to $filepath\n"
-        fi
-        if [ $option != c ]; then
-          printf "\n" >> $filepath
-          printf "######################################################################\n" >> $filepath
-          printf "\n" >> $filepath
-        fi
-        ;;
-      r)
-        echo -n "" > $filepath
-        if [ $quiet = false ]; then
-          printInfo "content of $filepath wiped\n"
-        fi
-        ;;
-      n)
-        if [ $quiet = false ]; then
-          printInfo "no log file will be generated\n"
-        fi
-        filepath=""
-        ;;
-      *) # sanity check (return error)
-        printError "unexpected argument: $option\n"; return -1;;
-    esac
-  else
-    if [ $quiet = false ]; then
-      printInfo "log file set to $filepath\n"
-    fi
-  fi
-
-  eval ${otherargs[1]}="$filepath"
-
-  return 0
-}
-
-### check whether commands are available #######################################
-# Checks whether the specified commands are available and can be executed.
-#
-# usage:      checkCommands [<command> <command> ...]
-# arguments:  <command>
-#                 Name of the command to check.
-# return:     0
-#                 All requested commands are available.
-#             >0
-#                 Number of requested commands that were not found.
-#             -1
-#                 No argument given.
-#
-function checkCommands {
-  local status=0
-
-  # return if no argument was specified
-  if [ $# -eq 0 ]; then
-    return -1
-  fi
-
-  # check all specified commands
-  while [ $# -gt 0 ]; do
-    command -v $1 &>/dev/null
-    if [ $? -ne 0 ]; then
-      printWarning "Command '$1' not available.\n"
-      status=$((status + 1))
-    fi
-    shift 1
-  done
-
-  return $status
-}
-
-################################################################################
-# SPECIFIC FUNCTIONS                                                           #
-################################################################################
+# load library
+source "$(dirname ${BASH_SOURCE[0]})/../bash/setuplib.sh"
 
 ### print welcome text #########################################################
 # Prints a welcome message to standard out.
