Statistics
| Branch: | Tag: | Revision:

amiro-os / setup.sh @ ded1ded7

History | View | Annotate | Download (13.4 KB)

1 e545e620 Thomas Schöpping
################################################################################
2
# AMiRo-OS is an operating system designed for the Autonomous Mini Robot       #
3
# (AMiRo) platform.                                                            #
4 96621a83 Thomas Schöpping
# Copyright (C) 2016..2020  Thomas Schöpping et al.                            #
5 e545e620 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 8516dad6 Thomas Schöpping
# load library
27
source "$(dirname ${BASH_SOURCE[0]})/tools/bash/setuplib.sh"
28 e545e620 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-OS setup!                   #\n"
40
  printf "#                                                                    #\n"
41
  printf "######################################################################\n"
42
  printf "#                                                                    #\n"
43 96621a83 Thomas Schöpping
  printf "# Copyright (c) 2016..2020  Thomas Schöpping                         #\n"
44 e545e620 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] [-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 "          -k, --kernel\n"
72
  printf "              Enter kernel setup.\n"
73
  printf "          -b, --bootloader\n"
74
  printf "              Enter bootloader setup.\n"
75
  printf "          -p, --periphery-LLD\n"
76
  printf "              Enter periphery-LLD setup.\n"
77
  printf "          -c, --compiler\n"
78
  printf "              Enter compiler setup.\n"
79
  printf "          --IDE\n"
80
  printf "              Enter IDE setup.\n"
81
  printf "          -q, --quit\n"
82
  printf "              Quit the script.\n"
83
  printf "          --log=<file>\n"
84
  printf "              Specify a log file.\n"
85
}
86
87
### initialize whole project ###################################################
88
# Initializes the whole project, including fetching all submodules and so on.
89
#
90
# usage:      projectInitialization
91
# arguments:  n/a
92
# return:     n/a
93
#
94
function projectInitialization {
95
  printInfo "initializing project\n"
96
  printf "\n"
97
  if [ -z "$LOG_FILE" ]; then
98
    printInfo "initializing kernel submodule...\n"
99
    $(dirname $(realpath ${BASH_SOURCE[0]}))/kernel/kernelsetup.sh --init --quit --noinfo
100
    printf "\n"
101
    printInfo "initializing ChibiOS...\n"
102
    $(dirname $(realpath ${BASH_SOURCE[0]}))/kernel/kernelsetup.sh --patch --documentation=g --quit --noinfo
103
    printf "\n"
104
105
    printInfo "initializing bootloader submodule...\n"
106
    $(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/bootloadersetup.sh --init --quit --noinfo
107
    printf "\n"
108
    printInfo "initializing AMiRo-BLT...\n"
109
    $(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/AMiRo-BLT/setup.sh --stm32flash --SerialBoot --quit --noinfo
110
    printf "\n"
111
112
    printInfo "initializing periphery-LLD (AMiRo-LLD)...\n"
113
    $(dirname $(realpath ${BASH_SOURCE[0]}))/periphery-lld/peripherylldsetup.sh --init --quit --noinfo
114
    printf "\n"
115
  else
116
    printInfo "initializing kernel submodule...\n"
117
    $(dirname $(realpath ${BASH_SOURCE[0]}))/kernel/kernelsetup.sh --init --quit --LOG="$LOG_FILE" --noinfo
118
    printf "\n"
119
    printInfo "initializing ChibiOS...\n"
120
    $(dirname $(realpath ${BASH_SOURCE[0]}))/kernel/kernelsetup.sh --patch --documentation=g --quit --LOG="$LOG_FILE" --noinfo
121
    printf "\n"
122
123
    printInfo "initializing bootloader submodule...\n"
124
    $(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/bootloadersetup.sh --init --quit --LOG="$LOG_FILE" --noinfo
125
    printf "\n"
126
    printInfo "initializing AMiRo-BLT...\n"
127
    $(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/AMiRo-BLT/setup.sh --stm32flash --SerialBoot --quit --LOG="$LOG_FILE" --noinfo
128
    printf "\n"
129
130
    printInfo "initializing periphery-LLD (AMiRo-LLD)...\n"
131
    $(dirname $(realpath ${BASH_SOURCE[0]}))/periphery-lld/peripherylldsetup.sh --init --quit --LOG="$LOG_FILE" --noinfo
132
    printf "\n"
133
  fi
134
  printInfo "initialization complete\n"
135
}
136
137
### enter kernel setup #########################################################
138
# Enter the kernel setup.
139
#
140
# usage:      kernelSetup
141
# arguments:  n/a
142
# return:     n/a
143
#
144
function kernelSetup {
145
  printInfo "entering kernel setup\n"
146
  printf "\n"
147
  if [ -z $LOG_FILE ]; then
148
    $(dirname $(realpath ${BASH_SOURCE[0]}))/kernel/kernelsetup.sh --noinfo
149
  else
150
    $(dirname $(realpath ${BASH_SOURCE[0]}))/kernel/kernelsetup.sh --LOG="$LOG_FILE" --noinfo
151
  fi
152
}
153
154
### enter bootloader setup #####################################################
155
# Enter bootloader setup.
156
#
157
# usage:      bootloaderSetup
158
# arguments:  n/a
159
# return:     n/a
160
#
161
function bootloaderSetup {
162
  printInfo "entering bootloader setup\n"
163
  printf "\n"
164
  if [ -z $LOG_FILE ]; then
165
    $(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/bootloadersetup.sh --noinfo
166
  else
167
    $(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/bootloadersetup.sh --LOG="$LOG_FILE" --noinfo
168
  fi
169
}
170
171
### enter periphery LLD setup ##################################################
172
# Enter the Periphery-LLD setup.
173
#
174
# usage:      peripheryLldSetup
175
# arguments:  n/a
176
# return:     n/a
177
#
178
function peripheryLldSetup {
179
  printInfo "entering periphery-LLD setup\n"
180
  printf "\n"
181
  if [ -z $LOG_FILE ]; then
182
    $(dirname $(realpath ${BASH_SOURCE[0]}))/periphery-lld/peripherylldsetup.sh --noinfo
183
  else
184
    $(dirname $(realpath ${BASH_SOURCE[0]}))/periphery-lld/peripherylldsetup.sh --LOG="$LOG_FILE" --noinfo
185
  fi
186
}
187
188
### enter compiler setup #######################################################
189
# Enter the compiler setup of tzhe AMiRo-BLT submodule.
190
#
191
# usage:      compilerSetup
192
# arguments:  n/a
193
# return:     0
194
#                 No error or warning occurred.
195
#             1
196
#                 Warning: AMiRo-BLT submodule not nitialized yet-
197
#
198
function compilerSetup {
199
  # check if the AMiRo-BLT submodule is initialized and the script file exists
200
  local amirobltdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/bootloader/AMiRo-BLT
201
  local compilerscriptfile=${amirobltdir}/tools/compiler/compilersetup.sh
202
  if [ -z "$(ls -A $amirobltdir)" ] || [ ! -f $compilerscriptfile ]; then
203
    printWarning "Please initialize AMiRo-BLT submodule first.\n"
204
    return 1
205
  else
206
    printInfo "entering compiler setup\n"
207
    if [ -z "$LOG_FILE" ]; then
208
      $compilerscriptfile --noinfo
209
    else
210
      $compilerscriptfile --LOG="$LOG_FILE" --noinfo
211
    fi
212
    return 0
213
  fi
214
}
215
216
### enter IDE setup ############################################################
217
# Enter IDE setup.
218
#
219
# usage:      ideSetup
220
# arguments:  n/a
221
# return:     n/a
222
#
223
function ideSetup {
224
  printInfo "entering IDE setup\n"
225
  printf "\n"
226
  if [ -z $LOG_FILE ]; then
227
    $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --noinfo
228
  else
229
    $(dirname $(realpath ${BASH_SOURCE[0]}))/tools/ide/idesetup.sh --LOG="$LOG_FILE" --noinfo
230
  fi
231
}
232
233
### main function of this script ###############################################
234
# Provides functions for project initialization, configuration of IDE and
235
# compiler setup, as well as entry points to the several Git submodules.
236
#
237
# usage:      see function printHelp
238
# arguments:  see function printHelp
239
# return:     0
240
#                 No error or warning occurred.
241
#
242
function main {
243
  # print welcome/info text if not suppressed
244
  if [[ $@ != *"--noinfo"* ]]; then
245
    printWelcomeText
246
  else
247
    printf "######################################################################\n"
248
  fi
249
  printf "\n"
250
251
  # if --help or -h was specified, print the help text and exit
252
  if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then
253
    printHelp
254
    printf "\n"
255
    quitScript
256
  fi
257
258
  # set log file if specified
259
  if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then
260
    # get the parameter (file name)
261
    local cmdidx=1
262
    while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
263
      cmdidx=$[cmdidx + 1]
264
    done
265
    local cmd="${!cmdidx}"
266
    local logfile=""
267
    if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then
268
      logfile=${cmd#*=}
269
    else
270
      local filenameidx=$((cmdidx + 1))
271
      logfile="${!filenameidx}"
272
    fi
273
    # optionally force silent appending
274
    if [[ "$cmd" = "--LOG"* ]]; then
275
      setLogFile --option=c --quiet "$logfile" LOG_FILE
276
    else
277
      setLogFile "$logfile" LOG_FILE
278
      printf "\n"
279
    fi
280
  fi
281
  # log script name
282
  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
283
284
  # parse arguments
285
  local otherargs=()
286
  while [ $# -gt 0 ]; do
287
    if ( parseIsOption $1 ); then
288
      case "$1" in
289
        -h|--help) # already handled; ignore
290
          shift 1;;
291
        -i|--init)
292
           projectInitialization; printf "\n"; shift 1;;
293
        -k|--kernel)
294
           kernelSetup; printf "\n"; shift 1;;
295
        -b|--bootloader)
296
           bootloaderSetup; printf "\n"; shift 1;;
297
        -p|--periphery-LLD)
298
           peripheryLldSetup; printf "\n"; shift 1;;
299
        -c|--compiler)
300
           compilerSetup; printf "\n"; shift 1;;
301
        --IDE)
302
           ideSetup; printf "\n"; shift 1;;
303
        -q|--quit)
304
          quitScript; shift 1;;
305
        --log=*|--LOG=*) # already handled; ignore
