Some of the repetitive violations were suppressed.
7.63KiB; Unix Shell | 2019-09-10 20:58:52+02 | SLOC 214
1
#!/bin/bash
2
#set -x
3
# =========================================================================
4
# Copyright 2019 T-Mobile, US
5
#␣
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
9
#
10
#    http://www.apache.org/licenses/LICENSE-2.0
11
#
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
17
# See the readme.txt file for additional language around disclaimer of warranties.
18
# ========================================================================
19
20
function exists {
21
   found=1
22 1
   type $1 >/dev/null 2>&1 || { found=0; }
23
   echo "$found"
24
}
25
26
APPS_TO_BUILD=NONE
27
PKG_TYPE=NONE
28
29
function usage {
30
   if [ $# -lt 4 ]; then
31 2
      echo "Usage: `basename $0` [--build|-b ui|api|all|none] [--package|-p tar|docker|none]"
32
      echo ""
33
      echo "Options: "
34
      echo ""
35
      echo "--build, -b             Builds all the cloud vault applications"
36
      echo "            ui          builds the cloud vault user portal"
37
      echo "            api         builds the cloud vault api"
38
      echo "            all         builds the cloud vault user portal and api"
39
      echo "            none        does not build any of the cloud vault applications"
40
      echo ""
41
      echo "--package, -p               Packages all the cloud vault application"
42
      echo "            tar         packages the cloud vault application as tar file"
43
      echo "            docker      packages the cloud vault application as docker container"
44
      echo "            none        does not package any of the cloud vault applications"
45
      echo ""
46
   fi
47
}
48
49
argc=$#
50
argv=($@)
51
52
for (( i=0; i<argc; i++ )); do
53
   option=${argv[i]}
54
   #echo "$option"
55
   j=i+1
56
   optionval=${argv[j]}
57
   #echo "optionval $optionval"
58
   #echo "option $option"
59
   case "$option" in
60
      --build|-b)
61
	# echo "build option"
62
         #optionval=${argv[i+1]}
63
         if [[ "$optionval" ==  "ui" ]]; then
64
            APPS_TO_BUILD=UI_ONLY
65
         elif [[ "$optionval" ==  "api" ]]; then
66
            APPS_TO_BUILD=API_ONLY
67
         elif [[ "$optionval" ==  "all" ]]; then
68
            APPS_TO_BUILD=ALL
69
         elif [[ "$optionval" ==  "none" ]]; then
70
            APPS_TO_BUILD=NONE
71
         else
72
            echo "Invalid build option specified"
73
         fi
74
      ;;
75
       --package|-p)
76
      # echo "package option $optionval"
77
         if [[ "$optionval" ==  "docker" ]]; then
78
            PKG_TYPE=docker
79
         elif [[ "$optionval" ==  "tar" ]]; then
80
            PKG_TYPE=tar
81
         elif [[ "$optionval" ==  "none" ]]; then
82
            PKG_TYPE=NONE
83
         else
84
            echo "Invalid package option specified"
85
            # As of now default this to tar
86
            PKG_TYPE=tar
87
         fi
88
      ;;
89
      --usage|-u|--help|-h)
90
      usage
91
      exit 0;
92
  esac
