blob: b8f0da39e4184bd4e5352b81f6d15d4aa4c8f5ed [file] [log] [blame]
garciadeblas93c61312016-09-28 15:12:48 +02001#!/bin/bash
2# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16function usage(){
17 echo -e "usage: $0 [OPTIONS]"
garciadeblasa1fc4572017-04-24 19:08:21 +020018 echo -e "Install OSM from binaries or source code (by default, from binaries)"
garciadeblas93c61312016-09-28 15:12:48 +020019 echo -e " OPTIONS"
garciadeblas0d934c12017-11-17 15:39:17 +010020 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
21 echo -e " --source: install OSM from source code using the latest stable tag"
Mike Marchetti425f8ce2017-06-15 13:02:16 -040022 echo -e " -r <repo>: use specified repository name for osm packages"
garciadeblas0d934c12017-11-17 15:39:17 +010023 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
Mike Marchetti425f8ce2017-06-15 13:02:16 -040024 echo -e " -u <repo base>: use specified repository url for osm packages"
25 echo -e " -k <repo key>: use specified repository public key url"
garciadeblas0d934c12017-11-17 15:39:17 +010026 echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag"
27 echo -e " -b master (main dev branch)"
28 echo -e " -b v2.0 (v2.0 branch)"
29 echo -e " -b tags/v1.1.0 (a specific tag)"
30 echo -e " ..."
31 echo -e " --lxdimages: download lxd images from OSM repository instead of creating them from scratch"
32 echo -e " -l <lxd_repo>: use specified repository url for lxd images"
garciadeblasfc8f0292018-04-02 16:55:29 +020033 echo -e " -p <path>: use specified repository path for lxd images"
peustermd74dc842018-01-24 15:32:17 +010034 echo -e " --vimemu: additionally fetch, build, and deploy the VIM emulator as a docker container"
garciadeblas0d934c12017-11-17 15:39:17 +010035 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
36# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
37 echo -e " --nat: install only NAT rules"
38 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
39# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
40 echo -e " --showopts: print chosen options and exit (only for debugging)"
41 echo -e " -y: do not prompt for confirmation, assumes yes"
Mike Marchetti4de48492018-04-05 12:44:01 -040042 echo -e " -D <devops path> use local devops installation path"
garciadeblas0d934c12017-11-17 15:39:17 +010043 echo -e " -h / --help: print this help"
garciadeblas93c61312016-09-28 15:12:48 +020044}
45
garciadeblas55490d42016-10-29 14:22:03 +020046#Uninstall OSM: remove containers
47function uninstall(){
garciadeblasa1fc4572017-04-24 19:08:21 +020048 echo -e "\nUninstalling OSM"
garciadeblas55490d42016-10-29 14:22:03 +020049 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
50 $OSM_DEVOPS/jenkins/host/clean_container RO
51 $OSM_DEVOPS/jenkins/host/clean_container VCA
prithiv4a98a042017-12-05 23:19:39 +000052 $OSM_DEVOPS/jenkins/host/clean_container MON
garciadeblas55490d42016-10-29 14:22:03 +020053 $OSM_DEVOPS/jenkins/host/clean_container SO
54 #$OSM_DEVOPS/jenkins/host/clean_container UI
55 else
56 lxc stop RO && lxc delete RO
57 lxc stop VCA && lxc delete VCA
prithiv4a98a042017-12-05 23:19:39 +000058 lxc stop MON && lxc delete MON
garciadeblas55490d42016-10-29 14:22:03 +020059 lxc stop SO-ub && lxc delete SO-ub
60 fi
garciadeblas54e7eed2018-03-19 17:38:04 +010061 echo -e "\nDeleting imported lxd images if they exist"
62 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
63 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
64 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
garciadeblas429b9f82018-03-20 02:09:44 +010065 return 0
garciadeblas55490d42016-10-29 14:22:03 +020066}
67
68#Configure NAT rules, based on the current IP addresses of containers
69function nat(){
70 echo -e "\nChecking required packages: iptables-persistent"
71 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
72 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
73 echo -e "\nConfiguring NAT rules"
74 echo -e " Required root privileges"
75 sudo $OSM_DEVOPS/installers/nat_osm
76}
77
Mike Marchettid8577f52017-10-19 15:27:48 -040078function FATAL(){
79 echo "FATAL error: Cannot install OSM due to \"$1\""
80 exit 1
81}
82
garciadeblas2a382732017-01-12 12:11:14 +010083#Update RO, SO and UI:
84function update(){
85 echo -e "\nUpdating components"
86
87 echo -e " Updating RO"
88 CONTAINER="RO"
89 MDG="RO"
90 INSTALL_FOLDER="/opt/openmano"
91 echo -e " Fetching the repo"
92 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
93 BRANCH=""
94 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
Jokin Garayc17db012017-03-08 17:45:39 +010095 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
garciadeblas2a382732017-01-12 12:11:14 +010096 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
97 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
98 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
99 # COMMIT_ID either was previously set with -b option, or is an empty string
100 CHECKOUT_ID=$COMMIT_ID
101 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
102 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
103 if [[ $CHECKOUT_ID == "tags/"* ]]; then
104 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
105 else
106 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
107 fi
108 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
109 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
110 echo " Nothing to be done."
111 else
112 echo " Update required."
garciadeblasa1fc4572017-04-24 19:08:21 +0200113 lxc exec $CONTAINER -- service osm-ro stop
garciadeblas2a382732017-01-12 12:11:14 +0100114 lxc exec $CONTAINER -- git -C /opt/openmano stash
115 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
116 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
117 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
118 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
garciadeblasa1fc4572017-04-24 19:08:21 +0200119 lxc exec $CONTAINER -- service osm-ro start
garciadeblas2a382732017-01-12 12:11:14 +0100120 fi
121 echo
122
123 echo -e " Updating SO and UI"
124 CONTAINER="SO-ub"
125 MDG="SO"
126 INSTALL_FOLDER="" # To be filled in
127 echo -e " Fetching the repo"
128 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
129 BRANCH=""
130 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
Jokin Garayc17db012017-03-08 17:45:39 +0100131 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
garciadeblas2a382732017-01-12 12:11:14 +0100132 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
133 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
134 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
135 # COMMIT_ID either was previously set with -b option, or is an empty string
136 CHECKOUT_ID=$COMMIT_ID
137 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
138 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
139 if [[ $CHECKOUT_ID == "tags/"* ]]; then
140 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
141 else
142 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
143 fi
144 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
145 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
146 echo " Nothing to be done."
147 else
148 echo " Update required."
149 # Instructions to be added
150 # lxc exec SO-ub -- ...
151 fi
152 echo
prithiv4a98a042017-12-05 23:19:39 +0000153 echo -e "Updating MON Container"
154 CONTAINER="MON"
155 MDG="MON"
156 INSTALL_FOLDER="/root/MON"
157 echo -e " Fetching the repo"
158 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
159 BRANCH=""
160 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
161 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
162 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
163 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
164 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
165 # COMMIT_ID either was previously set with -b option, or is an empty string
166 CHECKOUT_ID=$COMMIT_ID
167 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
168 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
169 if [[ $CHECKOUT_ID == "tags/"* ]]; then
170 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
171 else
172 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
173 fi
174 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
175 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
176 echo " Nothing to be done."
177 else
178 echo " Update required."
179 fi
180 echo
garciadeblas2a382732017-01-12 12:11:14 +0100181}
182
Mike Marchetti2b951282017-10-10 15:43:15 -0400183function so_is_up() {
garciadeblas0d934c12017-11-17 15:39:17 +0100184 if [ -n "$1" ]; then
185 SO_IP=$1
186 else
187 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
188 fi
Mike Marchetti6930bc02017-05-31 16:33:02 -0400189 time=0
190 step=5
191 timelength=300
192 while [ $time -le $timelength ]
193 do
Mike Marchetti2b951282017-10-10 15:43:15 -0400194 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
195 -H 'accept: application/vnd.yang.data+json' \
196 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
197 -H 'cache-control: no-cache' 2> /dev/null | jq '.[].components.component_info[] | select(.component_name=="RW.Restconf")' 2>/dev/null | grep "RUNNING" | wc -l` -eq 1 ]]
198 then
199 echo "RW.Restconf running....SO is up"
200 return 0
Mike Marchetti6930bc02017-05-31 16:33:02 -0400201 fi
Mike Marchetti2b951282017-10-10 15:43:15 -0400202
Mike Marchetti6930bc02017-05-31 16:33:02 -0400203 sleep $step
204 echo -n "."
205 time=$((time+step))
206 done
Mike Marchetti2b951282017-10-10 15:43:15 -0400207
garciadeblas0d934c12017-11-17 15:39:17 +0100208 FATAL "OSM Failed to startup. SO failed to startup"
Mike Marchetti6930bc02017-05-31 16:33:02 -0400209}
210
garciadeblas0d934c12017-11-17 15:39:17 +0100211function vca_is_up() {
212 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
213 echo "VCA is up and running"
214 return 0
215 fi
garciadeblas55490d42016-10-29 14:22:03 +0200216
garciadeblas0d934c12017-11-17 15:39:17 +0100217 FATAL "OSM Failed to startup. VCA failed to startup"
218}
219
prithiv4a98a042017-12-05 23:19:39 +0000220function mon_is_up() {
221 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
222 echo "MON is up and running"
223 return 0
224 fi
225
226 FATAL "OSM Failed to startup. MON failed to startup"
227}
228
garciadeblas0d934c12017-11-17 15:39:17 +0100229function ro_is_up() {
230 if [ -n "$1" ]; then
231 RO_IP=$1
232 else
233 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
234 fi
235 time=0
236 step=2
237 timelength=20
238 while [ $time -le $timelength ]; do
239 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
240 echo "RO is up and running"
241 return 0
242 fi
243 sleep $step
244 echo -n "."
245 time=$((time+step))
246 done
247
248 FATAL "OSM Failed to startup. RO failed to startup"
249}
250
251
252function configure_RO(){
253 . $OSM_DEVOPS/installers/export_ips
garciadeblas55490d42016-10-29 14:22:03 +0200254 echo -e " Configuring RO"
garciadeblasa1fc4572017-04-24 19:08:21 +0200255 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
256 lxc exec RO -- service osm-ro restart
Mike Marchetti6930bc02017-05-31 16:33:02 -0400257
garciadeblas0d934c12017-11-17 15:39:17 +0100258 ro_is_up
Mike Marchetti6930bc02017-05-31 16:33:02 -0400259
garciadeblasd8718f12016-10-30 19:39:01 +0100260 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
garciadeblas1b7107e2017-12-21 15:32:02 +0100261 lxc exec RO -- openmano tenant-create osm > /dev/null
prithiv4a98a042017-12-05 23:19:39 +0000262 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
tierno15f4f222017-06-14 13:23:01 +0200263 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
garciadeblas1b7107e2017-12-21 15:32:02 +0100264 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
garciadeblas0d934c12017-11-17 15:39:17 +0100265}
garciadeblas55490d42016-10-29 14:22:03 +0200266
garciadeblas0d934c12017-11-17 15:39:17 +0100267function configure_VCA(){
garciadeblas55490d42016-10-29 14:22:03 +0200268 echo -e " Configuring VCA"
269 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
270 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
garciadeblas0d934c12017-11-17 15:39:17 +0100271}
272
273function configure_SOUI(){
274 . $OSM_DEVOPS/installers/export_ips
garciadeblas55490d42016-10-29 14:22:03 +0200275 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
garciadeblas1b7107e2017-12-21 15:32:02 +0100276 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
garciadeblas55490d42016-10-29 14:22:03 +0200277
prithiv4a98a042017-12-05 23:19:39 +0000278 echo -e " Configuring MON"
279 #Information to be added about SO socket for logging
280
garciadeblas55490d42016-10-29 14:22:03 +0200281 echo -e " Configuring SO"
282 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas2f4c93b2017-04-10 18:12:12 +0200283 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
Jeremy Mordkoff5cc6ccc2017-10-05 15:21:07 -0400284 # make journaling persistent
285 lxc exec SO-ub -- mkdir -p /var/log/journal
286 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
287 lxc exec SO-ub -- systemctl restart systemd-journald
288
Jeremy Mordkoff3b3edea2017-10-03 16:21:56 -0400289 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
290
Mike Marchetti6930bc02017-05-31 16:33:02 -0400291 lxc exec SO-ub -- systemctl restart launchpad
garciadeblas55490d42016-10-29 14:22:03 +0200292
Mike Marchetti6930bc02017-05-31 16:33:02 -0400293 so_is_up $SO_CONTAINER_IP
294
295 #delete existing config agent (could be there on reconfigure)
296 curl -k --request DELETE \
297 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
298 --header 'accept: application/vnd.yang.data+json' \
299 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
300 --header 'cache-control: no-cache' \
301 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
302
303 result=$(curl -k --request POST \
garciadeblas55490d42016-10-29 14:22:03 +0200304 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
305 --header 'accept: application/vnd.yang.data+json' \
306 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
307 --header 'cache-control: no-cache' \
308 --header 'content-type: application/vnd.yang.data+json' \
Mike Marchetti6930bc02017-05-31 16:33:02 -0400309 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
310 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
garciadeblas55490d42016-10-29 14:22:03 +0200311
Mike Marchetti397a65d2017-10-02 22:36:16 -0400312 #R1/R2 config line
313 #result=$(curl -k --request PUT \
314 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
315 # --header 'accept: application/vnd.yang.data+json' \
316 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
317 # --header 'cache-control: no-cache' \
318 # --header 'content-type: application/vnd.yang.data+json' \
319 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
320
Mike Marchetti6930bc02017-05-31 16:33:02 -0400321 result=$(curl -k --request PUT \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400322 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
garciadeblas55490d42016-10-29 14:22:03 +0200323 --header 'accept: application/vnd.yang.data+json' \
324 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400325 --header 'cache-control: no-cache' \
garciadeblas55490d42016-10-29 14:22:03 +0200326 --header 'content-type: application/vnd.yang.data+json' \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400327 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
Mike Marchetti6930bc02017-05-31 16:33:02 -0400328 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
Jeremy Mordkoff2059b392017-10-03 17:34:10 -0400329
Jeremy Mordkoff34151f22017-10-04 19:45:37 -0400330 result=$(curl -k --request PATCH \
331 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
332 --header 'accept: application/vnd.yang.data+json' \
333 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
334 --header 'cache-control: no-cache' \
335 --header 'content-type: application/vnd.yang.data+json' \
336 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
337 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
338
339 result=$(curl -k --request PATCH \
340 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
341 --header 'accept: application/vnd.yang.data+json' \
342 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
343 --header 'cache-control: no-cache' \
344 --header 'content-type: application/vnd.yang.data+json' \
345 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
346 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
347
Jeremy Mordkofff4b6e622017-10-04 12:05:41 -0400348 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
349auto lo:1
prithiv4a98a042017-12-05 23:19:39 +0000350iface lo:1 inet static
Jeremy Mordkofff4b6e622017-10-04 12:05:41 -0400351 address $DEFAULT_IP
352 netmask 255.255.255.255
353EOF
354 lxc exec SO-ub ifup lo:1
garciadeblas0d934c12017-11-17 15:39:17 +0100355}
Jeremy Mordkoff2059b392017-10-03 17:34:10 -0400356
garciadeblas0d934c12017-11-17 15:39:17 +0100357#Configure RO, VCA, and SO with the initial configuration:
358# RO -> tenant:osm, logs to be sent to SO
359# VCA -> juju-password
360# SO -> route to Juju Controller, add RO account, add VCA account
361function configure(){
362 #Configure components
363 echo -e "\nConfiguring components"
364 configure_RO
365 configure_VCA
366 configure_SOUI
garciadeblas55490d42016-10-29 14:22:03 +0200367}
368
garciadeblas2a5a6512016-12-19 10:19:52 +0100369function install_lxd() {
garciadeblas0d934c12017-11-17 15:39:17 +0100370 sudo apt-get update
371 sudo apt-get install -y lxd
372 newgrp lxd
garciadeblas2a5a6512016-12-19 10:19:52 +0100373 lxd init --auto
374 lxd waitready
garciadeblas0d934c12017-11-17 15:39:17 +0100375 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
376 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
377 DEFAULT_MTU=$( ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
378 lxc profile device set default eth0 mtu $DEFAULT_MTU
379 #sudo systemctl stop lxd-bridge
380 #sudo systemctl --system daemon-reload
381 #sudo systemctl enable lxd-bridge
382 #sudo systemctl start lxd-bridge
garciadeblas2a5a6512016-12-19 10:19:52 +0100383}
384
tierno53881d72017-04-25 11:58:57 +0200385function ask_user(){
386 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
387 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
388 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
389 read -e -p "$1" USER_CONFIRMATION
390 while true ; do
391 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
392 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
393 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
394 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
395 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
396 done
397}
garciadeblas2a5a6512016-12-19 10:19:52 +0100398
garciadeblas0d934c12017-11-17 15:39:17 +0100399function launch_container_from_lxd(){
400 export OSM_MDG=$1
401 OSM_load_config
402 export OSM_BASE_IMAGE=$2
403 if ! container_exists $OSM_BUILD_CONTAINER; then
404 CONTAINER_OPTS=""
405 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
406 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
407 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
408 wait_container_up $OSM_BUILD_CONTAINER
409 fi
410}
411
412function install_osmclient(){
413 CLIENT_RELEASE=${RELEASE#"-R "}
414 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
415 CLIENT_REPOSITORY="stable"
416 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
417 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
418 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
419 curl $key_location | sudo apt-key add -
420 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
421 sudo apt-get update
422 sudo apt-get install -y python-osmclient
423 export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
424 export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
425 echo -e "\nOSM client installed"
426 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
427 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
428 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
429}
430
431function install_from_lxdimages(){
432 LXD_RELEASE=${RELEASE#"-R "}
garciadeblasfc8f0292018-04-02 16:55:29 +0200433 if [ -n "$LXD_REPOSITORY_PATH" ]; then
434 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
435 else
436 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
437 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
438 fi
garciadeblas54e7eed2018-03-19 17:38:04 +0100439 echo -e "\nDeleting previous lxd images if they exist"
440 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
441 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
442 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
443 echo -e "\nImporting osm-ro"
garciadeblasfc8f0292018-04-02 16:55:29 +0200444 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
garciadeblas0d934c12017-11-17 15:39:17 +0100445 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
446 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
garciadeblas54e7eed2018-03-19 17:38:04 +0100447 echo -e "\nImporting osm-vca"
garciadeblasfc8f0292018-04-02 16:55:29 +0200448 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
garciadeblas0d934c12017-11-17 15:39:17 +0100449 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
450 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
garciadeblas54e7eed2018-03-19 17:38:04 +0100451 echo -e "\nImporting osm-soui"
garciadeblasfc8f0292018-04-02 16:55:29 +0200452 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
garciadeblas0d934c12017-11-17 15:39:17 +0100453 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
454 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
455 launch_container_from_lxd RO osm-ro
456 ro_is_up && track RO
457 launch_container_from_lxd VCA osm-vca
458 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000459 launch_container_from_lxd MON osm-mon
460 mon_is_up && track MON
garciadeblas0d934c12017-11-17 15:39:17 +0100461 launch_container_from_lxd SO osm-soui
462 #so_is_up && track SOUI
463 track SOUI
464}
465
peusterm3a3e7a52017-12-22 13:10:54 +0100466function install_docker_ce() {
467 # installs and configures Docker CE
468 echo "Installing Docker CE ..."
peusterme2c017e2018-02-07 11:51:11 +0100469 sudo apt-get -qq update
470 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
peusterm3a3e7a52017-12-22 13:10:54 +0100471 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
472 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
473 sudo apt-get -qq update
peusterme2c017e2018-02-07 11:51:11 +0100474 sudo apt-get install -y docker-ce
peusterm3a3e7a52017-12-22 13:10:54 +0100475 echo "Adding user to group 'docker'"
peusterme2c017e2018-02-07 11:51:11 +0100476 sudo groupadd -f docker
peusterm3a3e7a52017-12-22 13:10:54 +0100477 sudo usermod -aG docker $USER
478 echo "... Docker CE installation done"
peusterme2c017e2018-02-07 11:51:11 +0100479 sleep 2
480 sudo service docker restart
481 echo "... restarted Docker service"
peusterm3a3e7a52017-12-22 13:10:54 +0100482}
483
484function install_vimemu() {
485 # install Docker
486 install_docker_ce
487 # clone vim-emu repository (attention: branch is currently master only)
488 echo "Cloning vim-emu repository ..."
489 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git
490 # build vim-emu docker
491 echo "Building vim-emu Docker container..."
peusterme2c017e2018-02-07 11:51:11 +0100492 sudo docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
peusterm3a3e7a52017-12-22 13:10:54 +0100493 # start vim-emu container as daemon
494 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterme2c017e2018-02-07 11:51:11 +0100495 sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
peusterm3a3e7a52017-12-22 13:10:54 +0100496 echo "Waiting for 'vim-emu' container to start ..."
497 sleep 5
peusterme2c017e2018-02-07 11:51:11 +0100498 export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
peusterm3a3e7a52017-12-22 13:10:54 +0100499 echo "vim-emu running at $VIMEMU_HOSTNAME ..."
peustermd74dc842018-01-24 15:32:17 +0100500 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
501 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
502 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
503 echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:"
peusterm3a3e7a52017-12-22 13:10:54 +0100504 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
505 echo -e "\nTo add the emulated VIM to OSM you should do:"
peustermd74dc842018-01-24 15:32:17 +0100506 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://$VIMEMU_HOSTNAME:6001/v2.0 --tenant tenantName --account_type openstack"
peusterm3a3e7a52017-12-22 13:10:54 +0100507}
508
garciadeblas0d934c12017-11-17 15:39:17 +0100509function dump_vars(){
510 echo "DEVELOP=$DEVELOP"
511 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
512 echo "UNINSTALL=$UNINSTALL"
513 echo "NAT=$NAT"
514 echo "UPDATE=$UPDATE"
515 echo "RECONFIGURE=$RECONFIGURE"
516 echo "TEST_INSTALLER=$TEST_INSTALLER"
peusterm3a3e7a52017-12-22 13:10:54 +0100517 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
garciadeblas0d934c12017-11-17 15:39:17 +0100518 echo "INSTALL_LXD=$INSTALL_LXD"
519 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
520 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
garciadeblasfc8f0292018-04-02 16:55:29 +0200521 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
garciadeblas0d934c12017-11-17 15:39:17 +0100522 echo "RELEASE=$RELEASE"
523 echo "REPOSITORY=$REPOSITORY"
524 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
525 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
526 echo "NOCONFIGURE=$NOCONFIGURE"
527 echo "SHOWOPTS=$SHOWOPTS"
528 echo "Install from specific refspec (-b): $COMMIT_ID"
529}
530
531function track(){
532 ctime=`date +%s`
533 duration=$((ctime - SESSION_ID))
534 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
535 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
536 event_name="bin"
537 [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src"
538 [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
539 event_name="${event_name}_$1"
540 url="${url}&event=${event_name}&ce_duration=${duration}"
541 wget -q -O /dev/null $url
542}
543
garciadeblas93c61312016-09-28 15:12:48 +0200544UNINSTALL=""
545DEVELOP=""
546NAT=""
garciadeblas2a382732017-01-12 12:11:14 +0100547UPDATE=""
garciadeblas55490d42016-10-29 14:22:03 +0200548RECONFIGURE=""
549TEST_INSTALLER=""
garciadeblas0d934c12017-11-17 15:39:17 +0100550INSTALL_LXD=""
garciadeblas2a5a6512016-12-19 10:19:52 +0100551SHOWOPTS=""
552COMMIT_ID=""
tierno2cc8e252017-03-08 17:12:05 +0100553ASSUME_YES=""
garciadeblasa1fc4572017-04-24 19:08:21 +0200554INSTALL_FROM_SOURCE=""
garciadeblas82442292017-11-16 14:48:12 +0100555RELEASE="-R ReleaseTHREE"
peusterm3a3e7a52017-12-22 13:10:54 +0100556INSTALL_VIMEMU=""
garciadeblas0d934c12017-11-17 15:39:17 +0100557INSTALL_FROM_LXDIMAGES=""
558LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
garciadeblasfc8f0292018-04-02 16:55:29 +0200559LXD_REPOSITORY_PATH=""
garciadeblas0d934c12017-11-17 15:39:17 +0100560NOCONFIGURE=""
Mike Marchettica56c642017-12-16 16:04:52 -0500561RELEASE_DAILY=""
garciadeblas0d934c12017-11-17 15:39:17 +0100562SESSION_ID=`date +%s`
Mike Marchetti4de48492018-04-05 12:44:01 -0400563OSM_DEVOPS=
garciadeblas0d934c12017-11-17 15:39:17 +0100564
Mike Marchetti4de48492018-04-05 12:44:01 -0400565while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
garciadeblas93c61312016-09-28 15:12:48 +0200566 case "${o}" in
567 h)
568 usage && exit 0
569 ;;
garciadeblas2a5a6512016-12-19 10:19:52 +0100570 b)
571 COMMIT_ID=${OPTARG}
572 ;;
Mike Marchetti425f8ce2017-06-15 13:02:16 -0400573 r)
574 REPOSITORY="-r ${OPTARG}"
575 ;;
576 R)
577 RELEASE="-R ${OPTARG}"
578 ;;
579 k)
580 REPOSITORY_KEY="-k ${OPTARG}"
581 ;;
582 u)
583 REPOSITORY_BASE="-u ${OPTARG}"
584 ;;
garciadeblas0d934c12017-11-17 15:39:17 +0100585 l)
586 LXD_REPOSITORY_BASE="${OPTARG}"
587 ;;
garciadeblasfc8f0292018-04-02 16:55:29 +0200588 p)
589 LXD_REPOSITORY_PATH="${OPTARG}"
590 ;;
Mike Marchetti4de48492018-04-05 12:44:01 -0400591 D)
592 OSM_DEVOPS="${OPTARG}"
593 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200594 -)
595 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblasa1fc4572017-04-24 19:08:21 +0200596 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200597 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
598 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
599 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
garciadeblas2a382732017-01-12 12:11:14 +0100600 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
garciadeblas55490d42016-10-29 14:22:03 +0200601 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
602 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
garciadeblas0d934c12017-11-17 15:39:17 +0100603 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
604 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
peusterm3a3e7a52017-12-22 13:10:54 +0100605 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas0d934c12017-11-17 15:39:17 +0100606 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
garciadeblas2a5a6512016-12-19 10:19:52 +0100607 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
Mike Marchettica56c642017-12-16 16:04:52 -0500608 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200609 echo -e "Invalid option: '--$OPTARG'\n" >&2
610 usage && exit 1
611 ;;
612 \?)
613 echo -e "Invalid option: '-$OPTARG'\n" >&2
614 usage && exit 1
615 ;;
tierno2cc8e252017-03-08 17:12:05 +0100616 y)
617 ASSUME_YES="y"
618 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200619 *)
620 usage && exit 1
621 ;;
622 esac
623done
624
garciadeblasa6ff9862017-04-07 02:00:29 +0200625if [ -n "$SHOWOPTS" ]; then
garciadeblas0d934c12017-11-17 15:39:17 +0100626 dump_vars
garciadeblasa6ff9862017-04-07 02:00:29 +0200627 exit 0
628fi
629
Mike Marchettica56c642017-12-16 16:04:52 -0500630[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
631
Mike Marchetti6930bc02017-05-31 16:33:02 -0400632# if develop, we force master
garciadeblas2a5a6512016-12-19 10:19:52 +0100633[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
Mike Marchetti6930bc02017-05-31 16:33:02 -0400634
Mike Marchetti0d567602017-09-29 14:30:28 -0400635# forcing source from master removed. Now only install from source when explicit
636# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
garciadeblas2a5a6512016-12-19 10:19:52 +0100637
Mike Marchetti4de48492018-04-05 12:44:01 -0400638if [ -z "$OSM_DEVOPS" ]; then
639 if [ -n "$TEST_INSTALLER" ]; then
640 echo -e "\nUsing local devops repo for OSM installation"
641 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
642 else
643 echo -e "\nCreating temporary dir for OSM installation"
644 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
645 trap 'rm -rf "$TEMPDIR"' EXIT
646 fi
garciadeblas55490d42016-10-29 14:22:03 +0200647fi
garciadeblas93c61312016-09-28 15:12:48 +0200648
Mike Marchetti2b951282017-10-10 15:43:15 -0400649need_packages="git jq"
650for package in $need_packages; do
651 echo -e "Checking required packages: $package"
Mike Marchettid8577f52017-10-19 15:27:48 -0400652 dpkg -l $package &>/dev/null \
653 || ! echo -e " $package not installed.\nInstalling $package requires root privileges" \
654 || sudo apt-get install -y $package \
655 || FATAL "failed to install $package"
Mike Marchetti2b951282017-10-10 15:43:15 -0400656done
657
Mike Marchetti4de48492018-04-05 12:44:01 -0400658if [ -z "$OSM_DEVOPS" ]; then
659 if [ -z "$TEST_INSTALLER" ]; then
660 echo -e "\nCloning devops repo temporarily"
661 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
662 RC_CLONE=$?
663 fi
664
665 echo -e "\nGuessing the current stable release"
666 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
667 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
668 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
669 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
670
671 if [ -n "$RELEASE_DAILY" ]; then
672 echo "Using master/HEAD devops"
673 git -C $TEMPDIR checkout master
674 elif [ -z "$TEST_INSTALLER" ]; then
675 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
676 fi
677 OSM_DEVOPS=$TEMPDIR
garciadeblas55490d42016-10-29 14:22:03 +0200678fi
garciadeblas2a382732017-01-12 12:11:14 +0100679
Mike Marchetti4de48492018-04-05 12:44:01 -0400680OSM_JENKINS="$OSM_DEVOPS/jenkins"
garciadeblas0fe45dd2016-10-04 07:54:17 +0200681. $OSM_JENKINS/common/all_funcs
garciadeblas93c61312016-09-28 15:12:48 +0200682
garciadeblasd8718f12016-10-30 19:39:01 +0100683[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
684[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
garciadeblas2a382732017-01-12 12:11:14 +0100685[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
garciadeblasd8718f12016-10-30 19:39:01 +0100686[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas93c61312016-09-28 15:12:48 +0200687
688#Installation starts here
garciadeblasa1fc4572017-04-24 19:08:21 +0200689echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
prithiv4a98a042017-12-05 23:19:39 +0000690if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
tierno53881d72017-04-25 11:58:57 +0200691 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
tierno2cc8e252017-03-08 17:12:05 +0100692fi
693
garciadeblasa1fc4572017-04-24 19:08:21 +0200694echo -e "\nChecking required packages: wget, curl, tar"
695dpkg -l wget curl tar &>/dev/null || ! echo -e " One or several packages are not installed.\nInstalling required packages\n Root privileges are required" || sudo apt-get install -y wget curl tar
696
Jokin Garayc0a65962017-03-09 14:51:48 +0100697echo -e "Checking required packages: lxd"
garciadeblasd880f722017-04-07 20:14:57 +0200698lxd --version &>/dev/null || FATAL "lxd not present, exiting."
garciadeblas0d934c12017-11-17 15:39:17 +0100699[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
garciadeblas2a5a6512016-12-19 10:19:52 +0100700
Mike Marchetti02a533a2018-04-05 21:23:33 -0400701wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
garciadeblas0d934c12017-11-17 15:39:17 +0100702track start
garciadeblas93c61312016-09-28 15:12:48 +0200703
Mike Marchettid1e08b92017-09-29 16:14:11 -0400704# use local devops for containers
705export OSM_USE_LOCAL_DEVOPS=true
garciadeblas0d934c12017-11-17 15:39:17 +0100706if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
garciadeblasa1fc4572017-04-24 19:08:21 +0200707 echo -e "\nCreating the containers and building from source ..."
708 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
garciadeblas0d934c12017-11-17 15:39:17 +0100709 ro_is_up && track RO
garciadeblasa1fc4572017-04-24 19:08:21 +0200710 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
garciadeblas0d934c12017-11-17 15:39:17 +0100711 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000712 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
713 mon_is_up && track MON
garciadeblasa1fc4572017-04-24 19:08:21 +0200714 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
715 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
garciadeblas0d934c12017-11-17 15:39:17 +0100716 #so_is_up && track SOUI
717 track SOUI
718elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
719 echo -e "\nInstalling from lxd images ..."
720 install_from_lxdimages
721else #install from binaries
722 echo -e "\nCreating the containers and installing from binaries ..."
723 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
724 ro_is_up && track RO
725 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
726 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000727 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
728 mon_is_up && track MON
garciadeblas0d934c12017-11-17 15:39:17 +0100729 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
730 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
731 #so_is_up && track SOUI
732 track SOUI
garciadeblasa1fc4572017-04-24 19:08:21 +0200733fi
garciadeblas93c61312016-09-28 15:12:48 +0200734
garciadeblas55490d42016-10-29 14:22:03 +0200735#Install iptables-persistent and configure NAT rules
garciadeblas0d934c12017-11-17 15:39:17 +0100736[ -z "$NOCONFIGURE" ] && nat
garciadeblas93c61312016-09-28 15:12:48 +0200737
738#Configure components
garciadeblas0d934c12017-11-17 15:39:17 +0100739[ -z "$NOCONFIGURE" ] && configure
740
741#Install osmclient
742[ -z "$NOCONFIGURE" ] && install_osmclient
garciadeblas93c61312016-09-28 15:12:48 +0200743
peusterm3a3e7a52017-12-22 13:10:54 +0100744#Install vim-emu (optional)
745if [ -n "$INSTALL_VIMEMU" ]; then
746 echo -e "\nInstalling vim-emu ..."
747 install_vimemu
748fi
749
Mike Marchetti02a533a2018-04-05 21:23:33 -0400750wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
garciadeblas0d934c12017-11-17 15:39:17 +0100751track end
Jokin Garay3eb9ce72017-03-09 14:48:11 +0100752echo -e "\nDONE"
garciadeblas0d934c12017-11-17 15:39:17 +0100753