blob: bacf424efdc7bd716209fdccd1500dfb95e221ad [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"
garciadeblas14097dc2018-04-04 18:36:32 +020034 echo -e " --lightweight: install lightweight build of OSM"
peustermd74dc842018-01-24 15:32:17 +010035 echo -e " --vimemu: additionally fetch, build, and deploy the VIM emulator as a docker container"
garciadeblas0d934c12017-11-17 15:39:17 +010036 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
37# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
38 echo -e " --nat: install only NAT rules"
39 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
40# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
41 echo -e " --showopts: print chosen options and exit (only for debugging)"
42 echo -e " -y: do not prompt for confirmation, assumes yes"
Mike Marchetti4de48492018-04-05 12:44:01 -040043 echo -e " -D <devops path> use local devops installation path"
garciadeblas0d934c12017-11-17 15:39:17 +010044 echo -e " -h / --help: print this help"
garciadeblas93c61312016-09-28 15:12:48 +020045}
46
garciadeblas55490d42016-10-29 14:22:03 +020047#Uninstall OSM: remove containers
48function uninstall(){
garciadeblasa1fc4572017-04-24 19:08:21 +020049 echo -e "\nUninstalling OSM"
garciadeblas55490d42016-10-29 14:22:03 +020050 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
51 $OSM_DEVOPS/jenkins/host/clean_container RO
52 $OSM_DEVOPS/jenkins/host/clean_container VCA
prithiv4a98a042017-12-05 23:19:39 +000053 $OSM_DEVOPS/jenkins/host/clean_container MON
garciadeblas55490d42016-10-29 14:22:03 +020054 $OSM_DEVOPS/jenkins/host/clean_container SO
55 #$OSM_DEVOPS/jenkins/host/clean_container UI
56 else
57 lxc stop RO && lxc delete RO
58 lxc stop VCA && lxc delete VCA
prithiv4a98a042017-12-05 23:19:39 +000059 lxc stop MON && lxc delete MON
garciadeblas55490d42016-10-29 14:22:03 +020060 lxc stop SO-ub && lxc delete SO-ub
61 fi
garciadeblas54e7eed2018-03-19 17:38:04 +010062 echo -e "\nDeleting imported lxd images if they exist"
63 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
64 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
65 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
garciadeblas429b9f82018-03-20 02:09:44 +010066 return 0
garciadeblas55490d42016-10-29 14:22:03 +020067}
68
garciadeblas831ee562018-04-30 10:02:21 +020069#Uninstall lightweight OSM: remove dockers
70function uninstall_lightweight(){
71 echo -e "\nUninstalling lightweight OSM"
72 docker stack rm osm
73 COUNTER=0
74 result=11
75 while [ ${COUNTER} -lt 30 ]; do
76 sleep 1
77 result=$(docker stack ps osm | wc -l)
78 #echo "Dockers running: $result"
79 if [ "${result}" == "0" ]; then
80 break
81 fi
82 let COUNTER=COUNTER+1
83 done
84 if [ "${result}" == "0" ]; then
85 echo "All dockers of the stack osm were removed"
86 else
87 FATAL "Some dockers of the stack osm could not be removed. Could not uninstall OSM in single shot. Try to uninstall again"
88 fi
89 sleep 5
90 docker image rm osm/ro
91 docker image rm osm/lcm
92 docker image rm osm/light-ui
93 docker image rm osm/nbi
94 docker image rm osm/mon
95 docker image rm osm/pm
96 return 0
97}
98
garciadeblas55490d42016-10-29 14:22:03 +020099#Configure NAT rules, based on the current IP addresses of containers
100function nat(){
101 echo -e "\nChecking required packages: iptables-persistent"
102 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
103 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
104 echo -e "\nConfiguring NAT rules"
105 echo -e " Required root privileges"
106 sudo $OSM_DEVOPS/installers/nat_osm
107}
108
Mike Marchettid8577f52017-10-19 15:27:48 -0400109function FATAL(){
110 echo "FATAL error: Cannot install OSM due to \"$1\""
111 exit 1
112}
113
garciadeblas2a382732017-01-12 12:11:14 +0100114#Update RO, SO and UI:
115function update(){
116 echo -e "\nUpdating components"
117
118 echo -e " Updating RO"
119 CONTAINER="RO"
120 MDG="RO"
121 INSTALL_FOLDER="/opt/openmano"
122 echo -e " Fetching the repo"
123 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
124 BRANCH=""
125 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 +0100126 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
garciadeblas2a382732017-01-12 12:11:14 +0100127 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
128 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
129 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
130 # COMMIT_ID either was previously set with -b option, or is an empty string
131 CHECKOUT_ID=$COMMIT_ID
132 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
133 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
134 if [[ $CHECKOUT_ID == "tags/"* ]]; then
135 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
136 else
137 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
138 fi
139 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
140 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
141 echo " Nothing to be done."
142 else
143 echo " Update required."
garciadeblasa1fc4572017-04-24 19:08:21 +0200144 lxc exec $CONTAINER -- service osm-ro stop
garciadeblas2a382732017-01-12 12:11:14 +0100145 lxc exec $CONTAINER -- git -C /opt/openmano stash
146 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
147 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
148 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
149 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
garciadeblasa1fc4572017-04-24 19:08:21 +0200150 lxc exec $CONTAINER -- service osm-ro start
garciadeblas2a382732017-01-12 12:11:14 +0100151 fi
152 echo
153
154 echo -e " Updating SO and UI"
155 CONTAINER="SO-ub"
156 MDG="SO"
157 INSTALL_FOLDER="" # To be filled in
158 echo -e " Fetching the repo"
159 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
160 BRANCH=""
161 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 +0100162 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
garciadeblas2a382732017-01-12 12:11:14 +0100163 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
164 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
165 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
166 # COMMIT_ID either was previously set with -b option, or is an empty string
167 CHECKOUT_ID=$COMMIT_ID
168 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
169 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
170 if [[ $CHECKOUT_ID == "tags/"* ]]; then
171 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
172 else
173 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
174 fi
175 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
176 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
177 echo " Nothing to be done."
178 else
179 echo " Update required."
180 # Instructions to be added
181 # lxc exec SO-ub -- ...
182 fi
183 echo
prithiv4a98a042017-12-05 23:19:39 +0000184 echo -e "Updating MON Container"
185 CONTAINER="MON"
186 MDG="MON"
187 INSTALL_FOLDER="/root/MON"
188 echo -e " Fetching the repo"
189 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
190 BRANCH=""
191 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
192 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
193 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
194 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
195 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
196 # COMMIT_ID either was previously set with -b option, or is an empty string
197 CHECKOUT_ID=$COMMIT_ID
198 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
199 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
200 if [[ $CHECKOUT_ID == "tags/"* ]]; then
201 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
202 else
203 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
204 fi
205 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
206 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
207 echo " Nothing to be done."
208 else
209 echo " Update required."
210 fi
211 echo
garciadeblas2a382732017-01-12 12:11:14 +0100212}
213
Mike Marchetti2b951282017-10-10 15:43:15 -0400214function so_is_up() {
garciadeblas0d934c12017-11-17 15:39:17 +0100215 if [ -n "$1" ]; then
216 SO_IP=$1
217 else
218 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
219 fi
Mike Marchetti6930bc02017-05-31 16:33:02 -0400220 time=0
221 step=5
222 timelength=300
223 while [ $time -le $timelength ]
224 do
Mike Marchetti2b951282017-10-10 15:43:15 -0400225 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
226 -H 'accept: application/vnd.yang.data+json' \
227 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
228 -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 ]]
229 then
230 echo "RW.Restconf running....SO is up"
231 return 0
Mike Marchetti6930bc02017-05-31 16:33:02 -0400232 fi
Mike Marchetti2b951282017-10-10 15:43:15 -0400233
Mike Marchetti6930bc02017-05-31 16:33:02 -0400234 sleep $step
235 echo -n "."
236 time=$((time+step))
237 done
Mike Marchetti2b951282017-10-10 15:43:15 -0400238
garciadeblas0d934c12017-11-17 15:39:17 +0100239 FATAL "OSM Failed to startup. SO failed to startup"
Mike Marchetti6930bc02017-05-31 16:33:02 -0400240}
241
garciadeblas0d934c12017-11-17 15:39:17 +0100242function vca_is_up() {
243 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
244 echo "VCA is up and running"
245 return 0
246 fi
garciadeblas55490d42016-10-29 14:22:03 +0200247
garciadeblas0d934c12017-11-17 15:39:17 +0100248 FATAL "OSM Failed to startup. VCA failed to startup"
249}
250
prithiv4a98a042017-12-05 23:19:39 +0000251function mon_is_up() {
252 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
253 echo "MON is up and running"
254 return 0
255 fi
256
257 FATAL "OSM Failed to startup. MON failed to startup"
258}
259
garciadeblas0d934c12017-11-17 15:39:17 +0100260function ro_is_up() {
261 if [ -n "$1" ]; then
262 RO_IP=$1
263 else
264 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
265 fi
266 time=0
267 step=2
268 timelength=20
269 while [ $time -le $timelength ]; do
270 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
271 echo "RO is up and running"
272 return 0
273 fi
274 sleep $step
275 echo -n "."
276 time=$((time+step))
277 done
278
279 FATAL "OSM Failed to startup. RO failed to startup"
280}
281
282
283function configure_RO(){
284 . $OSM_DEVOPS/installers/export_ips
garciadeblas55490d42016-10-29 14:22:03 +0200285 echo -e " Configuring RO"
garciadeblasa1fc4572017-04-24 19:08:21 +0200286 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
287 lxc exec RO -- service osm-ro restart
Mike Marchetti6930bc02017-05-31 16:33:02 -0400288
garciadeblas0d934c12017-11-17 15:39:17 +0100289 ro_is_up
Mike Marchetti6930bc02017-05-31 16:33:02 -0400290
garciadeblasd8718f12016-10-30 19:39:01 +0100291 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
garciadeblas1b7107e2017-12-21 15:32:02 +0100292 lxc exec RO -- openmano tenant-create osm > /dev/null
prithiv4a98a042017-12-05 23:19:39 +0000293 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
tierno15f4f222017-06-14 13:23:01 +0200294 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
garciadeblas1b7107e2017-12-21 15:32:02 +0100295 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
garciadeblas0d934c12017-11-17 15:39:17 +0100296}
garciadeblas55490d42016-10-29 14:22:03 +0200297
garciadeblas0d934c12017-11-17 15:39:17 +0100298function configure_VCA(){
garciadeblas55490d42016-10-29 14:22:03 +0200299 echo -e " Configuring VCA"
300 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
301 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
garciadeblas0d934c12017-11-17 15:39:17 +0100302}
303
304function configure_SOUI(){
305 . $OSM_DEVOPS/installers/export_ips
garciadeblas55490d42016-10-29 14:22:03 +0200306 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
garciadeblas1b7107e2017-12-21 15:32:02 +0100307 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
garciadeblas55490d42016-10-29 14:22:03 +0200308
prithiv4a98a042017-12-05 23:19:39 +0000309 echo -e " Configuring MON"
310 #Information to be added about SO socket for logging
311
garciadeblas55490d42016-10-29 14:22:03 +0200312 echo -e " Configuring SO"
313 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas2f4c93b2017-04-10 18:12:12 +0200314 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
Jeremy Mordkoff5cc6ccc2017-10-05 15:21:07 -0400315 # make journaling persistent
316 lxc exec SO-ub -- mkdir -p /var/log/journal
317 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
318 lxc exec SO-ub -- systemctl restart systemd-journald
319
Jeremy Mordkoff3b3edea2017-10-03 16:21:56 -0400320 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
321
Mike Marchetti6930bc02017-05-31 16:33:02 -0400322 lxc exec SO-ub -- systemctl restart launchpad
garciadeblas55490d42016-10-29 14:22:03 +0200323
Mike Marchetti6930bc02017-05-31 16:33:02 -0400324 so_is_up $SO_CONTAINER_IP
325
326 #delete existing config agent (could be there on reconfigure)
327 curl -k --request DELETE \
328 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
329 --header 'accept: application/vnd.yang.data+json' \
330 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
331 --header 'cache-control: no-cache' \
332 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
333
334 result=$(curl -k --request POST \
garciadeblas55490d42016-10-29 14:22:03 +0200335 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
336 --header 'accept: application/vnd.yang.data+json' \
337 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
338 --header 'cache-control: no-cache' \
339 --header 'content-type: application/vnd.yang.data+json' \
Mike Marchetti6930bc02017-05-31 16:33:02 -0400340 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
341 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
garciadeblas55490d42016-10-29 14:22:03 +0200342
Mike Marchetti397a65d2017-10-02 22:36:16 -0400343 #R1/R2 config line
344 #result=$(curl -k --request PUT \
345 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
346 # --header 'accept: application/vnd.yang.data+json' \
347 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
348 # --header 'cache-control: no-cache' \
349 # --header 'content-type: application/vnd.yang.data+json' \
350 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
351
Mike Marchetti6930bc02017-05-31 16:33:02 -0400352 result=$(curl -k --request PUT \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400353 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
garciadeblas55490d42016-10-29 14:22:03 +0200354 --header 'accept: application/vnd.yang.data+json' \
355 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400356 --header 'cache-control: no-cache' \
garciadeblas55490d42016-10-29 14:22:03 +0200357 --header 'content-type: application/vnd.yang.data+json' \
Mike Marchetti397a65d2017-10-02 22:36:16 -0400358 --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 -0400359 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
Jeremy Mordkoff2059b392017-10-03 17:34:10 -0400360
Jeremy Mordkoff34151f22017-10-04 19:45:37 -0400361 result=$(curl -k --request PATCH \
362 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
363 --header 'accept: application/vnd.yang.data+json' \
364 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
365 --header 'cache-control: no-cache' \
366 --header 'content-type: application/vnd.yang.data+json' \
367 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
368 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
369
370 result=$(curl -k --request PATCH \
371 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
372 --header 'accept: application/vnd.yang.data+json' \
373 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
374 --header 'cache-control: no-cache' \
375 --header 'content-type: application/vnd.yang.data+json' \
376 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
377 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
378
Jeremy Mordkofff4b6e622017-10-04 12:05:41 -0400379 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
380auto lo:1
prithiv4a98a042017-12-05 23:19:39 +0000381iface lo:1 inet static
Jeremy Mordkofff4b6e622017-10-04 12:05:41 -0400382 address $DEFAULT_IP
383 netmask 255.255.255.255
384EOF
385 lxc exec SO-ub ifup lo:1
garciadeblas0d934c12017-11-17 15:39:17 +0100386}
Jeremy Mordkoff2059b392017-10-03 17:34:10 -0400387
garciadeblas0d934c12017-11-17 15:39:17 +0100388#Configure RO, VCA, and SO with the initial configuration:
389# RO -> tenant:osm, logs to be sent to SO
390# VCA -> juju-password
391# SO -> route to Juju Controller, add RO account, add VCA account
392function configure(){
393 #Configure components
394 echo -e "\nConfiguring components"
395 configure_RO
396 configure_VCA
397 configure_SOUI
garciadeblas55490d42016-10-29 14:22:03 +0200398}
399
garciadeblas2a5a6512016-12-19 10:19:52 +0100400function install_lxd() {
garciadeblas0d934c12017-11-17 15:39:17 +0100401 sudo apt-get update
402 sudo apt-get install -y lxd
403 newgrp lxd
garciadeblas2a5a6512016-12-19 10:19:52 +0100404 lxd init --auto
405 lxd waitready
garciadeblas0d934c12017-11-17 15:39:17 +0100406 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
407 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
garciadeblas749af852018-04-19 18:43:50 +0200408 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
garciadeblas0d934c12017-11-17 15:39:17 +0100409 lxc profile device set default eth0 mtu $DEFAULT_MTU
410 #sudo systemctl stop lxd-bridge
411 #sudo systemctl --system daemon-reload
412 #sudo systemctl enable lxd-bridge
413 #sudo systemctl start lxd-bridge
garciadeblas2a5a6512016-12-19 10:19:52 +0100414}
415
tierno53881d72017-04-25 11:58:57 +0200416function ask_user(){
417 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
418 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
419 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
420 read -e -p "$1" USER_CONFIRMATION
421 while true ; do
422 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
423 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
424 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
425 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
426 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
427 done
428}
garciadeblas2a5a6512016-12-19 10:19:52 +0100429
garciadeblas0d934c12017-11-17 15:39:17 +0100430function launch_container_from_lxd(){
431 export OSM_MDG=$1
432 OSM_load_config
433 export OSM_BASE_IMAGE=$2
434 if ! container_exists $OSM_BUILD_CONTAINER; then
435 CONTAINER_OPTS=""
436 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
437 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
438 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
439 wait_container_up $OSM_BUILD_CONTAINER
440 fi
441}
442
443function install_osmclient(){
444 CLIENT_RELEASE=${RELEASE#"-R "}
445 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
garciadeblasa9ef0992018-04-19 11:18:06 +0200446 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
garciadeblas0d934c12017-11-17 15:39:17 +0100447 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
448 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
449 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
450 curl $key_location | sudo apt-key add -
451 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
452 sudo apt-get update
garciadeblas8db0ffd2018-04-20 11:56:34 +0200453 sudo apt-get install -y python-pip
454 sudo -H pip install pip==9.0.3
455 sudo -H pip install python-magic
garciadeblas0d934c12017-11-17 15:39:17 +0100456 sudo apt-get install -y python-osmclient
garciadeblasb7d8d802018-04-18 16:39:17 +0200457 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
458 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
459 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
garciadeblasfeef8872018-04-19 13:35:25 +0200460 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
461 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
462 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=localhost
garciadeblas0d934c12017-11-17 15:39:17 +0100463 echo -e "\nOSM client installed"
464 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
465 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
garciadeblasb7d8d802018-04-18 16:39:17 +0200466 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
467 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
468 return 0
garciadeblas0d934c12017-11-17 15:39:17 +0100469}
470
471function install_from_lxdimages(){
472 LXD_RELEASE=${RELEASE#"-R "}
garciadeblasfc8f0292018-04-02 16:55:29 +0200473 if [ -n "$LXD_REPOSITORY_PATH" ]; then
474 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
475 else
476 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
477 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
478 fi
garciadeblas54e7eed2018-03-19 17:38:04 +0100479 echo -e "\nDeleting previous lxd images if they exist"
480 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
481 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
482 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
483 echo -e "\nImporting osm-ro"
garciadeblasfc8f0292018-04-02 16:55:29 +0200484 [ -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 +0100485 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
486 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
garciadeblas54e7eed2018-03-19 17:38:04 +0100487 echo -e "\nImporting osm-vca"
garciadeblasfc8f0292018-04-02 16:55:29 +0200488 [ -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 +0100489 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
490 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
garciadeblas54e7eed2018-03-19 17:38:04 +0100491 echo -e "\nImporting osm-soui"
garciadeblasfc8f0292018-04-02 16:55:29 +0200492 [ -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 +0100493 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
494 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
495 launch_container_from_lxd RO osm-ro
496 ro_is_up && track RO
497 launch_container_from_lxd VCA osm-vca
498 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000499 launch_container_from_lxd MON osm-mon
500 mon_is_up && track MON
garciadeblas0d934c12017-11-17 15:39:17 +0100501 launch_container_from_lxd SO osm-soui
502 #so_is_up && track SOUI
503 track SOUI
504}
505
peusterm3a3e7a52017-12-22 13:10:54 +0100506function install_docker_ce() {
507 # installs and configures Docker CE
508 echo "Installing Docker CE ..."
peusterme2c017e2018-02-07 11:51:11 +0100509 sudo apt-get -qq update
510 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
peusterm3a3e7a52017-12-22 13:10:54 +0100511 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
512 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
513 sudo apt-get -qq update
peusterme2c017e2018-02-07 11:51:11 +0100514 sudo apt-get install -y docker-ce
peusterm3a3e7a52017-12-22 13:10:54 +0100515 echo "Adding user to group 'docker'"
peusterme2c017e2018-02-07 11:51:11 +0100516 sudo groupadd -f docker
peusterm3a3e7a52017-12-22 13:10:54 +0100517 sudo usermod -aG docker $USER
518 echo "... Docker CE installation done"
peusterme2c017e2018-02-07 11:51:11 +0100519 sleep 2
520 sudo service docker restart
521 echo "... restarted Docker service"
peusterm3a3e7a52017-12-22 13:10:54 +0100522}
523
garciadeblas41012602018-04-23 17:23:35 +0200524function install_docker_compose() {
525 # installs and configures docker-compose
526 echo "Installing Docker Compose ..."
527 sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
528 sudo chmod +x /usr/local/bin/docker-compose
529 echo "... Docker Compose installation done"
530}
531
garciadeblas14097dc2018-04-04 18:36:32 +0200532function install_juju() {
533 echo "Installing juju"
534 sudo snap install juju --classic
535 sudo dpkg-reconfigure -p medium lxd
garciadeblasdb797322018-05-04 11:03:31 +0200536 sg lxd -c "juju bootstrap localhost osm"
garciadeblas14097dc2018-04-04 18:36:32 +0200537 echo "Finished installation of juju"
538}
539
540function generate_docker_images() {
541 echo "Pulling and generating docker images"
542 newgrp docker << EONG
543 docker pull wurstmeister/kafka
544 docker pull wurstmeister/zookeeper
545 docker pull mongo
garciadeblas41012602018-04-23 17:23:35 +0200546 docker pull mysql:5
garciadeblas14097dc2018-04-04 18:36:32 +0200547 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
548 docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon || ! echo "cannot build MON docker image" >&2
549 docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm || ! echo "cannot build PM docker image" >&2
550 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
Mike Marchetti00b76aa2018-04-18 14:09:50 -0400551 docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2
garciadeblas14097dc2018-04-04 18:36:32 +0200552 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
553 docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2
554 docker build ${LWTEMPDIR}/RO/lcm -t osm/lcm || ! echo "cannot build LCM docker image" >&2
555 git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git
556 docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile
557EONG
558 echo "Finished generation of docker images"
559}
560
garciadeblas46e99592018-04-16 13:32:02 +0200561function generate_docker_env_files() {
562 echo "Generating docker env files"
563 OSMLCM_VCA_HOST=`juju show-controller|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
garciadeblas7077be62018-05-03 15:06:24 +0200564 OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
garciadeblas46e99592018-04-16 13:32:02 +0200565 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
garciadeblas5de942e2018-04-19 15:25:23 +0200566 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee ${OSM_DEVOPS}/installers/docker/lcm.env
567 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a ${OSM_DEVOPS}/installers/docker/lcm.env
568 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro-db.env
569 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro.env
570 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env
garciadeblas46e99592018-04-16 13:32:02 +0200571 echo "Finished generation of docker env files"
572}
573
garciadeblas14097dc2018-04-04 18:36:32 +0200574function deploy_lightweight() {
575 echo "Deploying lightweight build"
576 newgrp docker << EONG
garciadeblas46e99592018-04-16 13:32:02 +0200577 docker swarm init --advertise-addr ${DEFAULT_IP}
garciadeblas749af852018-04-19 18:43:50 +0200578 docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM
garciadeblas46e99592018-04-16 13:32:02 +0200579 docker stack deploy -c ${OSM_DEVOPS}/installers/docker/docker-compose.yaml osm
garciadeblas41012602018-04-23 17:23:35 +0200580 #docker-compose -f /usr/share/osm-devops/installers/docker/docker-compose.yaml up -d
garciadeblas14097dc2018-04-04 18:36:32 +0200581EONG
582 echo "Finished deployment of lightweight build"
583}
584
garciadeblas14097dc2018-04-04 18:36:32 +0200585function install_lightweight() {
586 echo "Installing lightweight build of OSM"
587 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
garciadeblas46e99592018-04-16 13:32:02 +0200588 trap 'rm -rf "${LWTEMPDIR}"' EXIT
589 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
590 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
garciadeblas749af852018-04-19 18:43:50 +0200591 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
garciadeblas63ac9022018-05-03 11:49:00 +0200592 need_packages_lw="lxd"
593 echo -e "Checking required packages: $need_packages_lw"
594 dpkg -l $need_packages_lw &>/dev/null \
595 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
596 || sudo apt-get update \
597 || FATAL "failed to run apt-get update"
598 dpkg -l $need_packages_lw &>/dev/null \
599 || ! echo -e "Installing $need_packages_lw requires root privileges." \
600 || sudo apt-get install -y $need_packages_lw \
601 || FATAL "failed to install $need_packages_lw"
garciadeblas14097dc2018-04-04 18:36:32 +0200602 install_juju
603 install_docker_ce
garciadeblas41012602018-04-23 17:23:35 +0200604 #install_docker_compose
garciadeblas14097dc2018-04-04 18:36:32 +0200605 generate_docker_images
garciadeblas46e99592018-04-16 13:32:02 +0200606 generate_docker_env_files
garciadeblas14097dc2018-04-04 18:36:32 +0200607 deploy_lightweight
garciadeblasb7d8d802018-04-18 16:39:17 +0200608 install_osmclient
609 return 0
garciadeblas14097dc2018-04-04 18:36:32 +0200610}
611
peusterm3a3e7a52017-12-22 13:10:54 +0100612function install_vimemu() {
613 # install Docker
614 install_docker_ce
615 # clone vim-emu repository (attention: branch is currently master only)
616 echo "Cloning vim-emu repository ..."
617 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git
618 # build vim-emu docker
619 echo "Building vim-emu Docker container..."
peusterme2c017e2018-02-07 11:51:11 +0100620 sudo docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
peusterm3a3e7a52017-12-22 13:10:54 +0100621 # start vim-emu container as daemon
622 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterme2c017e2018-02-07 11:51:11 +0100623 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 +0100624 echo "Waiting for 'vim-emu' container to start ..."
625 sleep 5
peusterme2c017e2018-02-07 11:51:11 +0100626 export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
garciadeblas46e99592018-04-16 13:32:02 +0200627 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peustermd74dc842018-01-24 15:32:17 +0100628 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
629 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
630 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
631 echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:"
peusterm3a3e7a52017-12-22 13:10:54 +0100632 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
633 echo -e "\nTo add the emulated VIM to OSM you should do:"
garciadeblas46e99592018-04-16 13:32:02 +0200634 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 +0100635}
636
garciadeblas0d934c12017-11-17 15:39:17 +0100637function dump_vars(){
638 echo "DEVELOP=$DEVELOP"
639 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
640 echo "UNINSTALL=$UNINSTALL"
641 echo "NAT=$NAT"
642 echo "UPDATE=$UPDATE"
643 echo "RECONFIGURE=$RECONFIGURE"
644 echo "TEST_INSTALLER=$TEST_INSTALLER"
peusterm3a3e7a52017-12-22 13:10:54 +0100645 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
garciadeblas0d934c12017-11-17 15:39:17 +0100646 echo "INSTALL_LXD=$INSTALL_LXD"
647 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
648 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
garciadeblasfc8f0292018-04-02 16:55:29 +0200649 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
garciadeblas14097dc2018-04-04 18:36:32 +0200650 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas0d934c12017-11-17 15:39:17 +0100651 echo "RELEASE=$RELEASE"
652 echo "REPOSITORY=$REPOSITORY"
653 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
654 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
655 echo "NOCONFIGURE=$NOCONFIGURE"
656 echo "SHOWOPTS=$SHOWOPTS"
657 echo "Install from specific refspec (-b): $COMMIT_ID"
658}
659
660function track(){
661 ctime=`date +%s`
662 duration=$((ctime - SESSION_ID))
663 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
664 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
665 event_name="bin"
666 [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src"
667 [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
668 event_name="${event_name}_$1"
669 url="${url}&event=${event_name}&ce_duration=${duration}"
670 wget -q -O /dev/null $url
671}
672
garciadeblas93c61312016-09-28 15:12:48 +0200673UNINSTALL=""
674DEVELOP=""
675NAT=""
garciadeblas2a382732017-01-12 12:11:14 +0100676UPDATE=""
garciadeblas55490d42016-10-29 14:22:03 +0200677RECONFIGURE=""
678TEST_INSTALLER=""
garciadeblas0d934c12017-11-17 15:39:17 +0100679INSTALL_LXD=""
garciadeblas2a5a6512016-12-19 10:19:52 +0100680SHOWOPTS=""
681COMMIT_ID=""
tierno2cc8e252017-03-08 17:12:05 +0100682ASSUME_YES=""
garciadeblasa1fc4572017-04-24 19:08:21 +0200683INSTALL_FROM_SOURCE=""
garciadeblas82442292017-11-16 14:48:12 +0100684RELEASE="-R ReleaseTHREE"
garciadeblasa9ef0992018-04-19 11:18:06 +0200685REPOSITORY="-r stable"
peusterm3a3e7a52017-12-22 13:10:54 +0100686INSTALL_VIMEMU=""
garciadeblas0d934c12017-11-17 15:39:17 +0100687INSTALL_FROM_LXDIMAGES=""
688LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
garciadeblasfc8f0292018-04-02 16:55:29 +0200689LXD_REPOSITORY_PATH=""
garciadeblas14097dc2018-04-04 18:36:32 +0200690INSTALL_LIGHTWEIGHT=""
garciadeblas0d934c12017-11-17 15:39:17 +0100691NOCONFIGURE=""
Mike Marchettica56c642017-12-16 16:04:52 -0500692RELEASE_DAILY=""
garciadeblas0d934c12017-11-17 15:39:17 +0100693SESSION_ID=`date +%s`
Mike Marchetti4de48492018-04-05 12:44:01 -0400694OSM_DEVOPS=
garciadeblas0d934c12017-11-17 15:39:17 +0100695
Mike Marchetti4de48492018-04-05 12:44:01 -0400696while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
garciadeblas93c61312016-09-28 15:12:48 +0200697 case "${o}" in
698 h)
699 usage && exit 0
700 ;;
garciadeblas2a5a6512016-12-19 10:19:52 +0100701 b)
702 COMMIT_ID=${OPTARG}
703 ;;
Mike Marchetti425f8ce2017-06-15 13:02:16 -0400704 r)
705 REPOSITORY="-r ${OPTARG}"
706 ;;
707 R)
708 RELEASE="-R ${OPTARG}"
709 ;;
710 k)
711 REPOSITORY_KEY="-k ${OPTARG}"
712 ;;
713 u)
714 REPOSITORY_BASE="-u ${OPTARG}"
715 ;;
garciadeblas0d934c12017-11-17 15:39:17 +0100716 l)
717 LXD_REPOSITORY_BASE="${OPTARG}"
718 ;;
garciadeblasfc8f0292018-04-02 16:55:29 +0200719 p)
720 LXD_REPOSITORY_PATH="${OPTARG}"
721 ;;
Mike Marchetti4de48492018-04-05 12:44:01 -0400722 D)
723 OSM_DEVOPS="${OPTARG}"
724 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200725 -)
726 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblasa1fc4572017-04-24 19:08:21 +0200727 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200728 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
729 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
730 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
garciadeblas2a382732017-01-12 12:11:14 +0100731 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
garciadeblas55490d42016-10-29 14:22:03 +0200732 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
733 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
garciadeblas0d934c12017-11-17 15:39:17 +0100734 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
735 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
garciadeblas14097dc2018-04-04 18:36:32 +0200736 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
peusterm3a3e7a52017-12-22 13:10:54 +0100737 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas0d934c12017-11-17 15:39:17 +0100738 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
garciadeblas2a5a6512016-12-19 10:19:52 +0100739 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
Mike Marchettica56c642017-12-16 16:04:52 -0500740 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200741 echo -e "Invalid option: '--$OPTARG'\n" >&2
742 usage && exit 1
743 ;;
744 \?)
745 echo -e "Invalid option: '-$OPTARG'\n" >&2
746 usage && exit 1
747 ;;
tierno2cc8e252017-03-08 17:12:05 +0100748 y)
749 ASSUME_YES="y"
750 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200751 *)
752 usage && exit 1
753 ;;
754 esac
755done
756
garciadeblasa6ff9862017-04-07 02:00:29 +0200757if [ -n "$SHOWOPTS" ]; then
garciadeblas0d934c12017-11-17 15:39:17 +0100758 dump_vars
garciadeblasa6ff9862017-04-07 02:00:29 +0200759 exit 0
760fi
761
Mike Marchettica56c642017-12-16 16:04:52 -0500762[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
763
Mike Marchetti6930bc02017-05-31 16:33:02 -0400764# if develop, we force master
garciadeblas2a5a6512016-12-19 10:19:52 +0100765[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
Mike Marchetti6930bc02017-05-31 16:33:02 -0400766
Mike Marchetti0d567602017-09-29 14:30:28 -0400767# forcing source from master removed. Now only install from source when explicit
768# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
garciadeblas2a5a6512016-12-19 10:19:52 +0100769
Mike Marchetti4de48492018-04-05 12:44:01 -0400770if [ -z "$OSM_DEVOPS" ]; then
771 if [ -n "$TEST_INSTALLER" ]; then
772 echo -e "\nUsing local devops repo for OSM installation"
773 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
774 else
775 echo -e "\nCreating temporary dir for OSM installation"
776 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
777 trap 'rm -rf "$TEMPDIR"' EXIT
778 fi
garciadeblas55490d42016-10-29 14:22:03 +0200779fi
garciadeblas93c61312016-09-28 15:12:48 +0200780
garciadeblas14097dc2018-04-04 18:36:32 +0200781need_packages="git jq wget curl tar"
782echo -e "Checking required packages: $need_packages"
783dpkg -l $need_packages &>/dev/null \
784 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
785 || sudo apt-get update \
786 || FATAL "failed to run apt-get update"
787dpkg -l $need_packages &>/dev/null \
788 || ! echo -e "Installing $need_packages requires root privileges." \
789 || sudo apt-get install -y $need_packages \
790 || FATAL "failed to install $need_packages"
Mike Marchetti2b951282017-10-10 15:43:15 -0400791
Mike Marchetti4de48492018-04-05 12:44:01 -0400792if [ -z "$OSM_DEVOPS" ]; then
793 if [ -z "$TEST_INSTALLER" ]; then
794 echo -e "\nCloning devops repo temporarily"
795 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
796 RC_CLONE=$?
797 fi
798
799 echo -e "\nGuessing the current stable release"
800 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
801 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
802 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
803 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
804
805 if [ -n "$RELEASE_DAILY" ]; then
806 echo "Using master/HEAD devops"
807 git -C $TEMPDIR checkout master
808 elif [ -z "$TEST_INSTALLER" ]; then
809 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
810 fi
811 OSM_DEVOPS=$TEMPDIR
garciadeblas55490d42016-10-29 14:22:03 +0200812fi
garciadeblas2a382732017-01-12 12:11:14 +0100813
Mike Marchetti4de48492018-04-05 12:44:01 -0400814OSM_JENKINS="$OSM_DEVOPS/jenkins"
garciadeblas0fe45dd2016-10-04 07:54:17 +0200815. $OSM_JENKINS/common/all_funcs
garciadeblas93c61312016-09-28 15:12:48 +0200816
garciadeblas831ee562018-04-30 10:02:21 +0200817[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
garciadeblasd8718f12016-10-30 19:39:01 +0100818[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
819[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
garciadeblas2a382732017-01-12 12:11:14 +0100820[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
garciadeblasd8718f12016-10-30 19:39:01 +0100821[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas93c61312016-09-28 15:12:48 +0200822
823#Installation starts here
garciadeblas14097dc2018-04-04 18:36:32 +0200824[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
garciadeblasa1fc4572017-04-24 19:08:21 +0200825echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
prithiv4a98a042017-12-05 23:19:39 +0000826if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
tierno53881d72017-04-25 11:58:57 +0200827 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
tierno2cc8e252017-03-08 17:12:05 +0100828fi
829
Jokin Garayc0a65962017-03-09 14:51:48 +0100830echo -e "Checking required packages: lxd"
garciadeblasd880f722017-04-07 20:14:57 +0200831lxd --version &>/dev/null || FATAL "lxd not present, exiting."
garciadeblas0d934c12017-11-17 15:39:17 +0100832[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
garciadeblas2a5a6512016-12-19 10:19:52 +0100833
Mike Marchetti02a533a2018-04-05 21:23:33 -0400834wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
garciadeblas0d934c12017-11-17 15:39:17 +0100835track start
garciadeblas93c61312016-09-28 15:12:48 +0200836
Mike Marchettid1e08b92017-09-29 16:14:11 -0400837# use local devops for containers
838export OSM_USE_LOCAL_DEVOPS=true
garciadeblas0d934c12017-11-17 15:39:17 +0100839if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
garciadeblasa1fc4572017-04-24 19:08:21 +0200840 echo -e "\nCreating the containers and building from source ..."
841 $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 +0100842 ro_is_up && track RO
garciadeblasa1fc4572017-04-24 19:08:21 +0200843 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
garciadeblas0d934c12017-11-17 15:39:17 +0100844 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000845 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
846 mon_is_up && track MON
garciadeblasa1fc4572017-04-24 19:08:21 +0200847 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
848 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
garciadeblas0d934c12017-11-17 15:39:17 +0100849 #so_is_up && track SOUI
850 track SOUI
851elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
852 echo -e "\nInstalling from lxd images ..."
853 install_from_lxdimages
854else #install from binaries
855 echo -e "\nCreating the containers and installing from binaries ..."
856 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
857 ro_is_up && track RO
858 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
859 vca_is_up && track VCA
prithiv4a98a042017-12-05 23:19:39 +0000860 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
861 mon_is_up && track MON
garciadeblas0d934c12017-11-17 15:39:17 +0100862 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
863 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
864 #so_is_up && track SOUI
865 track SOUI
garciadeblasa1fc4572017-04-24 19:08:21 +0200866fi
garciadeblas93c61312016-09-28 15:12:48 +0200867
garciadeblas55490d42016-10-29 14:22:03 +0200868#Install iptables-persistent and configure NAT rules
garciadeblas0d934c12017-11-17 15:39:17 +0100869[ -z "$NOCONFIGURE" ] && nat
garciadeblas93c61312016-09-28 15:12:48 +0200870
871#Configure components
garciadeblas0d934c12017-11-17 15:39:17 +0100872[ -z "$NOCONFIGURE" ] && configure
873
874#Install osmclient
875[ -z "$NOCONFIGURE" ] && install_osmclient
garciadeblas93c61312016-09-28 15:12:48 +0200876
peusterm3a3e7a52017-12-22 13:10:54 +0100877#Install vim-emu (optional)
878if [ -n "$INSTALL_VIMEMU" ]; then
879 echo -e "\nInstalling vim-emu ..."
880 install_vimemu
881fi
882
Mike Marchetti02a533a2018-04-05 21:23:33 -0400883wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
garciadeblas0d934c12017-11-17 15:39:17 +0100884track end
Jokin Garay3eb9ce72017-03-09 14:48:11 +0100885echo -e "\nDONE"
garciadeblas0d934c12017-11-17 15:39:17 +0100886