amiro-blt / ide / QtCreator / QtCreatorSetup.sh @ 0a42f078
History | View | Annotate | Download (31.566 KB)
| 1 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
|---|---|---|---|
| 2 | 1da30dfc | Thomas Schöpping | # AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
| 3 | # Robot (AMiRo) platform. # |
||
| 4 | 4cce70a8 | Thomas Schöpping | # 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 | 69661903 | Thomas Schöpping | #!/bin/bash |
| 25 | |||
| 26 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 27 | 1da30dfc | Thomas Schöpping | # GENERIC FUNCTIONS # |
| 28 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 29 | 69661903 | Thomas Schöpping | |
| 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 | 69661903 | Thomas Schöpping | fi |
| 45 | 1da30dfc | Thomas Schöpping | printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
| 46 | } |
||
| 47 | 69661903 | Thomas Schöpping | |
| 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 | 69661903 | Thomas Schöpping | fi |
| 98 | 1da30dfc | Thomas Schöpping | } |
| 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 | 69661903 | Thomas Schöpping | } |
| 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 | 69661903 | 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 | 69661903 | Thomas Schöpping | |
| 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 | 69661903 | Thomas Schöpping | 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 | 69661903 | Thomas Schöpping | |
| 213 | 1da30dfc | Thomas Schöpping | # 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 | 69661903 | Thomas Schöpping | else |
| 252 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
| 253 | printInfo "log file set to $filepath\n" |
||
| 254 | fi |
||
| 255 | 69661903 | Thomas Schöpping | fi |
| 256 | 0a42f078 | Thomas Schöpping | |
| 257 | eval ${otherargs[1]}="$filepath"
|
||
| 258 | |||
| 259 | return 0 |
||
| 260 | 69661903 | Thomas Schöpping | } |
| 261 | 4cce70a8 | Thomas Schöpping | |
| 262 | 1da30dfc | Thomas Schöpping | ################################################################################ |
| 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 | 1da30dfc | Thomas Schöpping | printf "# Welcome to the QtCreator setup! #\n" |
| 277 | 4cce70a8 | Thomas Schöpping | 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] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n"
|
| 303 | printf "\n" |
||
| 304 | printf "options: -h, --help\n" |
||
| 305 | printf " Print this help text.\n" |
||
| 306 | printf " -c, --clean\n" |
||
| 307 | printf " Delete project files.\n" |
||
| 308 | printf " -w, --wipe\n" |
||
| 309 | printf " Delete project and .user files.\n" |
||
| 310 | printf " --LightRing\n" |
||
| 311 | printf " Create project for the LightRing module.\n" |
||
| 312 | printf " --PowerManagement\n" |
||
| 313 | printf " Create project for the PowerManagement module.\n" |
||
| 314 | printf " --DiWheelDrive\n" |
||
| 315 | printf " Create project for the DiWheelDrive module.\n" |
||
| 316 | printf " -a, --all\n" |
||
| 317 | printf " Create projects for all modules.\n" |
||
| 318 | printf " -q, --quit\n" |
||
| 319 | printf " Quit the script.\n" |
||
| 320 | printf " --log=<file>\n" |
||
| 321 | printf " Specify a log file.\n" |
||
| 322 | 1da30dfc | Thomas Schöpping | } |
| 323 | 69661903 | Thomas Schöpping | |
| 324 | 0a42f078 | Thomas Schöpping | ### read directory where to create/delete projects ############################# |
| 325 | # Read the directory where to create/delete project files from user. |
||
| 326 | # |
||
| 327 | # usage: getProjectDir <pathvar> |
||
| 328 | # arguments: <pathvar> |
||
| 329 | # Variable to store the selected path to. |
||
| 330 | # return: n/a |
||
| 331 | # |
||
| 332 | 1da30dfc | Thomas Schöpping | function getProjectDir {
|
| 333 | 0a42f078 | Thomas Schöpping | printLog "reading path for project files from user...\n" |
| 334 | local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../Target/)
|
||
| 335 | local input="" |
||
| 336 | read -p "Path where to create/delete project files: " -i $amirobltdir -e input |
||
| 337 | printLog "user selected path $(realpath $input)\n" |
||
| 338 | eval $1="$(realpath $input)" |
||
| 339 | 1da30dfc | Thomas Schöpping | } |
| 340 | 69661903 | Thomas Schöpping | |
| 341 | 0a42f078 | Thomas Schöpping | ### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
| 342 | # Retrieves the include directory of the currently set arm-none-eabi-gcc. |
||
| 343 | # |
||
| 344 | # usage: retrieveGccIncludeDir <path> |
||
| 345 | # arguments: <path> |
||
| 346 | # Variable to store the path to. |
||
| 347 | # return: 0 |
||
| 348 | # No error or warning occurred. |
||
| 349 | # -1 |
||
| 350 | # Error: Command 'arm-none-eabi-gcc' not found. |
||
| 351 | # |
||
| 352 | 1da30dfc | Thomas Schöpping | function retrieveGccIncludeDir {
|
| 353 | # retrieve binary path or link |
||
| 354 | 0a42f078 | Thomas Schöpping | local binpath=$(which arm-none-eabi-gcc) |
| 355 | 1da30dfc | Thomas Schöpping | if [ -z "$binpath" ]; then |
| 356 | 0a42f078 | Thomas Schöpping | printError "command 'arm-none-eabi-gcc' not found\n" |
| 357 | 1da30dfc | Thomas Schöpping | return -1 |
| 358 | 0a42f078 | Thomas Schöpping | else |
| 359 | 69661903 | Thomas Schöpping | |
| 360 | 0a42f078 | Thomas Schöpping | # traverse any links |
| 361 | while [ -L "$binpath" ]; do |
||
| 362 | binpath=$(readlink $binpath) |
||
| 363 | done |
||
| 364 | printInfo "gcc-arm-none-eabi detected: $binpath\n" |
||
| 365 | 69661903 | Thomas Schöpping | |
| 366 | 0a42f078 | Thomas Schöpping | # return include path |
| 367 | eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
|
||
| 368 | 69661903 | Thomas Schöpping | |
| 369 | 0a42f078 | Thomas Schöpping | return 0 |
| 370 | fi |
||
| 371 | 1da30dfc | Thomas Schöpping | } |
| 372 | 69661903 | Thomas Schöpping | |
| 373 | 0a42f078 | Thomas Schöpping | ### delete project files ####################################################### |
| 374 | # Deletes all project files and optionally .user files, too. |
||
| 375 | # |
||
| 376 | # usage: deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
||
| 377 | # arguments: -p, --path <path> |
||
| 378 | # Path where to delete the project files. |
||
| 379 | # -o, --out <var> |
||
| 380 | # Variable to store the path to. |
||
| 381 | # -w, --wipe |
||
| 382 | # Delete .user files as well. |
||
| 383 | 1da30dfc | Thomas Schöpping | # return: |
| 384 | # - 0: no error |
||
| 385 | # - 1: warning: function aborted by user |
||
| 386 | # - -1: error: unexpected user input |
||
| 387 | function deleteProjects {
|
||
| 388 | local projectdir="" |
||
| 389 | local outvar="" |
||
| 390 | local wipe=false |
||
| 391 | 69661903 | Thomas Schöpping | |
| 392 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 393 | local otherargs=() |
||
| 394 | while [ $# -gt 0 ]; do |
||
| 395 | if ( parseIsOption $1 ); then |
||
| 396 | case "$1" in |
||
| 397 | -p=*|--path=*) |
||
| 398 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 399 | -p|--path) |
||
| 400 | projectdir=$(realpath "$2"); shift 2;; |
||
| 401 | -o=*|--out=*) |
||
| 402 | outvar=${1#*=}; shift 1;;
|
||
| 403 | -o|--out) |
||
| 404 | outvar=$2; shift 2;; |
||
| 405 | -w|--wipe) |
||
| 406 | wipe=true; shift 1;; |
||
| 407 | *) |
||
| 408 | printError "invalid option: $1\n"; shift 1;; |
||
| 409 | esac |
||
| 410 | else |
||
| 411 | otherargs+=("$1")
|
||
| 412 | shift 1 |
||
| 413 | fi |
||
| 414 | 4cce70a8 | Thomas Schöpping | done |
| 415 | 69661903 | Thomas Schöpping | |
| 416 | 1da30dfc | Thomas Schöpping | # print message |
| 417 | if [ $wipe != true ]; then |
||
| 418 | printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
||
| 419 | else |
||
| 420 | printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
||
| 421 | fi |
||
| 422 | 69661903 | Thomas Schöpping | |
| 423 | 1da30dfc | Thomas Schöpping | # read project directory if required |
| 424 | if [ -z "$projectdir" ]; then |
||
| 425 | getProjectDir projectdir |
||
| 426 | fi |
||
| 427 | 69661903 | Thomas Schöpping | |
| 428 | 1da30dfc | Thomas Schöpping | # remove all project files |
| 429 | rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE
|
||
| 430 | rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE
|
||
| 431 | rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE
|
||
| 432 | 69661903 | Thomas Schöpping | |
| 433 | 1da30dfc | Thomas Schöpping | rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE
|
| 434 | rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE
|
||
| 435 | rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE
|
||
| 436 | 4cce70a8 | Thomas Schöpping | |
| 437 | 1da30dfc | Thomas Schöpping | rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE
|
| 438 | rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE
|
||
| 439 | rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE
|
||
| 440 | 4cce70a8 | Thomas Schöpping | |
| 441 | 1da30dfc | Thomas Schöpping | rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE
|
| 442 | rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE
|
||
| 443 | rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE
|
||
| 444 | 69661903 | Thomas Schöpping | |
| 445 | 1da30dfc | Thomas Schöpping | if [ $wipe == true ]; then |
| 446 | rm ${projectdir}/LightRing.user 2>&1 | tee -a $LOG_FILE
|
||
| 447 | rm ${projectdir}/PowerManagement.user 2>&1 | tee -a $LOG_FILE
|
||
| 448 | rm ${projectdir}/DiWheelDrive.user 2>&1 | tee -a $LOG_FILE
|
||
| 449 | fi |
||
| 450 | 69661903 | Thomas Schöpping | |
| 451 | 1da30dfc | Thomas Schöpping | # store the path to the output variable, if required |
| 452 | if [ ! -z "$outvar" ]; then |
||
| 453 | eval $outvar="$projectdir" |
||
| 454 | fi |
||
| 455 | 69661903 | Thomas Schöpping | |
| 456 | 1da30dfc | Thomas Schöpping | return 0 |
| 457 | } |
||
| 458 | 4cce70a8 | Thomas Schöpping | |
| 459 | 0a42f078 | Thomas Schöpping | ### create LightRing project files ############################################# |
| 460 | # Create project files for the LightRing module. |
||
| 461 | # |
||
| 462 | # usage: createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
||
| 463 | # arguments: -p, --path <path> |
||
| 464 | # Path where to create the project files. |
||
| 465 | # --gcc=<path> |
||
| 466 | # Path to the GCC include directory. |
||
| 467 | # -o, --out <var> |
||
| 468 | # Variable to store the path to. |
||
| 469 | # --gccout=<var> |
||
| 470 | # Variable to store the path to the GCC include directory to. |
||
| 471 | # return: 0 |
||
| 472 | # No error or warning occurred. |
||
| 473 | # |
||
| 474 | 1da30dfc | Thomas Schöpping | function createLightRingProject {
|
| 475 | local projectdir="" |
||
| 476 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 477 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 478 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 479 | 4cce70a8 | Thomas Schöpping | |
| 480 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 481 | local otherargs=() |
||
| 482 | while [ $# -gt 0 ]; do |
||
| 483 | if ( parseIsOption $1 ); then |
||
| 484 | case "$1" in |
||
| 485 | -p=*|--path=*) |
||
| 486 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 487 | -p|--path) |
||
| 488 | projectdir=$(realpath "$2"); shift 2;; |
||
| 489 | --gcc=*) |
||
| 490 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 491 | --gcc) |
||
| 492 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 493 | -o=*|--out=*) |
||
| 494 | outvar=${1#*=}; shift 1;;
|
||
| 495 | -o|--out) |
||
| 496 | outvar=$2; shift 2;; |
||
| 497 | --gccout=*) |
||
| 498 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 499 | --gccout) |
||
| 500 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 501 | *) |
||
| 502 | printError "invalid option: $1\n"; shift 1;; |
||
| 503 | esac |
||
| 504 | else |
||
| 505 | otherargs+=("$1")
|
||
| 506 | shift 1 |
||
| 507 | fi |
||
| 508 | 1da30dfc | Thomas Schöpping | done |
| 509 | |||
| 510 | # print message |
||
| 511 | 0a42f078 | Thomas Schöpping | printInfo "creating QtCreator project files for the LightRing module...\n" |
| 512 | 1da30dfc | Thomas Schöpping | |
| 513 | # read project directory if required |
||
| 514 | if [ -z "$projectdir" ]; then |
||
| 515 | getProjectDir projectdir |
||
| 516 | fi |
||
| 517 | |||
| 518 | # retrieve gcc-arm-none-eabi include dir |
||
| 519 | if [ -z "$gccincludedir" ]; then |
||
| 520 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 521 | 1da30dfc | Thomas Schöpping | fi |
| 522 | |||
| 523 | # create project files |
||
| 524 | # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
||
| 525 | find $gccincludedir -type d > ${projectdir}/LightRing.includes
|
||
| 526 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes
|
||
| 527 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/LightRing.includes
|
||
| 528 | # generate a file that specifies all files |
||
| 529 | echo -n "" > ${projectdir}/LightRing.files
|
||
| 530 | for path in `cat ${projectdir}/LightRing.includes`; do
|
||
| 531 | find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files
|
||
| 532 | done |
||
| 533 | # generate a default project configuration file if none exists so far |
||
| 534 | if [ ! -f ${projectdir}/LightRing.config ]; then
|
||
| 535 | echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config
|
||
| 536 | echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config
|
||
| 537 | echo -e "" >> ${projectdir}/LightRing.config
|
||
| 538 | fi |
||
| 539 | # generate a default .creator file if none exists so far |
||
| 540 | if [ ! -f ${projectdir}/LightRing.creator ]; then
|
||
| 541 | echo -e "[general]" > ${projectdir}/LightRing.creator
|
||
| 542 | echo -e "" >> ${projectdir}/LightRing.creator
|
||
| 543 | fi |
||
| 544 | |||
| 545 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 546 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 547 | eval $outvar="$projectdir" |
||
| 548 | fi |
||
| 549 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 550 | eval $gccoutvar="$gccincludedir" |
||
| 551 | fi |
||
| 552 | 4cce70a8 | Thomas Schöpping | |
| 553 | 1da30dfc | Thomas Schöpping | return 0 |
| 554 | } |
||
| 555 | 4cce70a8 | Thomas Schöpping | |
| 556 | 0a42f078 | Thomas Schöpping | ### create PowerManagement project files ####################################### |
| 557 | # Create project files for the PowerManagement module. |
||
| 558 | # |
||
| 559 | # usage: createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
||
| 560 | # arguments: -p, --path <path> |
||
| 561 | # Path where to create the project files. |
||
| 562 | # --gcc=<path> |
||
| 563 | # Path to the GCC include directory. |
||
| 564 | # -o, --out <var> |
||
| 565 | # Variable to store the path to. |
||
| 566 | # --gccout=<var> |
||
| 567 | # Variable to store the path to the GCC include directory to. |
||
| 568 | # return: 0 |
||
| 569 | # No error or warning occurred. |
||
| 570 | # |
||
| 571 | 1da30dfc | Thomas Schöpping | function createPowerManagementProject {
|
| 572 | local projectdir="" |
||
| 573 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 574 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 575 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 576 | 4cce70a8 | Thomas Schöpping | |
| 577 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 578 | local otherargs=() |
||
| 579 | while [ $# -gt 0 ]; do |
||
| 580 | if ( parseIsOption $1 ); then |
||
| 581 | case "$1" in |
||
| 582 | -p=*|--path=*) |
||
| 583 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 584 | -p|--path) |
||
| 585 | projectdir=$(realpath "$2"); shift 2;; |
||
| 586 | --gcc=*) |
||
| 587 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 588 | --gcc) |
||
| 589 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 590 | -o=*|--out=*) |
||
| 591 | outvar=${1#*=}; shift 1;;
|
||
| 592 | -o|--out) |
||
| 593 | outvar=$2; shift 2;; |
||
| 594 | --gccout=*) |
||
| 595 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 596 | --gccout) |
||
| 597 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 598 | *) |
||
| 599 | printError "invalid option: $1\n"; shift 1;; |
||
| 600 | esac |
||
| 601 | else |
||
| 602 | otherargs+=("$1")
|
||
| 603 | shift 1 |
||
| 604 | fi |
||
| 605 | 1da30dfc | Thomas Schöpping | done |
| 606 | |||
| 607 | # print message |
||
| 608 | 0a42f078 | Thomas Schöpping | printInfo "creating QtCreator project files for the PowerManagement module...\n" |
| 609 | 4cce70a8 | Thomas Schöpping | |
| 610 | 1da30dfc | Thomas Schöpping | # read project directory if required |
| 611 | if [ -z "$projectdir" ]; then |
||
| 612 | getProjectDir projectdir |
||
| 613 | fi |
||
| 614 | |||
| 615 | # retrieve gcc-arm-none-eabi include dir |
||
| 616 | if [ -z "$gccincludedir" ]; then |
||
| 617 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 618 | 1da30dfc | Thomas Schöpping | fi |
| 619 | 4cce70a8 | Thomas Schöpping | |
| 620 | 1da30dfc | Thomas Schöpping | # create project files |
| 621 | # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
||
| 622 | find $gccincludedir -type d > ${projectdir}/PowerManagement.includes
|
||
| 623 | 0a42f078 | Thomas Schöpping | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/PowerManagement.includes
|
| 624 | 1da30dfc | Thomas Schöpping | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/PowerManagement.includes
|
| 625 | # generate a file that specifies all files |
||
| 626 | echo -n "" > ${projectdir}/PowerManagement.files
|
||
| 627 | for path in `cat ${projectdir}/PowerManagement.includes`; do
|
||
| 628 | find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files
|
||
| 629 | done |
||
| 630 | # generate a default project configuration file if none exists so far |
||
| 631 | if [ ! -f ${projectdir}/PowerManagement.config ]; then
|
||
| 632 | echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config
|
||
| 633 | echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config
|
||
| 634 | echo -e "" >> ${projectdir}/PowerManagement.config
|
||
| 635 | fi |
||
| 636 | # generate a default .creator file if none exists so far |
||
| 637 | if [ ! -f ${projectdir}/PowerManagement.creator ]; then
|
||
| 638 | echo -e "[general]" > ${projectdir}/PowerManagement.creator
|
||
| 639 | echo -e "" >> ${projectdir}/PowerManagement.creator
|
||
| 640 | fi |
||
| 641 | 4cce70a8 | Thomas Schöpping | |
| 642 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 643 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 644 | eval $outvar="$projectdir" |
||
| 645 | fi |
||
| 646 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 647 | eval $gccoutvar="$gccincludedir" |
||
| 648 | fi |
||
| 649 | 4cce70a8 | Thomas Schöpping | |
| 650 | 1da30dfc | Thomas Schöpping | return 0 |
| 651 | } |
||
| 652 | 4cce70a8 | Thomas Schöpping | |
| 653 | 0a42f078 | Thomas Schöpping | ### create DiWheelDrive project files ########################################## |
| 654 | # Create project files for the DiWheelDrive module. |
||
| 655 | # |
||
| 656 | # usage: createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
||
| 657 | # arguments: -p, --path <path> |
||
| 658 | # Path where to create the project files. |
||
| 659 | # --gcc=<path> |
||
| 660 | # Path to the GCC include directory. |
||
| 661 | # -o, --out <var> |
||
| 662 | # Variable to store the path to. |
||
| 663 | # --gccout=<var> |
||
| 664 | # Variable to store the path to the GCC include directory to. |
||
| 665 | # return: 0 |
||
| 666 | # No error or warning occurred. |
||
| 667 | # |
||
| 668 | 1da30dfc | Thomas Schöpping | function createDiWheelDriveProject {
|
| 669 | local projectdir="" |
||
| 670 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 671 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 672 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 673 | 4cce70a8 | Thomas Schöpping | |
| 674 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 675 | local otherargs=() |
||
| 676 | while [ $# -gt 0 ]; do |
||
| 677 | if ( parseIsOption $1 ); then |
||
| 678 | case "$1" in |
||
| 679 | -p=*|--path=*) |
||
| 680 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 681 | -p|--path) |
||
| 682 | projectdir=$(realpath "$2"); shift 2;; |
||
| 683 | --gcc=*) |
||
| 684 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 685 | --gcc) |
||
| 686 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 687 | -o=*|--out=*) |
||
| 688 | outvar=${1#*=}; shift 1;;
|
||
| 689 | -o|--out) |
||
| 690 | outvar=$2; shift 2;; |
||
| 691 | --gccout=*) |
||
| 692 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 693 | --gccout) |
||
| 694 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 695 | *) |
||
| 696 | printError "invalid option: $1\n"; shift 1;; |
||
| 697 | esac |
||
| 698 | else |
||
| 699 | otherargs+=("$1")
|
||
| 700 | shift 1 |
||
| 701 | fi |
||
| 702 | 1da30dfc | Thomas Schöpping | done |
| 703 | 4cce70a8 | Thomas Schöpping | |
| 704 | 1da30dfc | Thomas Schöpping | # print message |
| 705 | 0a42f078 | Thomas Schöpping | printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
| 706 | 4cce70a8 | Thomas Schöpping | |
| 707 | 1da30dfc | Thomas Schöpping | # read project directory if required |
| 708 | if [ -z "$projectdir" ]; then |
||
| 709 | getProjectDir projectdir |
||
| 710 | fi |
||
| 711 | 4cce70a8 | Thomas Schöpping | |
| 712 | 1da30dfc | Thomas Schöpping | # retrieve gcc-arm-none-eabi include dir |
| 713 | if [ -z "$gccincludedir" ]; then |
||
| 714 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 715 | 1da30dfc | Thomas Schöpping | fi |
| 716 | 4cce70a8 | Thomas Schöpping | |
| 717 | 1da30dfc | Thomas Schöpping | # create project files |
| 718 | # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
||
| 719 | find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes
|
||
| 720 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes
|
||
| 721 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/DiWheelDrive.includes
|
||
| 722 | # generate a file that specifies all files |
||
| 723 | echo -n "" > ${projectdir}/DiWheelDrive.files
|
||
| 724 | for path in `cat ${projectdir}/DiWheelDrive.includes`; do
|
||
| 725 | find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files
|
||
| 726 | done |
||
| 727 | # generate a default project configuration file if none exists so far |
||
| 728 | if [ ! -f ${projectdir}/DiWheelDrive.config ]; then
|
||
| 729 | echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config
|
||
| 730 | echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config
|
||
| 731 | echo -e "" >> ${projectdir}/DiWheelDrive.config
|
||
| 732 | fi |
||
| 733 | # generate a default .creator file if none exists so far |
||
| 734 | if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then
|
||
| 735 | echo -e "[general]" > ${projectdir}/DiWheelDrive.creator
|
||
| 736 | echo -e "" >> ${projectdir}/DiWheelDrive.creator
|
||
| 737 | fi |
||
| 738 | 4cce70a8 | Thomas Schöpping | |
| 739 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 740 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 741 | eval $outvar="$projectdir" |
||
| 742 | fi |
||
| 743 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 744 | eval $gccoutvar="$gccincludedir" |
||
| 745 | fi |
||
| 746 | 4cce70a8 | Thomas Schöpping | |
| 747 | 1da30dfc | Thomas Schöpping | return 0 |
| 748 | } |
||
| 749 | 4cce70a8 | Thomas Schöpping | |
| 750 | 0a42f078 | Thomas Schöpping | ### create project files for al modules ######################################## |
| 751 | # Create project files for all modules. |
||
| 752 | # |
||
| 753 | # usage: createAllProjects |
||
| 754 | # arguments: n/a |
||
| 755 | # return: 0 |
||
| 756 | # No error or warning occurred. |
||
| 757 | # |
||
| 758 | 1da30dfc | Thomas Schöpping | function createAllProjects {
|
| 759 | 0a42f078 | Thomas Schöpping | # print message |
| 760 | printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
||
| 761 | 1da30dfc | Thomas Schöpping | |
| 762 | 0a42f078 | Thomas Schöpping | # read project directory |
| 763 | 1da30dfc | Thomas Schöpping | local projectdir="" |
| 764 | 0a42f078 | Thomas Schöpping | getProjectDir projectdir |
| 765 | printInfo "files will be created in $projectdir\n" |
||
| 766 | 4cce70a8 | Thomas Schöpping | |
| 767 | 0a42f078 | Thomas Schöpping | # retrieve gcc-arm-none-eabi include dir |
| 768 | retrieveGccIncludeDir gccincludedir |
||
| 769 | 4cce70a8 | Thomas Schöpping | |
| 770 | 1da30dfc | Thomas Schöpping | # create projects |
| 771 | 0a42f078 | Thomas Schöpping | createLightRingProject --path="$projectdir" --gcc="$gccincludedir" |
| 772 | createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir" |
||
| 773 | createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir" |
||
| 774 | 4cce70a8 | Thomas Schöpping | |
| 775 | 1da30dfc | Thomas Schöpping | return 0 |
| 776 | } |
||
| 777 | 4cce70a8 | Thomas Schöpping | |
| 778 | 0a42f078 | Thomas Schöpping | ### main function of this script ############################################### |
| 779 | # Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
||
| 780 | # |
||
| 781 | # usage: see function printHelp |
||
| 782 | # arguments: see function printHelp |
||
| 783 | # return: 0 |
||
| 784 | # No error or warning ocurred. |
||
| 785 | # |
||
| 786 | 1da30dfc | Thomas Schöpping | function main {
|
| 787 | 0a42f078 | Thomas Schöpping | # print welcome/info text if not suppressed |
| 788 | 1da30dfc | Thomas Schöpping | if [[ $@ != *"--noinfo"* ]]; then |
| 789 | printWelcomeText |
||
| 790 | else |
||
| 791 | printf "######################################################################\n" |
||
| 792 | fi |
||
| 793 | printf "\n" |
||
| 794 | |||
| 795 | # set log file if specified |
||
| 796 | 0a42f078 | Thomas Schöpping | if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
| 797 | 1da30dfc | Thomas Schöpping | # get the parameter (file name) |
| 798 | local cmdidx=1 |
||
| 799 | 0a42f078 | Thomas Schöpping | while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
|
| 800 | 1da30dfc | Thomas Schöpping | cmdidx=$[cmdidx + 1] |
| 801 | done |
||
| 802 | 0a42f078 | Thomas Schöpping | local cmd="${!cmdidx}"
|
| 803 | local logfile="" |
||
| 804 | if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
||
| 805 | logfile=${cmd#*=}
|
||
| 806 | else |
||
| 807 | local filenameidx=$((cmdidx + 1)) |
||
| 808 | logfile="${!filenameidx}"
|
||
| 809 | fi |
||
| 810 | 1da30dfc | Thomas Schöpping | # optionally force silent appending |
| 811 | 0a42f078 | Thomas Schöpping | if [[ "$cmd" = "--LOG"* ]]; then |
| 812 | setLogFile --option=a --quiet "$logfile" LOG_FILE |
||
| 813 | 1da30dfc | Thomas Schöpping | else |
| 814 | 0a42f078 | Thomas Schöpping | setLogFile "$logfile" LOG_FILE |
| 815 | 1da30dfc | Thomas Schöpping | printf "\n" |
| 816 | fi |
||
| 817 | fi |
||
| 818 | |||
| 819 | # log script name |
||
| 820 | printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
|
||
| 821 | 4cce70a8 | Thomas Schöpping | |
| 822 | 1da30dfc | Thomas Schöpping | # if --help or -h was specified, print the help text and exit |
| 823 | if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
||
| 824 | printHelp |
||
| 825 | printf "\n" |
||
| 826 | 7a91596e | Thomas Schöpping | quitScript |
| 827 | 1da30dfc | Thomas Schöpping | fi |
| 828 | |||
| 829 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 830 | local otherargs=() |
||
| 831 | while [ $# -gt 0 ]; do |
||
| 832 | if ( parseIsOption $1 ); then |
||
| 833 | case "$1" in |
||
| 834 | -h|--help) # already handled; ignore |
||
| 835 | shift 1;; |
||
| 836 | -c|--clean) |
||
| 837 | deleteProjects; printf "\n"; shift 1;; |
||
| 838 | -w|--wipe) |
||
| 839 | deleteProjects --wipe; printf "\n"; shift 1;; |
||
| 840 | --LightRing) |
||
| 841 | createLightRingProject; printf "\n"; shift 1;; |
||
| 842 | --PowerManagement) |
||
| 843 | createPowerManagementProject; printf "\n"; shift 1;; |
||
| 844 | --DiWheelDrive) |
||
| 845 | createDiWheelDriveProject; printf "\n"; shift 1;; |
||
| 846 | -a|--all) |
||
| 847 | createAllProjects; printf "\n"; shift 1;; |
||
| 848 | -q|--quit) |
||
| 849 | quitScript; shift 1;; |
||
| 850 | --log=*|--LOG=*) # already handled; ignore |
||
| 851 | shift 1;; |
||
| 852 | --log|--LOG) # already handled; ignore |
||
| 853 | shift 2;; |
||
| 854 | --noinfo) # already handled; ignore |
||
| 855 | shift 1;; |
||
| 856 | *) |
||
| 857 | printError "invalid option: $1\n"; shift 1;; |
||
| 858 | esac |
||
| 859 | else |
||
| 860 | otherargs+=("$1")
|
||
| 861 | shift 1 |
||
| 862 | fi |
||
| 863 | 1da30dfc | Thomas Schöpping | done |
| 864 | 4cce70a8 | Thomas Schöpping | |
| 865 | 0a42f078 | Thomas Schöpping | # interactive menu |
| 866 | while ( true ); do |
||
| 867 | 1da30dfc | Thomas Schöpping | # main menu info prompt and selection |
| 868 | printInfo "QtCreator setup main menu\n" |
||
| 869 | printf "Please select one of the following actions:\n" |
||
| 870 | printf " [C] - clean project files\n" |
||
| 871 | printf " [W] - wipe project and .user files\n" |
||
| 872 | printf " [L] - create a project for the LightRing module\n" |
||
| 873 | printf " [P] - create a project for the PowerManagement module\n" |
||
| 874 | printf " [D] - create a project for the DiWheelDrive module\n" |
||
| 875 | printf " [A] - create a project for all modules\n" |
||
| 876 | printf " [Q] - quit this setup\n" |
||
| 877 | 0a42f078 | Thomas Schöpping | local userinput="" |
| 878 | readUserInput "CcWwLlPpDdAaQq" userinput |
||
| 879 | 1da30dfc | Thomas Schöpping | printf "\n" |
| 880 | |||
| 881 | # evaluate user selection |
||
| 882 | 0a42f078 | Thomas Schöpping | case "$userinput" in |
| 883 | 1da30dfc | Thomas Schöpping | C|c) |
| 884 | 0a42f078 | Thomas Schöpping | deleteProjects; printf "\n";; |
| 885 | 1da30dfc | Thomas Schöpping | W|w) |
| 886 | 0a42f078 | Thomas Schöpping | deleteProjects --wipe; printf "\n";; |
| 887 | 1da30dfc | Thomas Schöpping | L|l) |
| 888 | 0a42f078 | Thomas Schöpping | createLightRingProject; printf "\n";; |
| 889 | 1da30dfc | Thomas Schöpping | P|p) |
| 890 | 0a42f078 | Thomas Schöpping | createPowerManagementProject; printf "\n";; |
| 891 | 1da30dfc | Thomas Schöpping | D|d) |
| 892 | 0a42f078 | Thomas Schöpping | createDiWheelDriveProject; printf "\n";; |
| 893 | 1da30dfc | Thomas Schöpping | A|a) |
| 894 | 0a42f078 | Thomas Schöpping | createAllProjects; printf "\n";; |
| 895 | 1da30dfc | Thomas Schöpping | Q|q) |
| 896 | 0a42f078 | Thomas Schöpping | quitScript;; |
| 897 | 1da30dfc | Thomas Schöpping | *) # sanity check (exit with error) |
| 898 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $userinput\n";; |
| 899 | 4cce70a8 | Thomas Schöpping | esac |
| 900 | done |
||
| 901 | 1da30dfc | Thomas Schöpping | |
| 902 | exit 0 |
||
| 903 | } |
||
| 904 | 69661903 | Thomas Schöpping | |
| 905 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 906 | 1da30dfc | Thomas Schöpping | # SCRIPT ENTRY POINT # |
| 907 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 908 | 69661903 | Thomas Schöpping | |
| 909 | 1da30dfc | Thomas Schöpping | main "$@" |