Statistics
| Branch: | Revision:

amiro-apps / setup.sh @ 8a4aa333

History | View | Annotate | Download (11.813 KB)

1 b1f38b27 Thomas Schöpping
################################################################################
2
# AMiRo-Apps is a collection of applications for the Autonomous Mini Robot     #
3
# (AMiRo) platform.                                                            #
4 f25c513d Thomas Schöpping
# Copyright (C) 2018..2019  Thomas Schöpping et al.                            #
5 b1f38b27 Thomas Schöpping
#                                                                              #
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 8dab1768 Thomas Schöpping
# load library
27
source "$(dirname ${BASH_SOURCE[0]})/tools/bash/setuplib.sh"
28 b1f38b27 Thomas Schöpping
29
### print welcome text #########################################################
30
# Prints a welcome message to standard out.
31
#
32
# usage:      printWelcomeText
33
# arguments:  n/a
34
# return:     n/a
35
#
36
function printWelcomeText {
37
  printf "######################################################################\n"
38
  printf "#                                                                    #\n"
39
  printf "#                  Welcome to the AMiRo-Apps setup!                  #\n"
40
  printf "#                                                                    #\n"
41
  printf "######################################################################\n"
42
  printf "#                                                                    #\n"
43 f25c513d Thomas Schöpping
  printf "# Copyright (c) 2018..2019  Thomas Schöpping                         #\n"
44 b1f38b27 Thomas Schöpping
  printf "#                                                                    #\n"
45
  printf "# This is free software; see the source for copying conditions.      #\n"
46
  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
47
  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
48
  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
49
  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
50
  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
51
  printf "# Excellence Initiative.                                             #\n"
52
  printf "#                                                                    #\n"
53
  printf "######################################################################\n"
54
}
55
56
### print help #################################################################
57
# Prints a help text to standard out.
58
#
59
# usage:      printHelp
60
# arguments:  n/a
61
# return:     n/a
62
#
63
function printHelp {
64
  printInfo "printing help text\n"
65
  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-i|--init] [-k|--kernel] [-b|--bootloader] [-p|--periphery-LLD] [-m|--middleware] [-c|--compiler] [--IDE] [-q|--quit] [--log=<file>]\n"
66
  printf "\n"
67
  printf "options:  -h, --help\n"
68
  printf "              Print this help text.\n"
69
  printf "          -i, --init\n"
70
  printf "              Run project initalization.\n"
71
  printf "          -o. --os\n"
72
  printf "              Enter operating system setup.\n"
73
  printf "          -m, --middleware\n"
74
  printf "              Enter middleware setup.\n"
75
  printf "          -c, --compiler\n"
76
  printf "              Enter compiler setup.\n"
77
  printf "          --IDE\n"
78
  printf "              Enter IDE setup.\n"
79
  printf "          -q, --quit\n"
80
  printf "              Quit the script.\n"
81
  printf "          --log=<file>\n"
82
  printf "              Specify a log file.\n"
