Statistics
| Branch: | Tag: | Revision:

amiro-blt / setup.sh @ 6feb961b

History | View | Annotate | Download (6.994 KB)

1 4cce70a8 Thomas Schöpping
################################################################################
2
# AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini    #
3
# Robot (AMiRo) platform.                                                      #
4
# 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
#!/bin/bash
25
26
# initial info text (can be disabled with 'no_info' as last argument)
27
if [[ ! ${!#} = "no_info" ]]; then
28
  printf "######################################################################\n"
29
  printf "#                                                                    #\n"
30
  printf "#                  Welcome to the AMiRo-BLT setup!                   #\n"
31
  printf "#                                                                    #\n"
32
  printf "######################################################################\n"
33
  printf "#                                                                    #\n"
34
  printf "# Copyright (c) 2016..2017  Thomas Schöpping                         #\n"
35
  printf "#                                                                    #\n"
36
  printf "# This is free software; see the source for copying conditions.      #\n"
37
  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
38
  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
39
  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
40
  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
41
  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
42
  printf "# Excellence Initiative.                                             #\n"
43
  printf "#                                                                    #\n"
44
  printf "######################################################################\n"
45
  printf "\n"
46
fi
47
48
# initialization of variables
49
ARG_IDX=1
50
USER_INPUT=${!ARG_IDX}
51
52
while [[ ! $USER_INPUT =~ ^[Ee]$ ]]; do
53
54
  # main menu info prompt and selection
55
  printf "AMiRo-BLT setup\n"
56
  printf "===============\n"
57
  printf "\n"
58
  if [[ -z $USER_INPUT || $USER_INPUT == "no_info" ]]; then
59
    printf "Please select one of the following actions:\n"
60 6886c3b6 Thomas Schöpping
    printf "    [F] - stm32flash flashing tool setup\n"
61 4cce70a8 Thomas Schöpping
    printf "    [S] - SerialBoot flashing tool setup\n"
62
    printf "    [Q] - setup QtCreator projects\n"
63
    printf "    [E] - exit this setup\n"
64
65 6886c3b6 Thomas Schöpping
    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
66 4cce70a8 Thomas Schöpping
      read -p "your selection: " -n 1 -e USER_INPUT
67 6886c3b6 Thomas Schöpping
      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
68 4cce70a8 Thomas Schöpping
        printf "[%s] is no valid action. \n" $USER_INPUT
69
      fi
70
    done
71
72
    printf "\n"
73
    printf "######################################################################\n"
74
    printf "\n"
75
  fi
76
77
  # action selection
78
  case $USER_INPUT in
79
80 6886c3b6 Thomas Schöpping
    # stm32flash setup
81
    F|f)
82
    # initialize submodule
83
    git submodule update --init $(dirname ${BASH_SOURCE[0]})/Host/stm32flash/
84
85
    USER_DIR=${PWD}
86
    cd $(dirname ${BASH_SOURCE[0]})/Host/stm32flash
87
    BUILD_STM32FLASH=true
88
89
    # test for existing bonary
90 6feb961b Thomas Schöpping
    if [ -f stm32flash ]; then
91 6886c3b6 Thomas Schöpping
      printf "WARNING: stm32flash binary already exists.\n"
92
      read -p "Would you like to delete and rebuild it? [Y/n] " -n 1 -i "Y" -e USER_INPUT
93
      if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
94
        BUILD_STM32FLASH=true
95 6feb961b Thomas Schöpping
        make clean
96 6886c3b6 Thomas Schöpping
      elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
97
        BUILD_STM32FLASH=false
98
        printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
99
      else
100
        BUILD_STM32FLASH=false
101
      fi
102
    fi
103
104
    # build the tool if required
105
    if [ $BUILD_STM32FLASH = true ]; then
106
      make
107
    fi
108
109
    cd $USER_DIR
110
    ;;
111
112 4cce70a8 Thomas Schöpping
    # SerailBoot setup
113
    S|s)
114
      # print setup header
115
      printf "SerialBoot setup\n"
116
      printf "================\n"
117
      printf "\n"
118
119
      USER_DIR=${PWD}
120
      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot
121
      BUILD_SERIALBOOT=true
122
123
      # test for existing binary
124
      if [ -f build/SerialBoot ]; then
125
        printf "WARNING: SerialBoot binary already exists.\n"
126
        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
127
        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
128
          BUILD_SERIALBOOT=true
129
          rm -rf build/
130
        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
131
          BUILD_SERIALBOOT=false
132
          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
133
        else
134
          BUILD_SERIALBOOT=false
135
        fi
136
      fi
137
138 6886c3b6 Thomas Schöpping
      # build the tool if requested
139 4cce70a8 Thomas Schöpping
      if [ $BUILD_SERIALBOOT = true ]; then
140
        mkdir build
141
        cd build
142
        cmake ..
143
        make
144
      fi
145
146
      cd $USER_DIR
147
      ;;
148
149
    # QtCreator setup
150
    Q|q)
151
      # calling the script with no arguments prints the help and returns
152
      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh "no_info"
153
      printf "\n"
154
      # set deafult arguments and call the script again
155
      USER_INPUT="clean all"
156
      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
157
      printf "\n"
158
      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh "no_info" $USER_INPUT
159
      ;;
160
161
    # exit
162
    E|e)
163
      break;
164
      ;;
165
166
    # sanity check
167
    *)
168
      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
169
      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
170
      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
171
      printf "\n"
172
      exit
173
      ;;
174
175
  esac
176
177
  printf "\n"
178
  printf "######################################################################\n"
179
  printf "\n"
180
181
  let ARG_IDX++
182
  USER_INPUT=${!ARG_IDX}
183
184
done