blob: 1a7ad07e4a851691587a07e038c8efde2343ec83 [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]"
18 echo -e "Install OSM from source code"
19 echo -e " OPTIONS"
20 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
garciadeblas2a5a6512016-12-19 10:19:52 +010021 echo -e " -b <branch>: install OSM from source code using a specific branch (master, v1.0, ...)"
22 echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
garciadeblas93c61312016-09-28 15:12:48 +020023 echo -e " --nat: install only NAT rules"
24 echo -e " -h / --help: print this help"
25}
26
garciadeblas55490d42016-10-29 14:22:03 +020027#Uninstall OSM: remove containers
28function uninstall(){
29 if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
30 $OSM_DEVOPS/jenkins/host/clean_container RO
31 $OSM_DEVOPS/jenkins/host/clean_container VCA
32 $OSM_DEVOPS/jenkins/host/clean_container SO
33 #$OSM_DEVOPS/jenkins/host/clean_container UI
34 else
35 lxc stop RO && lxc delete RO
36 lxc stop VCA && lxc delete VCA
37 lxc stop SO-ub && lxc delete SO-ub
38 fi
39}
40
41#Configure NAT rules, based on the current IP addresses of containers
42function nat(){
43 echo -e "\nChecking required packages: iptables-persistent"
44 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
45 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
46 echo -e "\nConfiguring NAT rules"
47 echo -e " Required root privileges"
48 sudo $OSM_DEVOPS/installers/nat_osm
49}
50
51#Configure VCA, SO and RO with the initial configuration:
52# RO -> tenant:osm, logs to be sent to SO
53# VCA -> juju-password
54# SO -> route to Juju Controller, add RO account, add VCA account
55function configure(){
56 #Configure components
57 echo -e "\nConfiguring components"
58 . $OSM_DEVOPS/installers/export_ips
59
60 echo -e " Configuring RO"
61 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg
62 lxc exec RO -- service openmano restart
garciadeblasd8718f12016-10-30 19:39:01 +010063 time=0; step=2; timelength=20; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo
64 lxc exec RO -- openmano tenant-delete -f osm >/dev/null
garciadeblas55490d42016-10-29 14:22:03 +020065 RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'`
66
67 echo -e " Configuring VCA"
68 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
69 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
70 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
71
72 echo -e " Configuring SO"
73 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblasd05ae752016-12-07 12:13:00 +010074 lxc exec SO-ub -- nohup sudo -b -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode &
garciadeblasd8718f12016-10-30 19:39:01 +010075 time=0; step=30; timelength=300; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo
garciadeblas55490d42016-10-29 14:22:03 +020076
77 curl -k --request POST \
78 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
79 --header 'accept: application/vnd.yang.data+json' \
80 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
81 --header 'cache-control: no-cache' \
82 --header 'content-type: application/vnd.yang.data+json' \
83 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}'
84
85 curl -k --request PUT \
86 --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
87 --header 'accept: application/vnd.yang.data+json' \
88 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
89 --header 'cache-control: no-cache' \
90 --header 'content-type: application/vnd.yang.data+json' \
91 --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }'
92
93}
94
garciadeblas2a5a6512016-12-19 10:19:52 +010095function install_lxd() {
96 lxd init --auto
97 lxd waitready
98 systemctl stop lxd-bridge
99 systemctl --system daemon-reload
100 systemctl enable lxd-bridge
101 systemctl start lxd-bridge
102}
103
104
garciadeblas93c61312016-09-28 15:12:48 +0200105UNINSTALL=""
106DEVELOP=""
107NAT=""
garciadeblas55490d42016-10-29 14:22:03 +0200108RECONFIGURE=""
109TEST_INSTALLER=""
garciadeblas2a5a6512016-12-19 10:19:52 +0100110LXD=""
111SHOWOPTS=""
112COMMIT_ID=""
113while getopts ":h-:b:" o; do
garciadeblas93c61312016-09-28 15:12:48 +0200114 case "${o}" in
115 h)
116 usage && exit 0
117 ;;
garciadeblas2a5a6512016-12-19 10:19:52 +0100118 b)
119 COMMIT_ID=${OPTARG}
120 ;;
garciadeblas93c61312016-09-28 15:12:48 +0200121 -)
122 [ "${OPTARG}" == "help" ] && usage && exit 0
123 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
124 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
125 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
garciadeblas55490d42016-10-29 14:22:03 +0200126 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
127 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
garciadeblas2a5a6512016-12-19 10:19:52 +0100128 [ "${OPTARG}" == "lxd" ] && LXD="y" && continue
129 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
garciadeblas93c61312016-09-28 15:12:48 +0200130 echo -e "Invalid option: '--$OPTARG'\n" >&2
131 usage && exit 1
132 ;;
133 \?)
134 echo -e "Invalid option: '-$OPTARG'\n" >&2
135 usage && exit 1
136 ;;
137 *)
138 usage && exit 1
139 ;;
140 esac
141done
142
garciadeblas2a5a6512016-12-19 10:19:52 +0100143[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
garciadeblas14640f02017-01-04 13:40:55 +0100144[ -z "$COMMIT_ID" ] && COMMIT_ID="tags/v1.0.3"
garciadeblas2a5a6512016-12-19 10:19:52 +0100145
146if [ -n "$SHOWOPTS" ]; then
147 echo "UNINSTALL=$UNINSTALL"
148 echo "DEVELOP=$DEVELOP"
149 echo "NAT=$NAT"
150 echo "RECONFIGURE=$RECONFIGURE"
151 echo "TEST_INSTALLER=$TEST_INSTALLER"
152 echo "LXD=$LXD"
153 echo "Commit: $COMMIT_ID"
154 exit 0
155fi
156
garciadeblas55490d42016-10-29 14:22:03 +0200157if [ -n "$TEST_INSTALLER" ]; then
158 echo -e "\nUsing local devops repo for OSM installation"
159 TEMPDIR="$(dirname $(realpath $(dirname $0)))"
160else
161 echo -e "\nCreating temporary dir for OSM installation"
162 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
163 trap 'rm -rf "$TEMPDIR"' EXIT
164fi
garciadeblas93c61312016-09-28 15:12:48 +0200165
garciadeblas95f164e2016-10-19 13:00:54 +0200166echo -e "Checking required packages: git"
167dpkg -l git &>/dev/null || ! echo -e " git not installed.\nInstalling git requires root privileges" || sudo apt install -y git
garciadeblas55490d42016-10-29 14:22:03 +0200168if [ -z "$TEST_INSTALLER" ]; then
169 echo -e "\nCloning devops repo temporarily"
170 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
171 RC_CLONE=$?
garciadeblas14640f02017-01-04 13:40:55 +0100172 DEVOPS_COMMITID="tags/v1.0.3"
garciadeblas55490d42016-10-29 14:22:03 +0200173 git -C $TEMPDIR checkout $DEVOPS_COMMITID
174fi
garciadeblas93c61312016-09-28 15:12:48 +0200175OSM_DEVOPS=$TEMPDIR
garciadeblas0fe45dd2016-10-04 07:54:17 +0200176OSM_JENKINS="$TEMPDIR/jenkins"
177. $OSM_JENKINS/common/all_funcs
garciadeblas93c61312016-09-28 15:12:48 +0200178
garciadeblasd8718f12016-10-30 19:39:01 +0100179[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
180[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0
181[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0
garciadeblas93c61312016-09-28 15:12:48 +0200182
183#Installation starts here
garciadeblas0fe45dd2016-10-04 07:54:17 +0200184wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null
185
garciadeblas2a5a6512016-12-19 10:19:52 +0100186[ -n "$LXD" ] && echo -e "\nConfiguring lxd" && install_lxd
187
garciadeblas95f164e2016-10-19 13:00:54 +0200188echo -e "\nChecking required packages: wget, curl, tar"
189dpkg -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 install -y wget curl tar
garciadeblas93c61312016-09-28 15:12:48 +0200190
191echo -e "\nCreating the containers and building ..."
garciadeblas0fe45dd2016-10-04 07:54:17 +0200192$OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID
garciadeblas93c61312016-09-28 15:12:48 +0200193$OSM_DEVOPS/jenkins/host/start_build VCA
garciadeblas0fe45dd2016-10-04 07:54:17 +0200194$OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID
195$OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID
garciadeblas93c61312016-09-28 15:12:48 +0200196
garciadeblas55490d42016-10-29 14:22:03 +0200197#Install iptables-persistent and configure NAT rules
198nat
garciadeblas93c61312016-09-28 15:12:48 +0200199
200#Configure components
garciadeblas55490d42016-10-29 14:22:03 +0200201configure
garciadeblas93c61312016-09-28 15:12:48 +0200202
garciadeblas0fe45dd2016-10-04 07:54:17 +0200203echo -e "\nDONE"
garciadeblas93c61312016-09-28 15:12:48 +0200204
205