83
}
84
85
### initialize whole project ###################################################
86
# Initializes the whole project, including fetching all submodules and so on.
87
#
88
# usage:      projectInitialization
89
# arguments:  n/a
90
# return:     n/a
91
#
92
function projectInitialization {
93
  printInfo "initializing project\n"
94
  printf "\n"
95
  if [ -z "$LOG_FILE" ]; then
96
    printInfo "Initializing operating system submodule...\n"
97
    $(dirname $(realpath ${BASH_SOURCE[0]}))/os/ossetup.sh --init --quit --noinfo
98
    printf "\n"
99
    printInfo "initializing AMiRo-OS...\n"
100
    $(dirname $(realpath ${BASH_SOURCE[0]}))/os/AMiRo-OS/setup.sh --init --quit --noinfo
101
    printf "\n"
102
103
    printInfo "Initializing middlewre submodule...\n"
104
    $(dirname $(realpath ${BASH_SOURCE[0]}))/middleware/middlewaresetup.sh --init --quit --noinfo
105
    printf "\n"
106
  else
107
    printInfo "Initializing operating system submodule...\n"
108
    $(dirname $(realpath ${BASH_SOURCE[0]}))/os/ossetup.sh --init --quit --LOG="$LOG_FILE" --noinfo
109
    printf "\n"
110
    printInfo "initializing AMiRo-OS...\n"
111
    $(dirname $(realpath ${BASH_SOURCE[0]}))/os/AMiRo-OS/setup.sh --init --quit --LOG="$LOG_FILE" --noinfo
112
    printf "\n"
113
114
    printInfo "Initializing middlewre submodule...\n"
115
    $(dirname $(realpath ${BASH_SOURCE[0]}))/middleware/middlewaresetup.sh --init --quit --LOG="$LOG_FILE" --noinfo
116
    printf "\n"
117
  fi
118
  printInfo "initialization complete\n"
119
}
120
121
### enter operating system setup ###############################################
122
# Enter the operating system setup.
123
#
124
# usage:      osSetup
125
# arguments:  n/a
126
# return:     n/a
127
#
128
function osSetup {
129
  printInfo "entering operating system setup\n"
130
  printf "\n"
131
  if [ -z $LOG_FILE ]; then
132
    $(dirname $(realpath ${BASH_SOURCE[0]}))/os/ossetup.sh --noinfo
133
  else
134
    $(dirname $(realpath ${BASH_SOURCE[0]}))/os/ossetup.sh --LOG="$LOG_FILE" --noinfo
135
  fi
136
}
137
138
### enter middleware setup #####################################################
139
# Enter the middleware setup.
140
#
141
# usage:      middlewareSetup
142
# arguments:  n/a
143
# return:     n/a
144
#
145
function middlewareSetup {
146
  printInfo "entering middleware setup\n"
147
  printf "\n"
148
  if [ -z $LOG_FILE ]; then
149
    $(dirname $(realpath ${BASH_SOURCE[0]}))/middleware/middlewaresetup.sh --noinfo
150
  else
151
    $(dirname $(realpath ${BASH_SOURCE[0]}))/middleware/middlewaresetup.sh --LOG="$LOG_FILE" --noinfo
152
  fi
153
}
154
155
### enter compiler setup #######################################################
156
# Enter the compiler setup of the AMiRo-OS submodule.
157
#
158
# usage:      compilerSetup
159
# arguments:  n/a
160
# return:     0
161
#                 No error or warning occurred.
162
#             1
163
#                 Warning: AMiRo-OS submodule not nitialized yet-
164
#
165
function compilerSetup {
166
  # check if the AMiRo-OS submodule is initialized and the script file exists
167
  local amiroosdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/os/AMiRo-OS
168
  local amiroosscriptfile=${amiroosdir}/setup.sh
169
  if [ -z "$(ls -A $amiroosdir)" ] || [ ! -f $amiroosscriptfile ]; then
170
    printError "$amiroosdir is empty. Please initialize first.\n"
171
    return 1
172
  else
173
    printInfo "entering compiler setup\n"
174
    if [ -z "$LOG_FILE" ]; then
175
      $amiroosscriptfile --compiler --noinfo
176
    else
177
      $amiroosscriptfile --LOG="$LOG_FILE" --compiler --noinfo
178
    fi
179
    return 0
180
  fi
181
}
182
183
### enter IDE setup ############################################################
184
# Enter IDE setup.
185
#
186
# usage:      ideSetup
187
# arguments:  n/a
188
# return:     n/a
189
#
190
function ideSetup {
191
  printInfo "entering IDE setup\n"
192
  printf "\n"
193
  if [ -z $LOG_FILE ]; then
194
    $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --noinfo
195
  else
196
    $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --LOG="$LOG_FILE" --noinfo
197
  fi
198
}
199
200
### main function of this script ###############################################
201
# Provides functions for project initialization, configuration of IDE and
202
# compiler setup, as well as entry points to the several Git submodules.
203
#
204
# usage:      see function printHelp
205
# arguments:  see function printHelp
206
# return:     0
207
#                 No error or warning occurred.
208
#
209
function main {
210
  # print welcome/info text if not suppressed
211
  if [[ $@ != *"--noinfo"* ]]; then
212
    printWelcomeText
213
  else
214
    printf "######################################################################\n"
215
  fi
216
  printf "\n"
217
218
  # if --help or -h was specified, print the help text and exit
219
  if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then
220
    printHelp
221
    printf "\n"
222
    quitScript
223
  fi
224
225
  # set log file if specified
226
  if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then
227
    # get the parameter (file name)
228
    local cmdidx=1
229
    while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
230
      cmdidx=$[cmdidx + 1]
231
    done
232
    local cmd="${!cmdidx}"
233
    local logfile=""
234
    if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then
235
      logfile=${cmd#*=}
236
    else
237
      local filenameidx=$((cmdidx + 1))
238
      logfile="${!filenameidx}"
239
    fi
240
    # optionally force silent appending
241
    if [[ "$cmd" = "--LOG"* ]]; then
242
      setLogFile --option=c --quiet "$logfile" LOG_FILE
243
    else
244
      setLogFile "$logfile" LOG_FILE
245
      printf "\n"
246
    fi
247
  fi
248
  # log script name
249
  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
250
251
  # parse arguments
252
  local otherargs=()
253
  while [ $# -gt 0 ]; do
254
    if ( parseIsOption $1 ); then
255
      case "$1" in
256
        -h|--help) # already handled; ignore
257
          shift 1;;
258
        -i|--init)
259
           projectInitialization; printf "\n"; shift 1;;
260
        -o|--os)