93
done
94
95
if [ $# -lt 4 ]; then
96
   echo "Insufficent build/package options provided. Pre-built applications will be used and packaged as tar."
97
   usage
98
fi
99
100
echo "Cleaning the previously generated files/directories..."
101
102 1
if [ -z "out_bin/" ]; then
103
   echo "Removing out/bin ..."
104
   rm -rf out_bin/
105
fi
106 1
if [ -z "tvault_final/" ]; then
107
   echo "Removing tvault_final/ ..."
108
   rm -rf tvault_final/
109
fi
110
if [ -f "tvault_all.tar.gz" ]; then
111
   echo "Removing tvault_all.tar.gz ..."
112
   rm -f tvault_all.tar.gz
113
fi
114
115
echo "Building $APPS_TO_BUILD and packaging as $PKG_TYPE"
116
117 1
BASEDIR="$( cd "$(dirname "$0")" ; pwd -P )"
118
COMPONENTS_DIR=$BASEDIR/dist/src/main/components
119
DOCKER_FILE_DIR=$BASEDIR/dist/src/main/docker
120
TVAULT_TAR_DIR=$BASEDIR/tvault_final
121
122
if [[ "$APPS_TO_BUILD" == "UI_ONLY"  || "$APPS_TO_BUILD" == "ALL" ]]; then
123
   echo "-----------------------------------------------------"
124
   echo "Building TVault User Portal"
125
   echo "-----------------------------------------------------"
126
127
   # check for nodejs
128
   # check for gulp
129
   # check for Bower
130
   if [ "$(exists node)" == "0" ] ; then
131
      echo "Node is not installed/not available in the path. Please correct it and try again later"
132
      exit 1␣␣
133
   fi
134
   if [ "$(exists bower)" == "0" ] ; then
135
      echo "Bower is not installed/not available in the path. Please correct it and try again later"
136
      exit 1␣␣
137
   fi
138
   if [ "$(exists gulp)" == "0" ] ; then
139
      echo "Gulp is not installed/not available in the path. Please correct it and try again later"
140
      exit 1␣␣
141
   fi
142
␣␣␣
143
   UI_DIR=$BASEDIR/tvaultui
144 2
   cd $UI_DIR
145
   echo "Clean up existing node_modules directory..."
146
   echo "Removing $UI_DIR/node_modules/ ..."
147
   rm -rf node_modules
148
   echo "Removing $UI_DIR/.tmp ..."
149
   rm -rf .tmp
150
   echo "Removing $UI_DIR/app/ ..."
151
   rm -rf app
152
   echo "Completed removing the existing node_modules directory..."
153
154
   npm install
155
   bower install --allow-root
156
   #gulp serve:live
157
158
   gulp build
159
   UI_DESTINATION_DIR=$COMPONENTS_DIR/web/nginx/html
160
   echo "Copying Vault UI to $UI_DESTINATION_DIR"
161 1
   rm -rf $COMPONENTS_DIR/web/nginx/html/*
162 2
   cp -rf $UI_DIR/app/* $UI_DESTINATION_DIR/.
163
164 1
   mkdir -p $UI_DESTINATION_DIR/styles/sass/components/
165 2
   cp $UI_DIR/src/app/sass/components/jquery-ui.css $UI_DESTINATION_DIR/styles/sass/components/
166
   if [[ "$PKG_TYPE" == "NONE" ]]; then
167
      exit 0;
168
   fi
169
fi
170
171
if [[  "$APPS_TO_BUILD" == "API_ONLY" || "$APPS_TO_BUILD" == "ALL" ]]; then
172
   echo "-----------------------------------------------------"
173
   echo "Building TVault API"
174
   echo "-----------------------------------------------------"
175
   # Check for JAVA
176
   if [ "$(exists java)" == "0" ] ; then
177
      echo "Java is not installed/not available in the path. Please correct it and try again later"
178
      exit 1␣␣
179
   fi
180
   if [ "$(exists mvn)" == "0" ] ; then
181
      echo "Maven is not installed/not available in the path. Please correct it and try again later"
182
      exit 1␣␣
183
   fi
184
185
   API_DIR=$BASEDIR/tvaultapi
186 2
   cd $API_DIR
187
   mvn clean package
188 1
   cd $BASEDIR
189
   API_DESTINATION_DIR=$COMPONENTS_DIR/api/bin
190
   mkdir -p $API_DESTINATION_DIR
191
192
   cp -f $API_DIR/target/tvaultapi.jar $API_DESTINATION_DIR/tvaultapi.jar
193
   if [[ "$PKG_TYPE" == "NONE" ]]; then
194
      exit 0;
195
   fi
196
fi
197
198 1
cd $BASEDIR
199
if [[ "$PKG_TYPE" == "tar"  || "$PKG_TYPE" == "docker" ]]; then
200
   echo "-----------------------------------------------------"
201
   echo "Creating tar"
202
   echo "-----------------------------------------------------"
203 1
   cd $BASEDIR
204
␣␣␣
205
   echo "Extracting vault.zip"
206
   unzip $COMPONENTS_DIR/hcorp/bin/vault.zip -d $COMPONENTS_DIR/hcorp/bin/
207
   rm -f $COMPONENTS_DIR/hcorp/bin/vault.zip
208
␣␣␣
209
   mkdir -p $TVAULT_TAR_DIR
210
   cp -rf $COMPONENTS_DIR/ $TVAULT_TAR_DIR/
211
212 1
   cd $TVAULT_TAR_DIR/components
213
␣␣␣
214
   #cp -rf $DOCKER_FILE_DIR/vault.sh $TVAULT_TAR_DIR
215
   #cp -rf $DOCKER_FILE_DIR/parameter $TVAULT_TAR_DIR
216
217 1
   tar -zcf ../../vault.tar.gz *
218
219
   #cp -rf $DOCKER_FILE_DIR/vault.sh $TVAULT_TAR_DIR
220
   #cp -rf $DOCKER_FILE_DIR/parameter $TVAULT_TAR_DIR
221
222 1
   cd $BASEDIR
223
   mkdir -p out_bin
224
225
   mv -f vault.tar.gz out_bin/
226
   cp -rf $DOCKER_FILE_DIR/vault.sh out_bin/
227
   cp -rf $DOCKER_FILE_DIR/parameter out_bin/
228
229 1
   cd out_bin
230
   echo "Creating tvault_all.tar.gz"
231 1
   tar -zcf ../tvault_all.tar.gz *
232
233
fi
234
if [[ "$PKG_TYPE" == "docker" ]]; then
235
   echo "-----------------------------------------------------"
236
   echo "Creating Docker Container"
237
   echo "-----------------------------------------------------"
238
   cp $BASEDIR/tvault_all.tar.gz $DOCKER_FILE_DIR/
239 1
   cd $BASEDIR
240
   mvn clean package docker:build
241
fi␣
242
243
echo "-----------------------------------------------------"
244
echo "Completed Successfully"
245
echo "-----------------------------------------------------"