blob: 3a1c959e9a538c63f0941a963448a8a5f5d334d6 [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"
21 echo -e " --develop: install OSM from source code using the master branch"
22 echo -e " --nat: install only NAT rules"
23 echo -e " -h / --help: print this help"
24}
25
26UNINSTALL=""
27DEVELOP=""
28NAT=""
29while getopts ":h-:" o; do
30 case "${o}" in
31 h)
32 usage && exit 0
33 ;;
34 -)
35 [ "${OPTARG}" == "help" ] && usage && exit 0
36 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue
37 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
38 [ "${OPTARG}" == "nat" ] && NAT="y" && continue
39 echo -e "Invalid option: '--$OPTARG'\n" >&2
40 usage && exit 1
41 ;;
42 \?)
43 echo -e "Invalid option: '-$OPTARG'\n" >&2
44 usage && exit 1
45 ;;
46 *)
47 usage && exit 1
48 ;;
49 esac
50done
51
52echo -e "\nCreating temporary dir for OSM installation"
53TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
54trap 'rm -rf "$TEMPDIR"' EXIT
55
garciadeblas95f164e2016-10-19 13:00:54 +020056echo -e "Checking required packages: git"
57dpkg -l git &>/dev/null || ! echo -e " git not installed.\nInstalling git requires root privileges" || sudo apt install -y git
garciadeblas93c61312016-09-28 15:12:48 +020058echo -e "\nCloning devops repo temporarily"
59git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
garciadeblas95f164e2016-10-19 13:00:54 +020060#DEVOPS_COMMITID="tags/v1.0.0"
61DEVOPS_COMMITID="master"
62git -C $TEMPDIR checkout $DEVOPS_COMMITID
garciadeblas93c61312016-09-28 15:12:48 +020063RC_CLONE=$?
garciadeblas93c61312016-09-28 15:12:48 +020064OSM_DEVOPS=$TEMPDIR
garciadeblas0fe45dd2016-10-04 07:54:17 +020065OSM_JENKINS="$TEMPDIR/jenkins"
66. $OSM_JENKINS/common/all_funcs
garciadeblas93c61312016-09-28 15:12:48 +020067
68if [ -n "$UNINSTALL" ]; then
garciadeblas0fe45dd2016-10-04 07:54:17 +020069 if [ $RC_CLONE ]; then
garciadeblas93c61312016-09-28 15:12:48 +020070 $OSM_DEVOPS/jenkins/host/clean_container RO
71 $OSM_DEVOPS/jenkins/host/clean_container VCA
72 $OSM_DEVOPS/jenkins/host/clean_container SO
73 #$OSM_DEVOPS/jenkins/host/clean_container UI
74 else
75 lxc stop RO && lxc delete RO
76 lxc stop VCA && lxc delete VCA
77 lxc stop SO-ub && lxc delete SO-ub
78 fi
79 exit 0
80fi
81
82if [ -n "$NAT" ]; then
garciadeblas95f164e2016-10-19 13:00:54 +020083 echo -e "\nChecking required packages: iptables-persistent"
84 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
85 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
garciadeblas0fe45dd2016-10-04 07:54:17 +020086 sudo $OSM_DEVOPS/installers/nat_osm
87 exit 0
garciadeblas93c61312016-09-28 15:12:48 +020088fi
89
90#Installation starts here
garciadeblas0fe45dd2016-10-04 07:54:17 +020091wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null
92
garciadeblas95f164e2016-10-19 13:00:54 +020093echo -e "\nChecking required packages: wget, curl, tar"
94dpkg -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 +020095
96echo -e "\nCreating the containers and building ..."
garciadeblas95f164e2016-10-19 13:00:54 +020097COMMIT_ID="tags/v1.0.0"
garciadeblasbad19ac2016-10-04 16:35:57 +020098#COMMIT_ID="master"
99[ -n "$DEVELOP" ] && COMMIT_ID="master"
garciadeblas0fe45dd2016-10-04 07:54:17 +0200100$OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID
garciadeblas93c61312016-09-28 15:12:48 +0200101$OSM_DEVOPS/jenkins/host/start_build VCA
garciadeblas0fe45dd2016-10-04 07:54:17 +0200102$OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID
103$OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID
garciadeblas93c61312016-09-28 15:12:48 +0200104
garciadeblas837fc962016-10-06 01:53:55 +0200105#Install iptables-persistent
garciadeblas95f164e2016-10-19 13:00:54 +0200106echo -e "\nChecking required packages: iptables-persistent"
107dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
garciadeblas837fc962016-10-06 01:53:55 +0200108sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
109
garciadeblas93c61312016-09-28 15:12:48 +0200110#Configure NAT rules
111echo -e "\nConfiguring NAT rules"
garciadeblas0fe45dd2016-10-04 07:54:17 +0200112echo -e " Required root privileges"
113sudo $OSM_DEVOPS/installers/nat_osm
garciadeblas93c61312016-09-28 15:12:48 +0200114
115#Configure components
garciadeblas93c61312016-09-28 15:12:48 +0200116echo -e "\nConfiguring components"
117. $OSM_DEVOPS/installers/export_ips
118
garciadeblas0fe45dd2016-10-04 07:54:17 +0200119echo -e " Configuring RO"
120lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg
121lxc exec RO -- service openmano restart
garciadeblas018946b2016-10-04 19:56:28 +0200122time=0; step=1; timelength=10; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo
garciadeblas0fe45dd2016-10-04 07:54:17 +0200123RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'`
garciadeblas93c61312016-09-28 15:12:48 +0200124
garciadeblas0fe45dd2016-10-04 07:54:17 +0200125echo -e " Configuring VCA"
126JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
127echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
128JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
garciadeblas93c61312016-09-28 15:12:48 +0200129
garciadeblas0fe45dd2016-10-04 07:54:17 +0200130echo -e " Configuring SO"
131sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
garciadeblasbad19ac2016-10-04 16:35:57 +0200132lxc 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
garciadeblas018946b2016-10-04 19:56:28 +0200133time=0; step=18; timelength=180; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo
134
garciadeblasbad19ac2016-10-04 16:35:57 +0200135curl -k --request POST \
garciadeblas2035dd42016-10-04 18:09:17 +0200136 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
garciadeblasbad19ac2016-10-04 16:35:57 +0200137 --header 'accept: application/vnd.yang.data+json' \
138 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
139 --header 'cache-control: no-cache' \
140 --header 'content-type: application/vnd.yang.data+json' \
garciadeblas2035dd42016-10-04 18:09:17 +0200141 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}'
garciadeblasbad19ac2016-10-04 16:35:57 +0200142
garciadeblas2035dd42016-10-04 18:09:17 +0200143curl -k --request PUT \
144 --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \
145 --header 'accept: application/vnd.yang.data+json' \
146 --header 'authorization: Basic YWRtaW46YWRtaW4=' \
147 --header 'cache-control: no-cache' \
148 --header 'content-type: application/vnd.yang.data+json' \
149 --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }'
150
garciadeblas93c61312016-09-28 15:12:48 +0200151
garciadeblas0fe45dd2016-10-04 07:54:17 +0200152echo -e "\nDONE"
garciadeblas93c61312016-09-28 15:12:48 +0200153
154