3a1c959e9a538c63f0941a963448a8a5f5d334d6
[osm/devops.git] / installers / install_from_source.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 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
26 UNINSTALL=""
27 DEVELOP=""
28 NAT=""
29 while 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
50 done
51
52 echo -e "\nCreating temporary dir for OSM installation"
53 TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
54 trap 'rm -rf "$TEMPDIR"' EXIT
55
56 echo -e "Checking required packages: git"
57 dpkg -l git &>/dev/null || ! echo -e " git not installed.\nInstalling git requires root privileges" || sudo apt install -y git
58 echo -e "\nCloning devops repo temporarily"
59 git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
60 #DEVOPS_COMMITID="tags/v1.0.0"
61 DEVOPS_COMMITID="master"
62 git -C $TEMPDIR checkout $DEVOPS_COMMITID
63 RC_CLONE=$?
64 OSM_DEVOPS=$TEMPDIR
65 OSM_JENKINS="$TEMPDIR/jenkins"
66 . $OSM_JENKINS/common/all_funcs
67
68 if [ -n "$UNINSTALL" ]; then
69 if [ $RC_CLONE ]; then
70 $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
80 fi
81
82 if [ -n "$NAT" ]; then
83 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
86 sudo $OSM_DEVOPS/installers/nat_osm
87 exit 0
88 fi
89
90 #Installation starts here
91 wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null
92
93 echo -e "\nChecking required packages: wget, curl, tar"
94 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 install -y wget curl tar
95
96 echo -e "\nCreating the containers and building ..."
97 COMMIT_ID="tags/v1.0.0"
98 #COMMIT_ID="master"
99 [ -n "$DEVELOP" ] && COMMIT_ID="master"
100 $OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID
101 $OSM_DEVOPS/jenkins/host/start_build VCA
102 $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID
103 $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID
104
105 #Install iptables-persistent
106 echo -e "\nChecking required packages: iptables-persistent"
107 dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
108 sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
109
110 #Configure NAT rules
111 echo -e "\nConfiguring NAT rules"
112 echo -e " Required root privileges"
113 sudo $OSM_DEVOPS/installers/nat_osm
114
115 #Configure components
116 echo -e "\nConfiguring components"
117 . $OSM_DEVOPS/installers/export_ips
118
119 echo -e " Configuring RO"
120 lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg
121 lxc exec RO -- service openmano restart
122 time=0; step=1; timelength=10; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo
123 RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'`
124
125 echo -e " Configuring VCA"
126 JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32`
127 echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password
128 JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
129
130 echo -e " Configuring SO"
131 sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
132 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
133 time=0; step=18; timelength=180; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo
134
135 curl -k --request POST \
136 --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \
137 --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' \
141 --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}'
142
143 curl -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
151
152 echo -e "\nDONE"
153
154