| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 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" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 21 | 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" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 23 | echo -e " --nat: install only NAT rules" |
| 24 | echo -e " -h / --help: print this help" |
| 25 | } |
| 26 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 27 | #Uninstall OSM: remove containers |
| 28 | function 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 |
| 42 | function 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 |
| 55 | function 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 |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 63 | 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 |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 65 | 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 |
| garciadeblas | d05ae75 | 2016-12-07 12:13:00 +0100 | [diff] [blame] | 74 | 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 & |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 75 | time=0; step=30; timelength=300; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 76 | |
| 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 | |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 95 | function 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 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 105 | UNINSTALL="" |
| 106 | DEVELOP="" |
| 107 | NAT="" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 108 | RECONFIGURE="" |
| 109 | TEST_INSTALLER="" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 110 | LXD="" |
| 111 | SHOWOPTS="" |
| 112 | COMMIT_ID="" |
| 113 | while getopts ":h-:b:" o; do |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 114 | case "${o}" in |
| 115 | h) |
| 116 | usage && exit 0 |
| 117 | ;; |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 118 | b) |
| 119 | COMMIT_ID=${OPTARG} |
| 120 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 121 | -) |
| 122 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| 123 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| 124 | [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue |
| 125 | [ "${OPTARG}" == "nat" ] && NAT="y" && continue |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 126 | [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue |
| 127 | [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 128 | [ "${OPTARG}" == "lxd" ] && LXD="y" && continue |
| 129 | [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 130 | 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 |
| 141 | done |
| 142 | |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 143 | [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| garciadeblas | 14640f0 | 2017-01-04 13:40:55 +0100 | [diff] [blame] | 144 | [ -z "$COMMIT_ID" ] && COMMIT_ID="tags/v1.0.3" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 145 | |
| 146 | if [ -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 |
| 155 | fi |
| 156 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 157 | if [ -n "$TEST_INSTALLER" ]; then |
| 158 | echo -e "\nUsing local devops repo for OSM installation" |
| 159 | TEMPDIR="$(dirname $(realpath $(dirname $0)))" |
| 160 | else |
| 161 | echo -e "\nCreating temporary dir for OSM installation" |
| 162 | TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 163 | trap 'rm -rf "$TEMPDIR"' EXIT |
| 164 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 165 | |
| garciadeblas | 95f164e | 2016-10-19 13:00:54 +0200 | [diff] [blame] | 166 | echo -e "Checking required packages: git" |
| 167 | dpkg -l git &>/dev/null || ! echo -e " git not installed.\nInstalling git requires root privileges" || sudo apt install -y git |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 168 | if [ -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=$? |
| garciadeblas | 14640f0 | 2017-01-04 13:40:55 +0100 | [diff] [blame] | 172 | DEVOPS_COMMITID="tags/v1.0.3" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 173 | git -C $TEMPDIR checkout $DEVOPS_COMMITID |
| 174 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 175 | OSM_DEVOPS=$TEMPDIR |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 176 | OSM_JENKINS="$TEMPDIR/jenkins" |
| 177 | . $OSM_JENKINS/common/all_funcs |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 178 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 179 | [ -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 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 182 | |
| 183 | #Installation starts here |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 184 | wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null |
| 185 | |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 186 | [ -n "$LXD" ] && echo -e "\nConfiguring lxd" && install_lxd |
| 187 | |
| garciadeblas | 95f164e | 2016-10-19 13:00:54 +0200 | [diff] [blame] | 188 | echo -e "\nChecking required packages: wget, curl, tar" |
| 189 | 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 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 190 | |
| 191 | echo -e "\nCreating the containers and building ..." |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 192 | $OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 193 | $OSM_DEVOPS/jenkins/host/start_build VCA |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 194 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID |
| 195 | $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 196 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 197 | #Install iptables-persistent and configure NAT rules |
| 198 | nat |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 199 | |
| 200 | #Configure components |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 201 | configure |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 202 | |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 203 | echo -e "\nDONE" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 204 | |
| 205 | |