blob: d9d1e7d7fd87b0a67fa231a98cb397b019c990e8 [file] [log] [blame]
garciadeblasd8bc5c32018-05-09 17:37:56 +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]"
18 echo -e "Install OSM from binaries or source code (by default, from binaries)"
19 echo -e " OPTIONS"
20 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"
22 echo -e " -r <repo>: use specified repository name for osm packages"
23 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
24 echo -e " -u <repo base>: use specified repository url for osm packages"
25 echo -e " -k <repo key>: use specified repository public key url"
26 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"
33 echo -e " -p <path>: use specified repository path for lxd images"
34 echo -e " --lightweight: install lightweight build of OSM (default installation)"
garciadeblas432bcb22018-05-10 13:33:23 +020035 echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)"
garciadeblas6c66abf2018-05-16 14:46:19 +020036 echo -e " --vimemu: additionally deploy the VIM emulator as a docker container"
37 echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging"
38 echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
39 echo -e " -o <ADDON>: do not install OSM, but ONLY one of the addons (vimemu, elk_stack, pm_stack) (assumes OSM is already installed)"
garciadeblasd8bc5c32018-05-09 17:37:56 +020040 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
41# echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
42 echo -e " --nat: install only NAT rules"
43 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
44# echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
45 echo -e " --showopts: print chosen options and exit (only for debugging)"
46 echo -e " -y: do not prompt for confirmation, assumes yes"
47 echo -e " -D <devops path> use local devops installation path"
48 echo -e " -h / --help: print this help"
49}
50
51#Uninstall OSM: remove containers
52function uninstall(){
53 echo -e "\nUninstalling OSM"
54 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
55 $OSM_DEVOPS/jenkins/host/clean_container RO
56 $OSM_DEVOPS/jenkins/host/clean_container VCA
57 $OSM_DEVOPS/jenkins/host/clean_container MON
58 $OSM_DEVOPS/jenkins/host/clean_container SO
59 #$OSM_DEVOPS/jenkins/host/clean_container UI
60 else
61 lxc stop RO && lxc delete RO
62 lxc stop VCA && lxc delete VCA
63 lxc stop MON && lxc delete MON
64 lxc stop SO-ub && lxc delete SO-ub
65 fi
66 echo -e "\nDeleting imported lxd images if they exist"
67 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
68 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
69 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
70 return 0
71}
72
73#Uninstall lightweight OSM: remove dockers
74function uninstall_lightweight(){
75 echo -e "\nUninstalling lightweight OSM"
76 docker stack rm osm
77 COUNTER=0
78 result=11
79 while [ ${COUNTER} -lt 30 ]; do
80 sleep 1
81 result=$(docker stack ps osm | wc -l)
82 #echo "Dockers running: $result"
83 if [ "${result}" == "0" ]; then
84 break
85 fi
86 let COUNTER=COUNTER+1
87 done
88 if [ "${result}" == "0" ]; then
89 echo "All dockers of the stack osm were removed"
90 else
91 FATAL "Some dockers of the stack osm could not be removed. Could not uninstall OSM in single shot. Try to uninstall again"
92 fi
93 sleep 5
94 docker image rm osm/ro
95 docker image rm osm/lcm
96 docker image rm osm/light-ui
97 docker image rm osm/nbi
98 docker image rm osm/mon
99 docker image rm osm/pm
100 return 0
101}
102
103#Configure NAT rules, based on the current IP addresses of containers
104function nat(){
105 echo -e "\nChecking required packages: iptables-persistent"
106 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
107 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
108 echo -e "\nConfiguring NAT rules"
109 echo -e " Required root privileges"
110 sudo $OSM_DEVOPS/installers/nat_osm
111}
112
113function FATAL(){
114 echo "FATAL error: Cannot install OSM due to \"$1\""
115 exit 1
116}
117
118#Update RO, SO and UI:
119function update(){
120 echo -e "\nUpdating components"
121
122 echo -e " Updating RO"
123 CONTAINER="RO"
124 MDG="RO"
125 INSTALL_FOLDER="/opt/openmano"
126 echo -e " Fetching the repo"
127 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
128 BRANCH=""
129 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
130 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
131 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
132 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
133 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
134 # COMMIT_ID either was previously set with -b option, or is an empty string
135 CHECKOUT_ID=$COMMIT_ID
136 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
137 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
138 if [[ $CHECKOUT_ID == "tags/"* ]]; then
139 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
140 else
141 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
142 fi
143 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
144 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
145 echo " Nothing to be done."
146 else
147 echo " Update required."
148 lxc exec $CONTAINER -- service osm-ro stop
149 lxc exec $CONTAINER -- git -C /opt/openmano stash
150 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
151 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
152 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
153 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
154 lxc exec $CONTAINER -- service osm-ro start
155 fi
156 echo
157
158 echo -e " Updating SO and UI"
159 CONTAINER="SO-ub"
160 MDG="SO"
161 INSTALL_FOLDER="" # To be filled in
162 echo -e " Fetching the repo"
163 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
164 BRANCH=""
165 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
166 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
167 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
168 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
169 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
170 # COMMIT_ID either was previously set with -b option, or is an empty string
171 CHECKOUT_ID=$COMMIT_ID
172 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
173 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
174 if [[ $CHECKOUT_ID == "tags/"* ]]; then
175 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
176 else
177 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
178 fi
179 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
180 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
181 echo " Nothing to be done."
182 else
183 echo " Update required."
184 # Instructions to be added
185 # lxc exec SO-ub -- ...
186 fi
187 echo
188 echo -e "Updating MON Container"
189 CONTAINER="MON"
190 MDG="MON"
191 INSTALL_FOLDER="/root/MON"
192 echo -e " Fetching the repo"
193 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
194 BRANCH=""
195 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
196 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
197 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
198 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
199 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
200 # COMMIT_ID either was previously set with -b option, or is an empty string
201 CHECKOUT_ID=$COMMIT_ID
202 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
203 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
204 if [[ $CHECKOUT_ID == "tags/"* ]]; then
205 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
206 else
207 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
208 fi
209 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
210 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
211 echo " Nothing to be done."
212 else
213 echo " Update required."
214 fi
215 echo
216}
217
218function so_is_up() {
219 if [ -n "$1" ]; then
220 SO_IP=$1
221 else
222 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
223 fi
224 time=0
225 step=5
226 timelength=300
227 while [ $time -le $timelength ]
228 do
229 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
230 -H 'accept: application/vnd.yang.data+json' \
231 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
232 -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 ]]
233 then
234 echo "RW.Restconf running....SO is up"
235 return 0
236 fi
237
238 sleep $step
239 echo -n "."
240 time=$((time+step))
241 done
242
243 FATAL "OSM Failed to startup. SO failed to startup"
244}
245
246function vca_is_up() {
247 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
248 echo "VCA is up and running"
249 return 0
250 fi
251
252 FATAL "OSM Failed to startup. VCA failed to startup"
253}
254
255function mon_is_up() {
256 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
257 echo "MON is up and running"
258 return 0
259 fi
260
261 FATAL "OSM Failed to startup. MON failed to startup"
262}
263
264function ro_is_up() {
265 if [ -n "$1" ]; then
266 RO_IP=$1
267 else
268 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
269 fi
270 time=0
271 step=2
272 timelength=20
273 while [ $time -le $timelength ]; do
274 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
275 echo "RO is up and running"
276 return 0
277 fi
278 sleep $step
279 echo -n "."
280 time=$((time+step))
281 done
282
283 FATAL "OSM Failed to startup. RO failed to startup"
284}
285
286
287function configure_RO(){
288 . $OSM_DEVOPS/installers/export_ips
289 echo -e " Configuring RO"
290 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
291 lxc exec RO -- service osm-ro restart
292
293 ro_is_up
294
295 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
296 lxc exec RO -- openmano tenant-create osm > /dev/null
297 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
298 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
299 lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
300}
301
302function configure_VCA(){
303 echo -e " Configuring VCA"
304 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
305 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
306}
307
308function configure_SOUI(){
309 . $OSM_DEVOPS/installers/export_ips
310 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
311 RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
312
313 echo -e " Configuring MON"
314 #Information to be added about SO socket for logging
315
316 echo -e " Configuring SO"
317 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblas818fa5a2018-05-10 13:39:10 +0200318 sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP
garciadeblasd8bc5c32018-05-09 17:37:56 +0200319 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
garciadeblas818fa5a2018-05-10 13:39:10 +0200320 sudo sed -i "$ i ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP" /etc/rc.local
garciadeblasd8bc5c32018-05-09 17:37:56 +0200321 # make journaling persistent
322 lxc exec SO-ub -- mkdir -p /var/log/journal
323 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
324 lxc exec SO-ub -- systemctl restart systemd-journald
325
326 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
327
328 lxc exec SO-ub -- systemctl restart launchpad
329
330 so_is_up $SO_CONTAINER_IP
331
332 #delete existing config agent (could be there on reconfigure)
333 curl -k --request DELETE \
334 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
335 --header 'accept: application/vnd.yang.data+json' \
336 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
337 --header 'cache-control: no-cache' \
338 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
339
340 result=$(curl -k --request POST \
341 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
342 --header 'accept: application/vnd.yang.data+json' \
343 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
344 --header 'cache-control: no-cache' \
345 --header 'content-type: application/vnd.yang.data+json' \
346 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
347 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
348
349 #R1/R2 config line
350 #result=$(curl -k --request PUT \
351 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
352 # --header 'accept: application/vnd.yang.data+json' \
353 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
354 # --header 'cache-control: no-cache' \
355 # --header 'content-type: application/vnd.yang.data+json' \
356 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
357
358 result=$(curl -k --request PUT \
359 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
360 --header 'accept: application/vnd.yang.data+json' \
361 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
362 --header 'cache-control: no-cache' \
363 --header 'content-type: application/vnd.yang.data+json' \
364 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
365 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
366
367 result=$(curl -k --request PATCH \
368 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
369 --header 'accept: application/vnd.yang.data+json' \
370 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
371 --header 'cache-control: no-cache' \
372 --header 'content-type: application/vnd.yang.data+json' \
373 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
374 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
375
376 result=$(curl -k --request PATCH \
377 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
378 --header 'accept: application/vnd.yang.data+json' \
379 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
380 --header 'cache-control: no-cache' \
381 --header 'content-type: application/vnd.yang.data+json' \
382 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
383 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
384
385 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
386auto lo:1
387iface lo:1 inet static
388 address $DEFAULT_IP
389 netmask 255.255.255.255
390EOF
391 lxc exec SO-ub ifup lo:1
392}
393
394#Configure RO, VCA, and SO with the initial configuration:
395# RO -> tenant:osm, logs to be sent to SO
396# VCA -> juju-password
397# SO -> route to Juju Controller, add RO account, add VCA account
398function configure(){
399 #Configure components
400 echo -e "\nConfiguring components"
401 configure_RO
402 configure_VCA
403 configure_SOUI
404}
405
406function install_lxd() {
407 sudo apt-get update
408 sudo apt-get install -y lxd
409 newgrp lxd
410 lxd init --auto
411 lxd waitready
412 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
413 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
414 DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
415 lxc profile device set default eth0 mtu $DEFAULT_MTU
416 #sudo systemctl stop lxd-bridge
417 #sudo systemctl --system daemon-reload
418 #sudo systemctl enable lxd-bridge
419 #sudo systemctl start lxd-bridge
420}
421
422function ask_user(){
423 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
424 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
425 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
426 read -e -p "$1" USER_CONFIRMATION
427 while true ; do
428 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
429 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
430 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
431 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
432 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
433 done
434}
435
436function launch_container_from_lxd(){
437 export OSM_MDG=$1
438 OSM_load_config
439 export OSM_BASE_IMAGE=$2
440 if ! container_exists $OSM_BUILD_CONTAINER; then
441 CONTAINER_OPTS=""
442 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
443 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
444 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
445 wait_container_up $OSM_BUILD_CONTAINER
446 fi
447}
448
449function install_osmclient(){
450 CLIENT_RELEASE=${RELEASE#"-R "}
451 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
452 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
453 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
454 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
455 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
456 curl $key_location | sudo apt-key add -
457 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
458 sudo apt-get update
459 sudo apt-get install -y python-pip
460 sudo -H pip install pip==9.0.3
461 sudo -H pip install python-magic
462 sudo apt-get install -y python-osmclient
463 #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc
464 #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc
465 #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc
466 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
467 [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
garciadeblas8e6bc152018-05-14 11:36:11 +0200468 [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1
garciadeblasd8bc5c32018-05-09 17:37:56 +0200469 echo -e "\nOSM client installed"
470 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
471 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
472 [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True"
473 [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
474 return 0
475}
476
477function install_from_lxdimages(){
478 LXD_RELEASE=${RELEASE#"-R "}
479 if [ -n "$LXD_REPOSITORY_PATH" ]; then
480 LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH"
481 else
482 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
483 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
484 fi
485 echo -e "\nDeleting previous lxd images if they exist"
486 lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
487 lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
488 lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
489 echo -e "\nImporting osm-ro"
490 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
491 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
492 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
493 echo -e "\nImporting osm-vca"
494 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
495 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
496 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
497 echo -e "\nImporting osm-soui"
498 [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
499 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
500 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
501 launch_container_from_lxd RO osm-ro
502 ro_is_up && track RO
503 launch_container_from_lxd VCA osm-vca
504 vca_is_up && track VCA
505 launch_container_from_lxd MON osm-mon
506 mon_is_up && track MON
507 launch_container_from_lxd SO osm-soui
508 #so_is_up && track SOUI
509 track SOUI
510}
511
512function install_docker_ce() {
513 # installs and configures Docker CE
514 echo "Installing Docker CE ..."
515 sudo apt-get -qq update
516 sudo apt-get install -y apt-transport-https ca-certificates software-properties-common
517 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
518 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
519 sudo apt-get -qq update
520 sudo apt-get install -y docker-ce
521 echo "Adding user to group 'docker'"
522 sudo groupadd -f docker
523 sudo usermod -aG docker $USER
garciadeblasd8bc5c32018-05-09 17:37:56 +0200524 sleep 2
525 sudo service docker restart
526 echo "... restarted Docker service"
garciadeblas67ce97c2018-05-18 10:22:09 +0200527 sg docker -c "docker version" || FATAL "Docker installation failed"
528 echo "... Docker CE installation done"
529 return 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200530}
531
532function install_docker_compose() {
533 # installs and configures docker-compose
534 echo "Installing Docker Compose ..."
535 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
536 sudo chmod +x /usr/local/bin/docker-compose
537 echo "... Docker Compose installation done"
538}
539
540function install_juju() {
541 echo "Installing juju"
542 sudo snap install juju --classic
543 sudo dpkg-reconfigure -p medium lxd
garciadeblasa235be82018-05-18 15:37:28 +0200544 sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost osm"
garciadeblas67ce97c2018-05-18 10:22:09 +0200545 [ $(juju status |grep "osm" |wc -l) -eq 1 ] || FATAL "Juju installation failed"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200546 echo "Finished installation of juju"
547}
548
549function generate_docker_images() {
550 echo "Pulling and generating docker images"
551 newgrp docker << EONG
552 docker pull wurstmeister/kafka
553 docker pull wurstmeister/zookeeper
554 docker pull mongo
555 docker pull mysql:5
556 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON
557 docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon || ! echo "cannot build MON docker image" >&2
558 docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm || ! echo "cannot build PM docker image" >&2
559 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI
560 docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2
561 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO
562 docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2
tierno940a34c2018-05-11 12:27:10 +0200563 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM
564 docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm || ! echo "cannot build LCM docker image" >&2
garciadeblas41f38972018-05-10 08:43:00 +0200565# git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git
566# docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile
567 git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI
568 docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile
garciadeblasd8bc5c32018-05-09 17:37:56 +0200569EONG
570 echo "Finished generation of docker images"
571}
572
573function generate_docker_env_files() {
574 echo "Generating docker env files"
575 OSMLCM_VCA_HOST=`juju show-controller|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
576 OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
577 MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32`
578 echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee ${OSM_DEVOPS}/installers/docker/lcm.env
579 echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a ${OSM_DEVOPS}/installers/docker/lcm.env
580 echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro-db.env
581 echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro.env
582 echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env
583 echo "Finished generation of docker env files"
584}
585
586function deploy_lightweight() {
587 echo "Deploying lightweight build"
588 if [ "${DEFAULT_MTU}" != "1500" ]; then
589 DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
590 DOCKER_GW_NET=`sg docker -c "docker network inspect ${DOCKER_NETS}" | grep Subnet | awk -F\" '{print $4}' | egrep "^172" | sort -u | tail -1 | awk -F\. '{if ($2 != 255) print $1"."$2+1"."$3"."$4; else print "-1";}'`
591 sg docker -c "docker network create --subnet ${DOCKER_GW_NET} --opt com.docker.network.bridge.name=docker_gwbridge --opt com.docker.network.bridge.enable_icc=false --opt com.docker.network.bridge.enable_ip_masquerade=true --opt com.docker.network.driver.mtu=${DEFAULT_MTU} docker_gwbridge"
592 fi
593 newgrp docker << EONG
594 docker swarm init --advertise-addr ${DEFAULT_IP}
595 docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM
596 docker stack deploy -c ${OSM_DEVOPS}/installers/docker/docker-compose.yaml osm
597 #docker-compose -f /usr/share/osm-devops/installers/docker/docker-compose.yaml up -d
598EONG
599 echo "Finished deployment of lightweight build"
600}
601
garciadeblas6c66abf2018-05-16 14:46:19 +0200602function deploy_elk() {
603 echo "Deploying ELK stack"
604 sg docker -c "docker stack deploy -c ${OSM_DEVOPS}/installers/docker/osm_elk/docker-compose.yml osm_elk"
605 echo "Waiting for ELK stack to be up and running"
606 time=0
607 step=2
608 timelength=20
609 elk_is_up=1
610 while [ $time -le $timelength ]; do
611 if [[ $(curl -XGET http://localhost:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
612 elk_is_up=0
613 break
614 fi
615 sleep $step
616 time=$((time+step))
617 done
618 if [ $elk_is_up -eq 0 ]; then
619 echo "ELK is up and running. Trying to create index pattern..."
620 #Create index pattern
621 curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
622 "http://localhost:5601/api/saved_objects/index-pattern/logstash-*" \
623 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"
624 #Make it the default index
625 curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
626 "http://localhost:5601/api/kibana/settings/defaultIndex" \
627 -d"{\"value\":\"logstash-*\"}"
628 else
629 echo "Cannot connect to Kibana to create index pattern."
630 echo "Once Kibana is running, you can use the following instructions to create index pattern:"
631 echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
632 "http://localhost:5601/api/saved_objects/index-pattern/logstash-*" \
633 -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
634 echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
635 "http://localhost:5601/api/kibana/settings/defaultIndex" \
636 -d"{\"value\":\"logstash-*\"}"'
637 fi
638 echo "Finished deployment of ELK stack"
639 return 0
640}
641
642function deploy_perfmon() {
643 echo "Generating osm/kafka-exporter docker image"
644 sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter || ! echo 'cannot build kafka-exporter docker image' >&2"
645 echo "Finished generation of osm/kafka-exporter docker image"
646 echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
647 sg docker -c "docker stack deploy -c ${OSM_DEVOPS}/installers/docker/osm_metrics/docker-compose.yml osm_metrics"
648 echo "Finished deployment of PM stack"
649 return 0
650}
651
garciadeblasd8bc5c32018-05-09 17:37:56 +0200652function install_lightweight() {
garciadeblasd13a8aa2018-05-18 15:24:51 +0200653 [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
garciadeblasd8bc5c32018-05-09 17:37:56 +0200654 echo "Installing lightweight build of OSM"
655 LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
656 trap 'rm -rf "${LWTEMPDIR}"' EXIT
657 DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
658 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
659 DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
660 need_packages_lw="lxd"
661 echo -e "Checking required packages: $need_packages_lw"
662 dpkg -l $need_packages_lw &>/dev/null \
663 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
664 || sudo apt-get update \
665 || FATAL "failed to run apt-get update"
666 dpkg -l $need_packages_lw &>/dev/null \
667 || ! echo -e "Installing $need_packages_lw requires root privileges." \
668 || sudo apt-get install -y $need_packages_lw \
669 || FATAL "failed to install $need_packages_lw"
670 install_juju
garciadeblas6c66abf2018-05-16 14:46:19 +0200671 track juju
garciadeblasd8bc5c32018-05-09 17:37:56 +0200672 install_docker_ce
garciadeblas6c66abf2018-05-16 14:46:19 +0200673 track docker_ce
garciadeblasd8bc5c32018-05-09 17:37:56 +0200674 #install_docker_compose
675 generate_docker_images
garciadeblas6c66abf2018-05-16 14:46:19 +0200676 track docker_build
garciadeblasd8bc5c32018-05-09 17:37:56 +0200677 generate_docker_env_files
678 deploy_lightweight
garciadeblas6c66abf2018-05-16 14:46:19 +0200679 track docker_deploy
680 [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu
681 [ -n "$INSTALL_ELK" ] && deploy_elk && track elk
682 [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon
garciadeblasd8bc5c32018-05-09 17:37:56 +0200683 install_osmclient
garciadeblas6c66abf2018-05-16 14:46:19 +0200684 track osmclient
685 wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
686 track end
garciadeblasd8bc5c32018-05-09 17:37:56 +0200687 return 0
688}
689
690function install_vimemu() {
peusterm76353e42018-05-08 13:56:05 +0200691 echo "\nInstalling vim-emu"
692 EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")"
693 trap 'rm -rf "${EMUTEMPDIR}"' EXIT
garciadeblasd8bc5c32018-05-09 17:37:56 +0200694 # clone vim-emu repository (attention: branch is currently master only)
695 echo "Cloning vim-emu repository ..."
peusterm76353e42018-05-08 13:56:05 +0200696 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR
garciadeblasd8bc5c32018-05-09 17:37:56 +0200697 # build vim-emu docker
698 echo "Building vim-emu Docker container..."
peusterm76353e42018-05-08 13:56:05 +0200699 sudo docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile $EMUTEMPDIR/
garciadeblasd8bc5c32018-05-09 17:37:56 +0200700 # start vim-emu container as daemon
701 echo "Starting vim-emu Docker container 'vim-emu' ..."
peusterm76353e42018-05-08 13:56:05 +0200702 if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
703 # in lightweight mode, the emulator needs to be attached to netOSM
704 sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
705 else
706 # classic build mode
707 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
708 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200709 echo "Waiting for 'vim-emu' container to start ..."
710 sleep 5
711 export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
712 echo "vim-emu running at ${VIMEMU_HOSTNAME} ..."
peusterm76353e42018-05-08 13:56:05 +0200713 # print vim-emu connection info
714 echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200715 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
peusterm76353e42018-05-08 13:56:05 +0200716 echo -e "To add the emulated VIM to OSM you should do:"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200717 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack"
718}
719
720function dump_vars(){
721 echo "DEVELOP=$DEVELOP"
722 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
723 echo "UNINSTALL=$UNINSTALL"
724 echo "NAT=$NAT"
725 echo "UPDATE=$UPDATE"
726 echo "RECONFIGURE=$RECONFIGURE"
727 echo "TEST_INSTALLER=$TEST_INSTALLER"
728 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
729 echo "INSTALL_LXD=$INSTALL_LXD"
730 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
731 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
732 echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH"
733 echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT"
garciadeblas6c66abf2018-05-16 14:46:19 +0200734 echo "INSTALL_ONLY=$INSTALL_ONLY"
735 echo "INSTALL_ELK=$INSTALL_ELK"
736 echo "INSTALL_PERFMON=$INSTALL_PERFMON"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200737 echo "RELEASE=$RELEASE"
738 echo "REPOSITORY=$REPOSITORY"
739 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
740 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
741 echo "NOCONFIGURE=$NOCONFIGURE"
742 echo "SHOWOPTS=$SHOWOPTS"
743 echo "Install from specific refspec (-b): $COMMIT_ID"
744}
745
746function track(){
747 ctime=`date +%s`
748 duration=$((ctime - SESSION_ID))
749 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
750 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
751 event_name="bin"
garciadeblas6c66abf2018-05-16 14:46:19 +0200752 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc"
753 [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
754 [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200755 event_name="${event_name}_$1"
756 url="${url}&event=${event_name}&ce_duration=${duration}"
757 wget -q -O /dev/null $url
758}
759
760UNINSTALL=""
761DEVELOP=""
762NAT=""
763UPDATE=""
764RECONFIGURE=""
765TEST_INSTALLER=""
766INSTALL_LXD=""
767SHOWOPTS=""
768COMMIT_ID=""
769ASSUME_YES=""
770INSTALL_FROM_SOURCE=""
771RELEASE="-R ReleaseTHREE"
772REPOSITORY="-r stable"
773INSTALL_VIMEMU=""
774INSTALL_FROM_LXDIMAGES=""
775LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
776LXD_REPOSITORY_PATH=""
777INSTALL_LIGHTWEIGHT="y"
garciadeblas6c66abf2018-05-16 14:46:19 +0200778INSTALL_ONLY=""
779INSTALL_ELK=""
780INSTALL_PERFMON=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200781NOCONFIGURE=""
782RELEASE_DAILY=""
783SESSION_ID=`date +%s`
784OSM_DEVOPS=
785
garciadeblas6c66abf2018-05-16 14:46:19 +0200786while getopts ":hy-:b:r:k:u:R:l:p:D:o:" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +0200787 case "${o}" in
788 h)
789 usage && exit 0
790 ;;
791 b)
792 COMMIT_ID=${OPTARG}
793 ;;
794 r)
795 REPOSITORY="-r ${OPTARG}"
796 ;;
797 R)
798 RELEASE="-R ${OPTARG}"
799 ;;
800 k)
801 REPOSITORY_KEY="-k ${OPTARG}"
802 ;;
803 u)
804 REPOSITORY_BASE="-u ${OPTARG}"
805 ;;
806 l)
807 LXD_REPOSITORY_BASE="${OPTARG}"
808 ;;
809 p)
810 LXD_REPOSITORY_PATH="${OPTARG}"
811 ;;
812 D)
813 OSM_DEVOPS="${OPTARG}"
814 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +0200815 o)
816 INSTALL_ONLY="y"
817 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
818 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
819 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
820 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200821 -)
822 [ "${OPTARG}" == "help" ] && usage && exit 0
823 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
824 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
825 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
826 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
827 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
828 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
829 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
830 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
831 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
832 [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
garciadeblasef091862018-05-14 16:37:04 +0200833 [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE-Classic" && REPOSITORY="-r testing" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200834 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +0200835 [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue
836 [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200837 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
838 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
839 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
840 echo -e "Invalid option: '--$OPTARG'\n" >&2
841 usage && exit 1
842 ;;
843 \?)
844 echo -e "Invalid option: '-$OPTARG'\n" >&2
845 usage && exit 1
846 ;;
847 y)
848 ASSUME_YES="y"
849 ;;
850 *)
851 usage && exit 1
852 ;;
853 esac
854done
855
garciadeblas6c66abf2018-05-16 14:46:19 +0200856[ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui"
857
garciadeblasd8bc5c32018-05-09 17:37:56 +0200858if [ -n "$SHOWOPTS" ]; then
859 dump_vars
860 exit 0
861fi
862
863[ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
864
865# if develop, we force master
866[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
867
868# forcing source from master removed. Now only install from source when explicit
869# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
870
871if [ -z "$OSM_DEVOPS" ]; then
872 if [ -n "$TEST_INSTALLER" ]; then
873 echo -e "\nUsing local devops repo for OSM installation"
874 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
875 else
876 echo -e "\nCreating temporary dir for OSM installation"
877 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
878 trap 'rm -rf "$TEMPDIR"' EXIT
879 fi
880fi
881
882need_packages="git jq wget curl tar"
883echo -e "Checking required packages: $need_packages"
884dpkg -l $need_packages &>/dev/null \
885 || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \
886 || sudo apt-get update \
887 || FATAL "failed to run apt-get update"
888dpkg -l $need_packages &>/dev/null \
889 || ! echo -e "Installing $need_packages requires root privileges." \
890 || sudo apt-get install -y $need_packages \
891 || FATAL "failed to install $need_packages"
892
893if [ -z "$OSM_DEVOPS" ]; then
894 if [ -z "$TEST_INSTALLER" ]; then
895 echo -e "\nCloning devops repo temporarily"
896 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
897 RC_CLONE=$?
898 fi
899
900 echo -e "\nGuessing the current stable release"
901 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
902 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
903 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
904 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
905
906 if [ -n "$RELEASE_DAILY" ]; then
907 echo "Using master/HEAD devops"
908 git -C $TEMPDIR checkout master
909 elif [ -z "$TEST_INSTALLER" ]; then
910 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
911 fi
912 OSM_DEVOPS=$TEMPDIR
913fi
914
915OSM_JENKINS="$OSM_DEVOPS/jenkins"
916. $OSM_JENKINS/common/all_funcs
917
918[ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0
919[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
920[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
921[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
922[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas6c66abf2018-05-16 14:46:19 +0200923[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk
924[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon
925[ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu
926[ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0
garciadeblasd8bc5c32018-05-09 17:37:56 +0200927
928#Installation starts here
garciadeblas6c66abf2018-05-16 14:46:19 +0200929wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
930track start
931
garciadeblasd8bc5c32018-05-09 17:37:56 +0200932[ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0
933echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
934if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
935 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
936fi
937
938echo -e "Checking required packages: lxd"
939lxd --version &>/dev/null || FATAL "lxd not present, exiting."
940[ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
941
garciadeblasd8bc5c32018-05-09 17:37:56 +0200942# use local devops for containers
943export OSM_USE_LOCAL_DEVOPS=true
944if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
945 echo -e "\nCreating the containers and building from source ..."
946 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
947 ro_is_up && track RO
948 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
949 vca_is_up && track VCA
950 $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
951 mon_is_up && track MON
952 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
953 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
954 #so_is_up && track SOUI
955 track SOUI
956elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
957 echo -e "\nInstalling from lxd images ..."
958 install_from_lxdimages
959else #install from binaries
960 echo -e "\nCreating the containers and installing from binaries ..."
961 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
962 ro_is_up && track RO
963 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
964 vca_is_up && track VCA
965 $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
966 mon_is_up && track MON
967 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
968 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
969 #so_is_up && track SOUI
970 track SOUI
971fi
972
973#Install iptables-persistent and configure NAT rules
974[ -z "$NOCONFIGURE" ] && nat
975
976#Configure components
977[ -z "$NOCONFIGURE" ] && configure
978
979#Install osmclient
980[ -z "$NOCONFIGURE" ] && install_osmclient
981
982#Install vim-emu (optional)
peusterm76353e42018-05-08 13:56:05 +0200983[ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu
garciadeblasd8bc5c32018-05-09 17:37:56 +0200984
985wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
986track end
987echo -e "\nDONE"
988