Statistics
| Branch: | Tag: | Revision:

amiro-blt / setup.sh @ 8446a3a1

History | View | Annotate | Download (7.04 KB)

1
################################################################################
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
    printf "    [F] - stm32flash flashing tool setup\n"
61
    printf "    [S] - SerialBoot flashing tool setup\n"
62
    printf "    [Q] - setup QtCreator projects\n"
63
    printf "    [E] - exit this setup\n"
64

    
65
    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
66
      read -p "your selection: " -n 1 -e USER_INPUT
67
      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
68
        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
    # stm32flash setup
81
    F|f)
82
      USER_DIR=${PWD}
83
      cd $(dirname ${BASH_SOURCE[0]})
84

    
85
      # initialize submodule
86
      git submodule update --init ./Host/Source/stm32flash/
87

    
88
      cd ./Host/Source/stm32flash/
89
      BUILD_STM32FLASH=true
90

    
91
      # test for existing bonary
92
      if [ -f stm32flash ]; then
93
        printf "WARNING: stm32flash binary already exists.\n"
94
        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
95
        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
96
          BUILD_STM32FLASH=true
97
          make clean
98
        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
99
          BUILD_STM32FLASH=false
100
          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
101
        else
102
          BUILD_STM32FLASH=false
103
        fi
104
     fi
105

    
106
      # build the tool if required
107
      if [ $BUILD_STM32FLASH = true ]; then
108
       make
109
      fi
110

    
111
      cd $USER_DIR
112
      ;;
113

    
114
    # SerailBoot setup
115
    S|s)
116
      # print setup header
117
      printf "SerialBoot setup\n"
118
      printf "================\n"
119
      printf "\n"
120

    
121
      USER_DIR=${PWD}
122
      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot/
123
      BUILD_SERIALBOOT=true
124

    
125
      # test for existing binary
126
      if [ -f build/SerialBoot ]; then
127
        printf "WARNING: SerialBoot binary already exists.\n"
128
        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
129
        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
130
          BUILD_SERIALBOOT=true
131
          rm -rf build/
132
        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
133
          BUILD_SERIALBOOT=false
134
          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
135
        else
136
          BUILD_SERIALBOOT=false
137
        fi
138
      fi
139

    
140
      # build the tool if requested
141
      if [ $BUILD_SERIALBOOT = true ]; then
142
        mkdir build
143
        cd build
144
        cmake ..
145
        make
146
      fi
147

    
148
      cd $USER_DIR
149
      ;;
150

    
151
    # QtCreator setup
152
    Q|q)
153
      # calling the script with no arguments prints the help and returns
154
      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh "no_info"
155
      printf "\n"
156
      # set deafult arguments and call the script again
157
      USER_INPUT="clean all"
158
      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
159
      printf "\n"
160
      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh "no_info" $USER_INPUT
161
      ;;
162

    
163
    # exit
164
    E|e)
165
      break;
166
      ;;
167

    
168
    # sanity check
169
    *)
170
      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
171
      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
172
      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
173
      printf "\n"
174
      exit
175
      ;;
176

    
177
  esac
178

    
179
  printf "\n"
180
  printf "######################################################################\n"
181
  printf "\n"
182

    
183
  let ARG_IDX++
184
  USER_INPUT=${!ARG_IDX}
185

    
186
done
187