261
           osSetup; printf "\n"; shift 1;;
262
        -m|--middleware)
263
           middlewareSetup; printf "\n"; shift 1;;
264
        -c|--compiler)
265
           compilerSetup; printf "\n"; shift 1;;
266
        --IDE)
267
           ideSetup; printf "\n"; shift 1;;
268
        -q|--quit)
269
          quitScript; shift 1;;
270
        --log=*|--LOG=*) # already handled; ignore
271
          shift 1;;
272
        --log|--LOG) # already handled; ignore
273
          shift 2;;
274
        --noinfo) # already handled; ignore
275
          shift 1;;
276
        *)
277
          printError "invalid option: $1\n"; shift 1;;
278
      esac
279
    else
280
      otherargs+=("$1")
281
      shift 1
282
    fi
283
  done
284
285
  # interactive menu
286
  while ( true ); do
287
    # main menu info prompt and selection
288
    printInfo "AMiRo-Apps main menu\n"
289
    printf "Please select one of the following actions:\n"
290
    printf "  [I] - project initialization\n"
291
    printf "  [O] - enter operating system setup\n"
292
    printf "  [M] - enter middleware setup\n"
293
    printf "  [C] - enter compiler setup\n"
294
    printf "  [E] - enter IDE project setup\n"
295
    printf "  [Q] - quit this setup\n"
296
    local userinput=""
297
    readUserInput "IiOoMmCcEeQq" userinput
298
    printf "\n"
299
300
    # evaluate user selection
301
    case "$userinput" in
302
      I|i)
303
        projectInitialization; printf "\n";;
304
      O|o)
305
        osSetup; printf "\n";;
306
      M|m)
307
        middlewareSetup; printf "\n";;
308
      C|c)
309
        compilerSetup; printf "\n";;
310
      E|e)
311
        ideSetup; printf "\n";;
312
      Q|q)
313
        quitScript;;
314
      *) # sanity check (exit with error)
315
        printError "unexpected argument: $userinput\n";;
316
    esac
317
  done
318
319
  exit 0
320
}
321
322
################################################################################
323
# SCRIPT ENTRY POINT                                                           #
324
################################################################################
325
326
main "$@"