08f45635149df1f6f3e9517a2fad7bb90e75f4f6
[it/dep.git] / ric-xapps / 90-xApps / bin / install
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
4 #   Copyright (c) 2019 Nokia.                                                  #
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 ################################################################################
18
19
20 while [ -n "$1" ]; do # while loop starts
21
22     case "$1" in
23
24     -n) 
25         CHART_NAME=$2
26         shift
27         ;; 
28
29     -v) CHART_VERSION=$2
30         shift
31         ;; # Message for -b option
32
33     -f) OVERRIDEYAML=$2
34         shift
35         ;; # Message for -c option
36     
37     -i) FULLIMAGE=$2
38         shift
39         ;;
40
41     -d) DESCRIPTOR_PATH=$2
42         shift
43         ;;
44
45     -c) CONFIG_JSON_PATH=$2
46         shift
47         ;;
48
49     -h) HELM_REPO_USERNAME=$2
50         shift
51         ;;
52     
53     -p) HELM_REPO_PASSWORD=$2
54         shift
55         ;;
56
57     *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
58
59     esac
60
61     shift
62
63 done
64
65
66
67
68 if [ -z $CHART_NAME ]; then
69   echo "Please specify chart name using -n option."
70   exit 1
71 fi
72 if [ -z $CHART_VERSION ]; then
73   echo "Please specify chart version using -v option."
74   exit 1
75 fi
76 if [ -z $FULLIMAGE ]; then
77   echo "Please specify image using -i option."
78   exit 1
79 fi
80 if [ -z $DESCRIPTOR_PATH ]; then
81   echo "Please specify descriptor file using -d option."
82   exit 1
83 fi
84 if [ -z $CONFIG_JSON_PATH ]; then
85   echo "Please specify config json file using -c option."
86   exit 1
87 fi
88
89
90 if [ ! -f $DESCRIPTOR_PATH ]; then
91   echo "Descriptor file cannot be founded at $DESCRIPTOR_PATH"
92   exit 1
93 fi
94 if [ ! -f $CONFIG_JSON_PATH ]; then
95   echo "Config json file cannot be founded at $CONFIG_JSON_PATH"
96   exit 1
97 fi
98
99
100 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
101
102
103 source $DIR/../etc/xapp.conf
104
105 if [ -z $OVERRIDEYAML ]; then
106   HELM_REPO=$default_helm_repo
107   DOCKER_REGISTRY=$default_docker_registry
108 else
109   helm_repo_override=$(grep "^ *helmRepository:" $OVERRIDEYAML |  awk '{gsub(/ /,""); gsub(/\"/,""); split($0, b, "tory:");split(b[2],c,"#"); print c[1]}')
110   docker_reg_override=$(grep "^ *repository:" $OVERRIDEYAML |  awk '{ gsub(/ /,""); gsub(/\"/,""); split($0, b, "tory:");split(b[2],c,"#"); print c[1]}')
111   if [ -z $helm_repo_override ]; then
112     HELM_REPO=$default_helm_repo
113   else
114     HELM_REPO=$helm_repo_override
115   fi
116
117   if [ -z $docker_reg_override ]; then
118     DOCKER_REGISTRY=$default_docker_registry
119   else
120     DOCKER_REGISTRY=$docker_reg_override
121   fi
122 fi
123
124
125
126
127 rm -rf /tmp/$CHART_NAME
128
129 cp -r $DIR/../helm/xapp-std/ /tmp/$CHART_NAME
130
131
132
133 sed -i "s/^name: xapp-std/name: $CHART_NAME/" /tmp/$CHART_NAME/Chart.yaml
134 sed -i "s/^version: 0.0.1/version: $CHART_VERSION/" /tmp/$CHART_NAME/Chart.yaml
135
136
137 registry_path=$(echo $FULLIMAGE | awk '{n=split($0, a, "/"); if(n>1) print a[1]}')
138
139
140
141 tag=$(echo $FULLIMAGE | awk '{n=split($0, a, "/"); split(a[n], b, ":"); print b[2]}')
142
143 image=$(echo $FULLIMAGE | awk -v head="$registry_path/" -v tail=":$tag" '{gsub (head, ""); gsub(tail,""); gsub(/\//,"\\/"); print $0}') 
144
145
146 sed -i "s/^  name: xapp-std/  name: $CHART_NAME/" /tmp/$CHART_NAME/values.yaml
147 sed -i "s/^    name: xapp-std/    name: $image/" /tmp/$CHART_NAME/values.yaml
148 sed -i "s/^    tag: latest/    tag: $tag/" /tmp/$CHART_NAME/values.yaml
149
150
151 if [ -z $registry_path ]; then
152   sed -i "s/^    repository: xapp-std-reg/    repository: $DOCKER_REGISTRY/" /tmp/$CHART_NAME/values.yaml
153 else
154   sed -i "s/^    repository: xapp-std-reg/    repository: $registry_path/" /tmp/$CHART_NAME/values.yaml
155 fi
156
157
158
159
160 cp $CONFIG_JSON_PATH /tmp/$CHART_NAME/config/
161 cp $DESCRIPTOR_PATH /tmp/$CHART_NAME/descriptors/
162
163
164 helm package -d /tmp /tmp/$CHART_NAME
165
166
167 echo $HELM_REPO
168 curl -k -u $HELM_REPO_USERNAME:$HELM_REPO_PASSWORD $HELM_REPO --upload-file /tmp/$CHART_NAME-$CHART_VERSION.tgz -v
169
170