Improvement: Added help text for --vimemu flag.
[osm/devops.git] / installers / install_osm.sh
1 #!/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
16 function 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 " --vimemu: additionally fetch, build, and deploy the VIM emulator as a docker container"
34 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
35 # echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)"
36 echo -e " --nat: install only NAT rules"
37 echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules"
38 # echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch"
39 echo -e " --showopts: print chosen options and exit (only for debugging)"
40 echo -e " -y: do not prompt for confirmation, assumes yes"
41 echo -e " -h / --help: print this help"
42 }
43
44 #Uninstall OSM: remove containers
45 function uninstall(){
46 echo -e "\nUninstalling OSM"
47 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
48 $OSM_DEVOPS/jenkins/host/clean_container RO
49 $OSM_DEVOPS/jenkins/host/clean_container VCA
50 $OSM_DEVOPS/jenkins/host/clean_container SO
51 #$OSM_DEVOPS/jenkins/host/clean_container UI
52 else
53 lxc stop RO && lxc delete RO
54 lxc stop VCA && lxc delete VCA
55 lxc stop SO-ub && lxc delete SO-ub
56 fi
57 }
58
59 #Configure NAT rules, based on the current IP addresses of containers
60 function nat(){
61 echo -e "\nChecking required packages: iptables-persistent"
62 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
63 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
64 echo -e "\nConfiguring NAT rules"
65 echo -e " Required root privileges"
66 sudo $OSM_DEVOPS/installers/nat_osm
67 }
68
69 function FATAL(){
70 echo "FATAL error: Cannot install OSM due to \"$1\""
71 exit 1
72 }
73
74 #Update RO, SO and UI:
75 function update(){
76 echo -e "\nUpdating components"
77
78 echo -e " Updating RO"
79 CONTAINER="RO"
80 MDG="RO"
81 INSTALL_FOLDER="/opt/openmano"
82 echo -e " Fetching the repo"
83 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
84 BRANCH=""
85 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
86 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
87 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
88 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
89 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
90 # COMMIT_ID either was previously set with -b option, or is an empty string
91 CHECKOUT_ID=$COMMIT_ID
92 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
93 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
94 if [[ $CHECKOUT_ID == "tags/"* ]]; then
95 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
96 else
97 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
98 fi
99 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
100 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
101 echo " Nothing to be done."
102 else
103 echo " Update required."
104 lxc exec $CONTAINER -- service osm-ro stop
105 lxc exec $CONTAINER -- git -C /opt/openmano stash
106 lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
107 lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
108 lxc exec $CONTAINER -- git -C /opt/openmano stash pop
109 lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
110 lxc exec $CONTAINER -- service osm-ro start
111 fi
112 echo
113
114 echo -e " Updating SO and UI"
115 CONTAINER="SO-ub"
116 MDG="SO"
117 INSTALL_FOLDER="" # To be filled in
118 echo -e " Fetching the repo"
119 lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
120 BRANCH=""
121 BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
122 [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
123 CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
124 CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
125 echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
126 # COMMIT_ID either was previously set with -b option, or is an empty string
127 CHECKOUT_ID=$COMMIT_ID
128 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
129 [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
130 if [[ $CHECKOUT_ID == "tags/"* ]]; then
131 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
132 else
133 REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
134 fi
135 echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
136 if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
137 echo " Nothing to be done."
138 else
139 echo " Update required."
140 # Instructions to be added
141 # lxc exec SO-ub -- ...
142 fi
143 echo
144 }
145
146 function so_is_up() {
147 if [ -n "$1" ]; then
148 SO_IP=$1
149 else
150 SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
151 fi
152 time=0
153 step=5
154 timelength=300
155 while [ $time -le $timelength ]
156 do
157 if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
158 -H 'accept: application/vnd.yang.data+json' \
159 -H 'authorization: Basic YWRtaW46YWRtaW4=' \
160 -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 ]]
161 then
162 echo "RW.Restconf running....SO is up"
163 return 0
164 fi
165
166 sleep $step
167 echo -n "."
168 time=$((time+step))
169 done
170
171 FATAL "OSM Failed to startup. SO failed to startup"
172 }
173
174 function vca_is_up() {
175 if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
176 echo "VCA is up and running"
177 return 0
178 fi
179
180 FATAL "OSM Failed to startup. VCA failed to startup"
181 }
182
183 function ro_is_up() {
184 if [ -n "$1" ]; then
185 RO_IP=$1
186 else
187 RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
188 fi
189 time=0
190 step=2
191 timelength=20
192 while [ $time -le $timelength ]; do
193 if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
194 echo "RO is up and running"
195 return 0
196 fi
197 sleep $step
198 echo -n "."
199 time=$((time+step))
200 done
201
202 FATAL "OSM Failed to startup. RO failed to startup"
203 }
204
205
206 function configure_RO(){
207 . $OSM_DEVOPS/installers/export_ips
208 echo -e " Configuring RO"
209 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg
210 lxc exec RO -- service osm-ro restart
211
212 ro_is_up
213
214 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
215 lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
216 lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
217 #lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
218 }
219
220 function configure_VCA(){
221 echo -e " Configuring VCA"
222 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
223 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
224 }
225
226 function configure_SOUI(){
227 . $OSM_DEVOPS/installers/export_ips
228 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
229 RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'`
230
231 echo -e " Configuring SO"
232 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
233 sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
234 # make journaling persistent
235 lxc exec SO-ub -- mkdir -p /var/log/journal
236 lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal
237 lxc exec SO-ub -- systemctl restart systemd-journald
238
239 echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad
240
241 lxc exec SO-ub -- systemctl restart launchpad
242
243 so_is_up $SO_CONTAINER_IP
244
245 #delete existing config agent (could be there on reconfigure)
246 curl -k --request DELETE \
247 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \
248 --header 'accept: application/vnd.yang.data+json' \
249 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
250 --header 'cache-control: no-cache' \
251 --header 'content-type: application/vnd.yang.data+json' &> /dev/null
252
253 result=$(curl -k --request POST \
254 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
255 --header 'accept: application/vnd.yang.data+json' \
256 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
257 --header 'cache-control: no-cache' \
258 --header 'content-type: application/vnd.yang.data+json' \
259 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}')
260 [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result"
261
262 #R1/R2 config line
263 #result=$(curl -k --request PUT \
264 # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
265 # --header 'accept: application/vnd.yang.data+json' \
266 # --header 'authorization: Basic YWRtaW46YWRtaW4=' \
267 # --header 'cache-control: no-cache' \
268 # --header 'content-type: application/vnd.yang.data+json' \
269 # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }')
270
271 result=$(curl -k --request PUT \
272 --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \
273 --header 'accept: application/vnd.yang.data+json' \
274 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
275 --header 'cache-control: no-cache' \
276 --header 'content-type: application/vnd.yang.data+json' \
277 --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}')
278 [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result"
279
280 result=$(curl -k --request PATCH \
281 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \
282 --header 'accept: application/vnd.yang.data+json' \
283 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
284 --header 'cache-control: no-cache' \
285 --header 'content-type: application/vnd.yang.data+json' \
286 --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }')
287 [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result"
288
289 result=$(curl -k --request PATCH \
290 --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \
291 --header 'accept: application/vnd.yang.data+json' \
292 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
293 --header 'cache-control: no-cache' \
294 --header 'content-type: application/vnd.yang.data+json' \
295 --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }')
296 [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result"
297
298 lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
299 auto lo:1
300 iface lo:1 inet static
301 address $DEFAULT_IP
302 netmask 255.255.255.255
303 EOF
304 lxc exec SO-ub ifup lo:1
305 }
306
307 #Configure RO, VCA, and SO with the initial configuration:
308 # RO -> tenant:osm, logs to be sent to SO
309 # VCA -> juju-password
310 # SO -> route to Juju Controller, add RO account, add VCA account
311 function configure(){
312 #Configure components
313 echo -e "\nConfiguring components"
314 configure_RO
315 configure_VCA
316 configure_SOUI
317 }
318
319 function install_lxd() {
320 sudo apt-get update
321 sudo apt-get install -y lxd
322 newgrp lxd
323 lxd init --auto
324 lxd waitready
325 lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false
326 DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}')
327 DEFAULT_MTU=$( ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
328 lxc profile device set default eth0 mtu $DEFAULT_MTU
329 #sudo systemctl stop lxd-bridge
330 #sudo systemctl --system daemon-reload
331 #sudo systemctl enable lxd-bridge
332 #sudo systemctl start lxd-bridge
333 }
334
335 function ask_user(){
336 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
337 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
338 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
339 read -e -p "$1" USER_CONFIRMATION
340 while true ; do
341 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
342 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
343 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
344 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
345 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
346 done
347 }
348
349 function launch_container_from_lxd(){
350 export OSM_MDG=$1
351 OSM_load_config
352 export OSM_BASE_IMAGE=$2
353 if ! container_exists $OSM_BUILD_CONTAINER; then
354 CONTAINER_OPTS=""
355 [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true"
356 [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true"
357 create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS
358 wait_container_up $OSM_BUILD_CONTAINER
359 fi
360 }
361
362 function install_osmclient(){
363 CLIENT_RELEASE=${RELEASE#"-R "}
364 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
365 CLIENT_REPOSITORY="stable"
366 [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian"
367 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
368 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
369 curl $key_location | sudo apt-key add -
370 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient"
371 sudo apt-get update
372 sudo apt-get install -y python-osmclient
373 export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'`
374 export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'`
375 echo -e "\nOSM client installed"
376 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
377 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
378 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
379 }
380
381 function install_from_lxdimages(){
382 LXD_RELEASE=${RELEASE#"-R "}
383 LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")"
384 trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT
385 wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz
386 lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro
387 rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz
388 wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz
389 lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca
390 rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz
391 wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz
392 lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui
393 rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz
394 launch_container_from_lxd RO osm-ro
395 ro_is_up && track RO
396 launch_container_from_lxd VCA osm-vca
397 vca_is_up && track VCA
398 launch_container_from_lxd SO osm-soui
399 #so_is_up && track SOUI
400 track SOUI
401 }
402
403 function install_docker_ce() {
404 # installs and configures Docker CE
405 echo "Installing Docker CE ..."
406 sudo apt-get install apt-transport-https ca-certificates software-properties-common
407 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
408 sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
409 sudo apt-get -qq update
410 sudo apt-get install docker-ce
411 # user management
412 echo "Adding user to group 'docker'"
413 sudo groupadd docker
414 sudo usermod -aG docker $USER
415 echo "... Docker CE installation done"
416 }
417
418 function install_vimemu() {
419 # install Docker
420 install_docker_ce
421 # clone vim-emu repository (attention: branch is currently master only)
422 echo "Cloning vim-emu repository ..."
423 git clone https://osm.etsi.org/gerrit/osm/vim-emu.git
424 # build vim-emu docker
425 echo "Building vim-emu Docker container..."
426 docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/
427 # start vim-emu container as daemon
428 echo "Starting vim-emu Docker container 'vim-emu' ..."
429 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
430 echo "Waiting for 'vim-emu' container to start ..."
431 sleep 5
432 export VIMEMU_HOSTNAME=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
433 echo "vim-emu running at $VIMEMU_HOSTNAME ..."
434 echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:"
435 echo " export OSM_HOSTNAME=${OSM_HOSTNAME}"
436 echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}"
437 echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:"
438 echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}"
439 echo -e "\nTo add the emulated VIM to OSM you should do:"
440 echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://$VIMEMU_HOSTNAME:6001/v2.0 --tenant tenantName --account_type openstack"
441 }
442
443 function dump_vars(){
444 echo "DEVELOP=$DEVELOP"
445 echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE"
446 echo "UNINSTALL=$UNINSTALL"
447 echo "NAT=$NAT"
448 echo "UPDATE=$UPDATE"
449 echo "RECONFIGURE=$RECONFIGURE"
450 echo "TEST_INSTALLER=$TEST_INSTALLER"
451 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
452 echo "INSTALL_LXD=$INSTALL_LXD"
453 echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES"
454 echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE"
455 echo "RELEASE=$RELEASE"
456 echo "REPOSITORY=$REPOSITORY"
457 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
458 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
459 echo "NOCONFIGURE=$NOCONFIGURE"
460 echo "SHOWOPTS=$SHOWOPTS"
461 echo "Install from specific refspec (-b): $COMMIT_ID"
462 }
463
464 function track(){
465 ctime=`date +%s`
466 duration=$((ctime - SESSION_ID))
467 url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}"
468 #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}"
469 event_name="bin"
470 [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src"
471 [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd"
472 event_name="${event_name}_$1"
473 url="${url}&event=${event_name}&ce_duration=${duration}"
474 wget -q -O /dev/null $url
475 }
476
477 UNINSTALL=""
478 DEVELOP=""
479 NAT=""
480 UPDATE=""
481 RECONFIGURE=""
482 TEST_INSTALLER=""
483 INSTALL_LXD=""
484 SHOWOPTS=""
485 COMMIT_ID=""
486 ASSUME_YES=""
487 INSTALL_FROM_SOURCE=""
488 RELEASE="-R ReleaseTHREE"
489 INSTALL_VIMEMU=""
490 INSTALL_FROM_LXDIMAGES=""
491 LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
492 NOCONFIGURE=""
493 RELEASE_DAILY=""
494 SESSION_ID=`date +%s`
495
496 while getopts ":hy-:b:r:k:u:R:l:" o; do
497 case "${o}" in
498 h)
499 usage && exit 0
500 ;;
501 b)
502 COMMIT_ID=${OPTARG}
503 ;;
504 r)
505 REPOSITORY="-r ${OPTARG}"
506 ;;
507 R)
508 RELEASE="-R ${OPTARG}"
509 ;;
510 k)
511 REPOSITORY_KEY="-k ${OPTARG}"
512 ;;
513 u)
514 REPOSITORY_BASE="-u ${OPTARG}"
515 ;;
516 l)
517 LXD_REPOSITORY_BASE="${OPTARG}"
518 ;;
519 -)
520 [ "${OPTARG}" == "help" ] && usage && exit 0
521 [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
522 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
523 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
524 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
525 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
526 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
527 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
528 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
529 [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
530 [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue
531 [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue
532 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
533 [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue
534 echo -e "Invalid option: '--$OPTARG'\n" >&2
535 usage && exit 1
536 ;;
537 \?)
538 echo -e "Invalid option: '-$OPTARG'\n" >&2
539 usage && exit 1
540 ;;
541 y)
542 ASSUME_YES="y"
543 ;;
544 *)
545 usage && exit 1
546 ;;
547 esac
548 done
549
550 if [ -n "$SHOWOPTS" ]; then
551 dump_vars
552 exit 0
553 fi
554
555 [ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master"
556
557 # if develop, we force master
558 [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
559
560 # forcing source from master removed. Now only install from source when explicit
561 # [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
562
563 if [ -n "$TEST_INSTALLER" ]; then
564 echo -e "\nUsing local devops repo for OSM installation"
565 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
566 else
567 echo -e "\nCreating temporary dir for OSM installation"
568 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
569 trap 'rm -rf "$TEMPDIR"' EXIT
570 fi
571
572 need_packages="git jq"
573 for package in $need_packages; do
574 echo -e "Checking required packages: $package"
575 dpkg -l $package &>/dev/null \
576 || ! echo -e " $package not installed.\nInstalling $package requires root privileges" \
577 || sudo apt-get install -y $package \
578 || FATAL "failed to install $package"
579 done
580
581 if [ -z "$TEST_INSTALLER" ]; then
582 echo -e "\nCloning devops repo temporarily"
583 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
584 RC_CLONE=$?
585 fi
586
587 echo -e "\nGuessing the current stable release"
588 LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
589 [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
590 echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
591 [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
592
593 if [ -n "$RELEASE_DAILY" ]; then
594 echo "Using master/HEAD devops"
595 git -C $TEMPDIR checkout master
596 elif [ -z "$TEST_INSTALLER" ]; then
597 git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
598 fi
599
600 OSM_DEVOPS=$TEMPDIR
601 OSM_JENKINS="$TEMPDIR/jenkins"
602 . $OSM_JENKINS/common/all_funcs
603
604 [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
605 [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
606 [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0
607 [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
608
609 #Installation starts here
610 echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
611 if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
612 ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
613 fi
614
615 echo -e "\nChecking required packages: wget, curl, tar"
616 dpkg -l wget curl tar &>/dev/null || ! echo -e " One or several packages are not installed.\nInstalling required packages\n Root privileges are required" || sudo apt-get install -y wget curl tar
617
618 echo -e "Checking required packages: lxd"
619 lxd --version &>/dev/null || FATAL "lxd not present, exiting."
620 [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
621
622 wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README.txt &> /dev/null
623 track start
624
625 # use local devops for containers
626 export OSM_USE_LOCAL_DEVOPS=true
627 if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
628 echo -e "\nCreating the containers and building from source ..."
629 $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')"
630 ro_is_up && track RO
631 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
632 vca_is_up && track VCA
633 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
634 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
635 #so_is_up && track SOUI
636 track SOUI
637 elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo
638 echo -e "\nInstalling from lxd images ..."
639 install_from_lxdimages
640 else #install from binaries
641 echo -e "\nCreating the containers and installing from binaries ..."
642 $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed"
643 ro_is_up && track RO
644 $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
645 vca_is_up && track VCA
646 $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
647 $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
648 #so_is_up && track SOUI
649 track SOUI
650 fi
651
652 #Install iptables-persistent and configure NAT rules
653 [ -z "$NOCONFIGURE" ] && nat
654
655 #Configure components
656 [ -z "$NOCONFIGURE" ] && configure
657
658 #Install osmclient
659 [ -z "$NOCONFIGURE" ] && install_osmclient
660
661 #Install vim-emu (optional)
662 if [ -n "$INSTALL_VIMEMU" ]; then
663 echo -e "\nInstalling vim-emu ..."
664 install_vimemu
665 fi
666
667 wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README2.txt &> /dev/null
668 track end
669 echo -e "\nDONE"
670