| 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" |
| 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 "\nCloning devops repo temporarily" |
| 57 | git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR |
| 58 | RC_CLONE=$? |
| 59 | |
| 60 | OSM_DEVOPS=$TEMPDIR |
| 61 | |
| 62 | if [ -n "$UNINSTALL" ]; then |
| 63 | if $RC_CLONE; then |
| 64 | $OSM_DEVOPS/jenkins/host/clean_container RO |
| 65 | $OSM_DEVOPS/jenkins/host/clean_container VCA |
| 66 | $OSM_DEVOPS/jenkins/host/clean_container SO |
| 67 | #$OSM_DEVOPS/jenkins/host/clean_container UI |
| 68 | else |
| 69 | lxc stop RO && lxc delete RO |
| 70 | lxc stop VCA && lxc delete VCA |
| 71 | lxc stop SO-ub && lxc delete SO-ub |
| 72 | fi |
| 73 | exit 0 |
| 74 | fi |
| 75 | |
| 76 | if [ -n "$NAT" ]; then |
| 77 | $OSM_DEVOPS/installers/nat-osm || FATAL "Failed to run nat-osm" |
| 78 | fi |
| 79 | |
| 80 | #Installation starts here |
| 81 | echo -e "\nInstalling required packages: git, wget, curl, tar" |
| 82 | echo -e "\n Required root privileges" |
| 83 | sudo apt install -y git wget curl tar |
| 84 | |
| 85 | echo -e "\nCreating the containers and building ..." |
| 86 | . $OSM_DEVOPS/jenkins/common/all_funcs |
| 87 | $OSM_DEVOPS/jenkins/host/start_build RO |
| 88 | $OSM_DEVOPS/jenkins/host/start_build VCA |
| 89 | $OSM_DEVOPS/jenkins/host/start_build SO |
| 90 | $OSM_DEVOPS/jenkins/host/start_build UI |
| 91 | |
| 92 | #Configure NAT rules |
| 93 | echo -e "\nConfiguring NAT rules" |
| 94 | echo -e "\n Required root privileges" |
| 95 | sudo $OSM_DEVOPS/installers/nat-osm |
| 96 | |
| 97 | #Configure components |
| 98 | # TO BE DONE |
| 99 | echo -e "\nConfiguring components" |
| 100 | . $OSM_DEVOPS/installers/export_ips |
| 101 | |
| 102 | echo -e "\n Configuring RO" |
| 103 | #RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` |
| 104 | |
| 105 | echo -e "\n Configuring VCA" |
| 106 | #JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 107 | #lxc exec VCA -- juju change-user-password $JUJUPASSWD |
| 108 | #JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| 109 | |
| 110 | echo -e "\n Configuring SO" |
| 111 | #sudo route add -net $JUJU_CONTROLLER_IP/32 gw $VCA_CONTAINER_IP |
| 112 | #lxc exec SO-ub -- sudo -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode --test-name "launchpad" |
| 113 | #sleep 2 |
| 114 | #lxc exec SO-ub -- resource-orchestrator name openmano account-type openmano openmano host $RO_CONTAINER_IP tenant-id $RO_TENANT_ID port 9090 |
| 115 | #lxc exec SO-ub -- config-agent account juju account-type juju juju ip-address $JUJU_CONTROLLER_IP port 17070 user admin secret $JUJU_PASSWD |
| 116 | |
| 117 | echo "\nDONE" |
| 118 | |
| 119 | |