amiro-apps / tools / ide / QtCreator / QtCreatorSetup.sh @ feecea37
History | View | Annotate | Download (25.054 KB)
1 |
################################################################################ |
---|---|
2 |
# AMiRo-Apps is a collection of applications and configurations for the # |
3 |
# Autonomous Mini Robot (AMiRo). # |
4 |
# Copyright (C) 2018..2019 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 |
################################################################################ |
27 |
# GENERIC FUNCTIONS # |
28 |
################################################################################ |
29 |
|
30 |
### 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 |
function printError { |
40 |
local string="ERROR: $1" |
41 |
# if a log file is specified |
42 |
if [ -n "$LOG_FILE" ]; then |
43 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
44 |
fi |
45 |
printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
46 |
} |
47 |
|
48 |
### 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 |
function printWarning { |
58 |
local string="WARNING: $1" |
59 |
# if a log file is specified |
60 |
if [ -n "$LOG_FILE" ]; then |
61 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
62 |
fi |
63 |
printf "$(tput setaf 3)>>> $string$(tput sgr 0)" |
64 |
} |
65 |
|
66 |
### 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 |
function printInfo { |
76 |
local string="INFO: $1" |
77 |
# if a log file is specified |
78 |
if [ -n "$LOG_FILE" ]; then |
79 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
80 |
fi |
81 |
printf "$(tput setaf 2)>>> $string$(tput sgr 0)" |
82 |
} |
83 |
|
84 |
### 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 |
function printLog { |
93 |
local string="LOG: $1" |
94 |
# if a log file is specified |
95 |
if [ -n "$LOG_FILE" ]; then |
96 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
97 |
fi |
98 |
} |
99 |
|
100 |
### 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 |
function quitScript { |
109 |
printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n" |
110 |
printf "\n" |
111 |
printf "######################################################################\n" |
112 |
exit 0 |
113 |
} |
114 |
|
115 |
### read a user input ########################################################## |
116 |
# Reads a single character user input from a set up <options> and stores it in |
117 |
# a given <return> variable. |
118 |
# |
119 |
# usage: readUserInput <options> <return> |
120 |
# arguments: <options> |
121 |
# String definiing the set of valid characters. |
122 |
# If the string is empty, the user can input any character. |
123 |
# <return> |
124 |
# Variable to store the selected character to. |
125 |
# return: n/a |
126 |
# |
127 |
function readUserInput { |
128 |
local input="" |
129 |
# read user input |
130 |
while [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); do |
131 |
read -p "your selection: " -n 1 -e input |
132 |
if [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); then |
133 |
printWarning "[$input] is no valid action\n" |
134 |
fi |
135 |
done |
136 |
printLog "[$input] has been selected\n" |
137 |
eval $2="$input" |
138 |
} |
139 |
|
140 |
### check whether argument is an option ######################################## |
141 |
# Checks a <string> whether it is an option. |
142 |
# Options are defined to either start with '--' followed by any string, or |
143 |
# to start with a single '-' followed by a single character, or |
144 |
# to start with a single '-' followed by a single character, a '=' and any string. |
145 |
# Examples: '--option', '--option=arg', '-o', '-o=arg', '--' |
146 |
# |
147 |
# usage: parseIsOption <string> |
148 |
# arguments: <string> |
149 |
# A string to check whether it is an option. |
150 |
# return: 0 |
151 |
# <string> is an option. |
152 |
# -1 |
153 |
# <string> is not an option. |
154 |
# |
155 |
function parseIsOption { |
156 |
if [[ "$1" =~ ^-(.$|.=.*) ]] || [[ "$1" =~ ^--.* ]]; then |
157 |
return 0 |
158 |
else |
159 |
return -1 |
160 |
fi |
161 |
} |
162 |
|
163 |
### set the log file ########################################################### |
164 |
# Sets a specified <infile> as log file and checks whether it already exists. |
165 |
# If so, the log may either be appended to the file, its content can be cleared, |
166 |
# or no log is generated at all. |
167 |
# The resulting path is stored in <outvar>. |
168 |
# |
169 |
# usage: setLogFile [--option=<option>] [--quiet] <infile> <outvar> |
170 |
# arguments: --option=<option> |
171 |
# Select what to do if <file> already exists. |
172 |
# Possible values are 'a', 'c', 'r' and 'n'. |
173 |
# - a: append (starts with a separator) |
174 |
# - c: continue (does not insert a seperator) |
175 |
# - r: delete and restart |
176 |
# - n: no log |
177 |
# If no option is secified but <file> exists, an interactive selection is provided. |
178 |
# --quiet |
179 |
# Suppress all messages. |
180 |
# <infile> |
181 |
# Path of the wanted log file. |
182 |
# <outvar> |
183 |
# Variable to store the path of the log file to. |
184 |
# return: 0 |
185 |
# No error or warning occurred. |
186 |
# -1 |
187 |
# Error: invalid input |
188 |
# |
189 |
function setLogFile { |
190 |
local filepath="" |
191 |
local option="" |
192 |
local quiet=false |
193 |
|
194 |
# parse arguments |
195 |
local otherargs=() |
196 |
while [ $# -gt 0 ]; do |
197 |
if ( parseIsOption $1 ); then |
198 |
case "$1" in |
199 |
-o=*|--option=*) |
200 |
option=${1#*=}; shift 1;; |
201 |
-o*|--option*) |
202 |
option="$2"; shift 2;; |
203 |
-q|--quiet) |
204 |
quiet=true; shift 1;; |
205 |
*) |
206 |
printError "invalid option: $1\n"; shift 1;; |
207 |
esac |
208 |
else |
209 |
otherargs+=("$1") |
210 |
shift 1 |
211 |
fi |
212 |
done |
213 |
filepath=$(realpath ${otherargs[0]}) |
214 |
|
215 |
# if file already exists |
216 |
if [ -e $filepath ]; then |
217 |
# if no option was specified, ask what to do |
218 |
if [ -z "$option" ]; then |
219 |
printWarning "log file $filepath already esists\n" |
220 |
local userinput="" |
221 |
printf "Select what to do:\n" |
222 |
printf " [A] - append log\n" |
223 |
printf " [R] - restart log (delete existing file)\n" |
224 |
printf " [N] - no log\n" |
225 |
readUserInput "AaRrNn" userinput |
226 |
option=${userinput,,} |
227 |
fi |
228 |
# evaluate option |
229 |
case "$option" in |
230 |
a|c) |
231 |
if [ $quiet = false ]; then |
232 |
printInfo "appending log to $filepath\n" |
233 |
fi |
234 |
if [ $option != c ]; then |
235 |
printf "\n" >> $filepath |
236 |
printf "######################################################################\n" >> $filepath |
237 |
printf "\n" >> $filepath |
238 |
fi |
239 |
;; |
240 |
r) |
241 |
echo -n "" > $filepath |
242 |
if [ $quiet = false ]; then |
243 |
printInfo "content of $filepath wiped\n" |
244 |
fi |
245 |
;; |
246 |
n) |
247 |
if [ $quiet = false ]; then |
248 |
printInfo "no log file will be generated\n" |
249 |
fi |
250 |
filepath="" |
251 |
;; |
252 |
*) # sanity check (return error) |
253 |
printError "unexpected argument: $option\n"; return -1;; |
254 |
esac |
255 |
else |
256 |
if [ $quiet = false ]; then |
257 |
printInfo "log file set to $filepath\n" |
258 |
fi |
259 |
fi |
260 |
|
261 |
eval ${otherargs[1]}="$filepath" |
262 |
|
263 |
return 0 |
264 |
} |
265 |
|
266 |
### check whether commands are available ####################################### |
267 |
# Checks whether the specified commands are available and can be executed. |
268 |
# |
269 |
# usage: checkCommand [<command> <command> ...] |
270 |
# arguments: <command> |
271 |
# Name of the command to check. |
272 |
# return: 0 |
273 |
# All requested commands are available. |
274 |
# >0 |
275 |
# Number of requested commands that were not found. |
276 |
# -1 |
277 |
# No argument given. |
278 |
# |
279 |
function checkCommands { |
280 |
local status=0 |
281 |
|
282 |
# return if no argument was specified |
283 |
if [ $# -eq 0 ]; then |
284 |
return -1 |
285 |
fi |
286 |
|
287 |
# check all specified commands |
288 |
while [ $# -gt 0 ]; do |
289 |
command -v $1 &>/dev/null |
290 |
if [ $? -ne 0 ]; then |
291 |
printWarning "Command '$1' not available.\n" |
292 |
status=$((status + 1)) |
293 |
fi |
294 |
shift 1 |
295 |
done |
296 |
|
297 |
return $status |
298 |
} |
299 |
|
300 |
################################################################################ |
301 |
# SPECIFIC FUNCTIONS # |
302 |
################################################################################ |
303 |
|
304 |
### print welcome text ######################################################### |
305 |
# Prints a welcome message to standard out. |
306 |
# |
307 |
# usage: printWelcomeText |
308 |
# arguments: n/a |
309 |
# return: n/a |
310 |
# |
311 |
function printWelcomeText { |
312 |
printf "######################################################################\n" |
313 |
printf "# #\n" |
314 |
printf "# Welcome to the QtCreator setup! #\n" |
315 |
printf "# #\n" |
316 |
printf "######################################################################\n" |
317 |
printf "# #\n" |
318 |
printf "# Copyright (c) 2018..2019 Thomas Schöpping #\n" |
319 |
printf "# #\n" |
320 |
printf "# This is free software; see the source for copying conditions. #\n" |
321 |
printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
322 |
printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
323 |
printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
324 |
printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
325 |
printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
326 |
printf "# Excellence Initiative. #\n" |
327 |
printf "# #\n" |
328 |
printf "######################################################################\n" |
329 |
} |
330 |
|
331 |
### print help ################################################################# |
332 |
# Prints a help text to standard out. |
333 |
# |
334 |
# usage: printHelp |
335 |
# arguments: n/a |
336 |
# return: n/a |
337 |
# |
338 |
function printHelp { |
339 |
printInfo "printing help text\n" |
340 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n" |
341 |
printf "\n" |
342 |
printf "options: -h, --help\n" |
343 |
printf " Print this help text.\n" |
344 |
printf " -i, --initialize\n" |
345 |
printf " Initialize project files.\n" |
346 |
printf " -c, --clean\n" |
347 |
printf " Delete project files.\n" |
348 |
printf " -w, --wipe\n" |
349 |
printf " Delete project and .user files.\n" |
350 |
printf " -q, --quit\n" |
351 |
printf " Quit the script.\n" |
352 |
printf " --log=<file>\n" |
353 |
printf " Specify a log file.\n" |
354 |
} |
355 |
|
356 |
### read directory where to create/delete projects ############################# |
357 |
# Read the directory where to create/delete project files from user. |
358 |
# |
359 |
# usage: getProjectDir <pathvar> |
360 |
# arguments: <pathvar> |
361 |
# Variable to store the selected path to. |
362 |
# return: n/a |
363 |
# |
364 |
function getProjectDir { |
365 |
printLog "reading path for project files from user...\n" |
366 |
local amiroappsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../) |
367 |
local input="" |
368 |
read -p "Path where to create/delete project files: " -i $amiroappsdir -e input |
369 |
printLog "user selected path $(realpath $input)\n" |
370 |
eval $1="$(realpath $input)" |
371 |
} |
372 |
|
373 |
### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
374 |
# Retrieves the include directory of the currently set arm-none-eabi-gcc. |
375 |
# |
376 |
# usage: retrieveGccIncludeDir <path> |
377 |
# arguments: <path> |
378 |
# Variable to store the path to. |
379 |
# return: 0 |
380 |
# No error or warning occurred. |
381 |
# -1 |
382 |
# Error: Command 'arm-none-eabi-gcc' not found. |
383 |
# |
384 |
function retrieveGccIncludeDir { |
385 |
# retrieve binary path or link |
386 |
local binpath=$(which arm-none-eabi-gcc) |
387 |
if [ -z "$binpath" ]; then |
388 |
printError "command 'arm-none-eabi-gcc' not found\n" |
389 |
return -1 |
390 |
else |
391 |
|
392 |
# traverse any links |
393 |
while [ -L "$binpath" ]; do |
394 |
binpath=$(readlink $binpath) |
395 |
done |
396 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
397 |
|
398 |
# return include path |
399 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
400 |
|
401 |
return 0 |
402 |
fi |
403 |
} |
404 |
|
405 |
### intialize project files #################################################### |
406 |
# Initailizes all project files. |
407 |
# |
408 |
# usage: initProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
409 |
# arguments: -p, --path <path> |
410 |
# Path where to create the project files. |
411 |
# --gcc=<path> |
412 |
# Path to the GCC include directory. |
413 |
# -o, --out <var> |
414 |
# Variable to store the path to. |
415 |
# --gccout=<var> |
416 |
# Variable to store the path to the GCC include directory to. |
417 |
# return: 0 |
418 |
# No error or warning occurred. |
419 |
# |
420 |
function initProject { |
421 |
local userdir=$(pwd) |
422 |
local projectdir="" |
423 |
local gccincludedir="" |
424 |
local outvar="" |
425 |
local gccoutvar="" |
426 |
|
427 |
# parse arguments |
428 |
local otherargs=() |
429 |
while [ $# -gt 0 ]; do |
430 |
if ( parseIsOption $1 ); then |
431 |
case "$1" in |
432 |
-p=*|--path=*) |
433 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
434 |
-p|--path) |
435 |
projectdir=$(realpath "$2"); shift 2;; |
436 |
--gcc=*) |
437 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
438 |
--gcc) |
439 |
gccincludedir=$(realpath "$2"); shift 2;; |
440 |
-o=*|--out=*) |
441 |
outvar=${1#*=}; shift 1;; |
442 |
-o|--out) |
443 |
outvar=$2; shift 2;; |
444 |
--gccout=*) |
445 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
446 |
--gccout) |
447 |
gccoutvar=$(realpath "$2"); shift 2;; |
448 |
*) |
449 |
printError "invalid option: $1\n"; shift 1;; |
450 |
esac |
451 |
else |
452 |
otherargs+=("$1") |
453 |
shift 1 |
454 |
fi |
455 |
done |
456 |
|
457 |
# print message |
458 |
printInfo "creating QtCreator project files...\n" |
459 |
|
460 |
# read absolute project directory if required |
461 |
if [ -z "$projectdir" ]; then |
462 |
getProjectDir projectdir |
463 |
fi |
464 |
|
465 |
# retrieve absolute GCC include dir |
466 |
if [ -z "$gccincludedir" ]; then |
467 |
retrieveGccIncludeDir gccincludedir |
468 |
fi |
469 |
|
470 |
# move to project directory |
471 |
cd $projectdir |
472 |
|
473 |
# AMiRo-OS, ChibiOS, AMiRo-BLT, AMiRo-LLD and uRtWare relative root directories |
474 |
local amiroappsrootdir=$(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../..) |
475 |
local amiroosrootdir=$(realpath --relative-base=$projectdir ${amiroappsrootdir}/os/AMiRo-OS/os) |
476 |
local chibiosrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../kernel/ChibiOS) |
477 |
local amirobltrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../bootloader/AMiRo-BLT) |
478 |
local amirolldrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../periphery-lld/AMiRo-LLD) |
479 |
local urtwarerootdir=$(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../middleware/uRtWare/) |
480 |
|
481 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
482 |
find $gccincludedir -type d > ${projectdir}/AMiRo-Apps.includes |
483 |
find $amiroappsrootdir -type d | grep -E "/(apps|configurations)/.+" >> ${projectdir}/AMiRo-Apps.includes |
484 |
find $amiroosrootdir -type d | grep -v "/doc\|/build\|/.dep\|/hal\|/ports" >> ${projectdir}/AMiRo-Apps.includes |
485 |
find $amiroosrootdir -type d | grep -E "/os/hal/(include|src)" >> ${projectdir}/AMiRo-Apps.includes |
486 |
find $chibiosrootdir -type d | grep -E "/os/common/abstractions/cmsis_os$" >> ${projectdir}/AMiRo-Apps.includes |
487 |
find $chibiosrootdir -type d | grep -E "/os/common/oslib/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes |
488 |
find $chibiosrootdir -type d | grep -E "/os/hal/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes |
489 |
find $chibiosrootdir -type d | grep -E "/os/hal/lib/streams" >> ${projectdir}/AMiRo-Apps.includes |
490 |
find $chibiosrootdir -type d | grep -E "/os/hal/osal/(lib|rt)$" >> ${projectdir}/AMiRo-Apps.includes |
491 |
find $chibiosrootdir -type d | grep -E "/os/license$" >> ${projectdir}/AMiRo-Apps.includes |
492 |
find $chibiosrootdir -type d | grep -E "/os/rt/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes |
493 |
find $chibiosrootdir -type d | grep -E "/os/various/(shell|cpp_wrappers)" >> ${projectdir}/AMiRo-Apps.includes |
494 |
find $chibiosrootdir -type d | grep -E "/test/(lib|rt/source/test)$" >> ${projectdir}/AMiRo-Apps.includes |
495 |
find $amirobltrootdir -type d | grep -E "/Target/Source/AMiRo$" >> ${projectdir}/AMiRo-Apps.includes |
496 |
echo "$(realpath --relative-base=$projectdir ${amirolldrootdir}/..)" >> ${projectdir}/AMiRo-Apps.includes |
497 |
find $amirolldrootdir -type d | grep -v "/doc" >> ${projectdir}/AMiRo-Apps.includes |
498 |
find $urtwarerootdir -type d | grep -v "/doc" >> ${projectdir}/AMiRo-Apps.includes |
499 |
# generate a file that specifies all files |
500 |
echo -n "" > ${projectdir}/AMiRo-Apps.files |
501 |
for path in `cat ${projectdir}/AMiRo-Apps.includes`; do |
502 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | |
503 |
grep -Ev "^.*/arm-none-eabi/.*$" | |
504 |
grep -E "^.*(\.s|\.S|\.h|\.c|\.hpp|\.cpp|\.tpp|\.ld)$" | |
505 |
grep -Ev "^${amirobltrootdir}/Target/Source/AMiRo/helper.*$" >> ${projectdir}/AMiRo-Apps.files; |
506 |
done |
507 |
# generate a default project configuration file if none exists so far |
508 |
if [ ! -f ${projectdir}/AMiRo-Apps.config ]; then |
509 |
echo "// Add predefined macros for your project here. For example:" > ${projectdir}/AMiRo-Apps.config |
510 |
echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/AMiRo-Apps.config |
511 |
fi |
512 |
# generate a default .creator file if none exists so far |
513 |
if [ ! -f ${projectdir}/AMiRo-Apps}.creator ]; then |
514 |
echo "[general]" > ${projectdir}/AMiRo-Apps.creator |
515 |
fi |
516 |
|
517 |
# go back to user directory |
518 |
cd $userdir |
519 |
|
520 |
# fill the output variables |
521 |
if [ ! -z "$outvar" ]; then |
522 |
eval $outvar="$projectdir" |
523 |
fi |
524 |
if [ ! -z "$gccoutvar" ]; then |
525 |
eval $gccoutvar="$gccincludedir" |
526 |
fi |
527 |
|
528 |
return 0 |
529 |
} |
530 |
|
531 |
### delete project files ####################################################### |
532 |
# Deletes all project files and optionally .user files, too. |
533 |
# |
534 |
# usage: deleteProject [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
535 |
# arguments: -p, --path <path> |
536 |
# Path where to delete the project files. |
537 |
# -o, --out <var> |
538 |
# Variable to store the path to. |
539 |
# -w, --wipe |
540 |
# Delete .user files as well. |
541 |
# return: |
542 |
# - 0: no error |
543 |
# - 1: warning: function aborted by user |
544 |
# - -1: error: unexpected user input |
545 |
function deleteProject { |
546 |
local projectdir="" |
547 |
local outvar="" |
548 |
local wipe=false |
549 |
|
550 |
# parse arguments |
551 |
local otherargs=() |
552 |
while [ $# -gt 0 ]; do |
553 |
if ( parseIsOption $1 ); then |
554 |
case "$1" in |
555 |
-p=*|--path=*) |
556 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
557 |
-p|--path) |
558 |
projectdir=$(realpath "$2"); shift 2;; |
559 |
-o=*|--out=*) |
560 |
outvar=${1#*=}; shift 1;; |
561 |
-o|--out) |
562 |
outvar=$2; shift 2;; |
563 |
-w|--wipe) |
564 |
wipe=true; shift 1;; |
565 |
*) |
566 |
printError "invalid option: $1\n"; shift 1;; |
567 |
esac |
568 |
else |
569 |
otherargs+=("$1") |
570 |
shift 1 |
571 |
fi |
572 |
done |
573 |
|
574 |
# print message |
575 |
if [ $wipe != true ]; then |
576 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
577 |
else |
578 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
579 |
fi |
580 |
|
581 |
# read project directory if required |
582 |
if [ -z "$projectdir" ]; then |
583 |
getProjectDir projectdir |
584 |
fi |
585 |
|
586 |
# remove all project files |
587 |
rm ${projectdir}/AMiRo-Apps.includes 2>&1 | tee -a $LOG_FILE |
588 |
rm ${projectdir}/AMiRo-Apps.files 2>&1 | tee -a $LOG_FILE |
589 |
rm ${projectdir}/AMiRo-Apps.config 2>&1 | tee -a $LOG_FILE |
590 |
rm ${projectdir}/AMiRo-Apps.creator 2>&1 | tee -a $LOG_FILE |
591 |
|
592 |
if [ $wipe == true ]; then |
593 |
rm ${projectdir}/AMiRo-Apps.creator.user 2>&1 | tee -a $LOG_FILE |
594 |
fi |
595 |
|
596 |
# store the path to the output variable, if required |
597 |
if [ ! -z "$outvar" ]; then |
598 |
eval $outvar="$projectdir" |
599 |
fi |
600 |
|
601 |
return 0 |
602 |
|
603 |
} |
604 |
|
605 |
### main function of this script ############################################### |
606 |
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
607 |
# |
608 |
# usage: see function printHelp |
609 |
# arguments: see function printHelp |
610 |
# return: 0 |
611 |
# No error or warning ocurred. |
612 |
# |
613 |
function main { |
614 |
# print welcome/info text if not suppressed |
615 |
if [[ $@ != *"--noinfo"* ]]; then |
616 |
printWelcomeText |
617 |
else |
618 |
printf "######################################################################\n" |
619 |
fi |
620 |
printf "\n" |
621 |
|
622 |
# if --help or -h was specified, print the help text and exit |
623 |
if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
624 |
printHelp |
625 |
printf "\n" |
626 |
quitScript |
627 |
fi |
628 |
|
629 |
# set log file if specified |
630 |
if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
631 |
# get the parameter (file name) |
632 |
local cmdidx=1 |
633 |
while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
634 |
cmdidx=$[cmdidx + 1] |
635 |
done |
636 |
local cmd="${!cmdidx}" |
637 |
local logfile="" |
638 |
if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
639 |
logfile=${cmd#*=} |
640 |
else |
641 |
local filenameidx=$((cmdidx + 1)) |
642 |
logfile="${!filenameidx}" |
643 |
fi |
644 |
# optionally force silent appending |
645 |
if [[ "$cmd" = "--LOG"* ]]; then |
646 |
setLogFile --option=c --quiet "$logfile" LOG_FILE |
647 |
else |
648 |
setLogFile "$logfile" LOG_FILE |
649 |
printf "\n" |
650 |
fi |
651 |
fi |
652 |
# log script name |
653 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
654 |
|
655 |
# parse arguments |
656 |
local otherargs=() |
657 |
while [ $# -gt 0 ]; do |
658 |
if ( parseIsOption $1 ); then |
659 |
case "$1" in |
660 |
-h|--help) # already handled; ignore |
661 |
shift 1;; |
662 |
-c|--clean) |
663 |
deleteProjects; printf "\n"; shift 1;; |
664 |
-w|--wipe) |
665 |
deleteProjects --wipe; printf "\n"; shift 1;; |
666 |
-q|--quit) |
667 |
quitScript; shift 1;; |
668 |
--log=*|--LOG=*) # already handled; ignore |
669 |
shift 1;; |
670 |
--log|--LOG) # already handled; ignore |
671 |
shift 2;; |
672 |
--noinfo) # already handled; ignore |
673 |
shift 1;; |
674 |
*) |
675 |
printError "invalid option: $1\n"; shift 1;; |
676 |
esac |
677 |
else |
678 |
otherargs+=("$1") |
679 |
shift 1 |
680 |
fi |
681 |
done |
682 |
|
683 |
# interactive menu |
684 |
while ( true ); do |
685 |
# main menu info prompt and selection |
686 |
printInfo "QtCreator setup main menu\n" |
687 |
printf "Please select one of the following actions:\n" |
688 |
printf " [I] - initialize project files\n" |
689 |
printf " [C] - clean project files\n" |
690 |
printf " [W] - wipe project and .user files\n" |
691 |
printf " [Q] - quit this setup\n" |
692 |
local userinput="" |
693 |
readUserInput "IiCcWwQq" userinput |
694 |
printf "\n" |
695 |
|
696 |
# evaluate user selection |
697 |
case "$userinput" in |
698 |
I|i) |
699 |
initProject; printf "\n";; |
700 |
C|c) |
701 |
deleteProject; printf "\n";; |
702 |
W|w) |
703 |
deleteProject --wipe; printf "\n";; |
704 |
Q|q) |
705 |
quitScript;; |
706 |
*) # sanity check (exit with error) |
707 |
printError "unexpected argument: $userinput\n";; |
708 |
esac |
709 |
done |
710 |
|
711 |
exit 0 |
712 |
} |
713 |
|
714 |
################################################################################ |
715 |
# SCRIPT ENTRY POINT # |
716 |
################################################################################ |
717 |
|
718 |
main "$@" |