306
          shift 1;;
307
        --log|--LOG) # already handled; ignore
308
          shift 2;;
309
        --noinfo) # already handled; ignore
310
          shift 1;;
311
        *)
312
          printError "invalid option: $1\n"; shift 1;;
313
      esac
314
    else
315
      otherargs+=("$1")
316
      shift 1
317
    fi
318
  done
319
320
  # interactive menu
321
  while ( true ); do
322
    # main menu info prompt and selection
323
    printInfo "AMiRo-OS main menu\n"
324
    printf "Please select one of the following actions:\n"
325
    printf "  [I] - project initialization\n"
326
    printf "  [K] - enter kernel setup\n"
327
    printf "  [B] - enter bootloaders setup\n"
328
    printf "  [P] - enter periphery-LLD setup\n"
329
    printf "  [C] - enter compiler setup\n"
330
    printf "  [E] - enter IDE project setup\n"
331
    printf "  [Q] - quit this setup\n"
332
    local userinput=""
333
    readUserInput "IiKkBbPpCcEeQq" userinput
334
    printf "\n"
335
336
    # evaluate user selection
337
    case "$userinput" in
338
      I|i)
339
        projectInitialization; printf "\n";;
340
      K|k)
341
        kernelSetup; printf "\n";;
342
      B|b)
343
        bootloaderSetup; printf "\n";;
344
      P|p)
345
        peripheryLldSetup; printf "\n";;
346
      C|c)
347
        compilerSetup; printf "\n";;
348
      E|e)
349
        ideSetup; printf "\n";;
350
      Q|q)
351
        quitScript;;
352
      *) # sanity check (exit with error)
353
        printError "unexpected argument: $userinput\n";;
354
    esac
355
  done
356
357
  exit 0
358
}
359
360
################################################################################
361
# SCRIPT ENTRY POINT                                                           #
362
################################################################################
363
364
main "$@"