| 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]" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 18 | echo -e "Install OSM from binaries or source code (by default, from binaries)" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 19 | echo -e " OPTIONS" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 20 | echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" |
| 21 | echo -e " --source: install OSM from source code using the latest stable tag" |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 22 | echo -e " -r <repo>: use specified repository name for osm packages" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 23 | echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)" |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 24 | echo -e " -u <repo base>: use specified repository url for osm packages" |
| 25 | echo -e " -k <repo key>: use specified repository public key url" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 26 | echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag" |
| 27 | echo -e " -b master (main dev branch)" |
| 28 | echo -e " -b v2.0 (v2.0 branch)" |
| 29 | echo -e " -b tags/v1.1.0 (a specific tag)" |
| 30 | echo -e " ..." |
| 31 | echo -e " --lxdimages: download lxd images from OSM repository instead of creating them from scratch" |
| 32 | echo -e " -l <lxd_repo>: use specified repository url for lxd images" |
| 33 | echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch" |
| 34 | # echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)" |
| 35 | echo -e " --nat: install only NAT rules" |
| 36 | echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules" |
| 37 | # echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch" |
| 38 | echo -e " --showopts: print chosen options and exit (only for debugging)" |
| 39 | echo -e " -y: do not prompt for confirmation, assumes yes" |
| 40 | echo -e " -h / --help: print this help" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 43 | #Uninstall OSM: remove containers |
| 44 | function uninstall(){ |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 45 | echo -e "\nUninstalling OSM" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 46 | if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then |
| 47 | $OSM_DEVOPS/jenkins/host/clean_container RO |
| 48 | $OSM_DEVOPS/jenkins/host/clean_container VCA |
| 49 | $OSM_DEVOPS/jenkins/host/clean_container SO |
| 50 | #$OSM_DEVOPS/jenkins/host/clean_container UI |
| 51 | else |
| 52 | lxc stop RO && lxc delete RO |
| 53 | lxc stop VCA && lxc delete VCA |
| 54 | lxc stop SO-ub && lxc delete SO-ub |
| 55 | fi |
| 56 | } |
| 57 | |
| 58 | #Configure NAT rules, based on the current IP addresses of containers |
| 59 | function nat(){ |
| 60 | echo -e "\nChecking required packages: iptables-persistent" |
| 61 | dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \ |
| 62 | sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent |
| 63 | echo -e "\nConfiguring NAT rules" |
| 64 | echo -e " Required root privileges" |
| 65 | sudo $OSM_DEVOPS/installers/nat_osm |
| 66 | } |
| 67 | |
| Mike Marchetti | d8577f5 | 2017-10-19 15:27:48 -0400 | [diff] [blame] | 68 | function FATAL(){ |
| 69 | echo "FATAL error: Cannot install OSM due to \"$1\"" |
| 70 | exit 1 |
| 71 | } |
| 72 | |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 73 | #Update RO, SO and UI: |
| 74 | function update(){ |
| 75 | echo -e "\nUpdating components" |
| 76 | |
| 77 | echo -e " Updating RO" |
| 78 | CONTAINER="RO" |
| 79 | MDG="RO" |
| 80 | INSTALL_FOLDER="/opt/openmano" |
| 81 | echo -e " Fetching the repo" |
| 82 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 83 | BRANCH="" |
| 84 | BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'` |
| Jokin Garay | c17db01 | 2017-03-08 17:45:39 +0100 | [diff] [blame] | 85 | [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 86 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 87 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 88 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 89 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 90 | CHECKOUT_ID=$COMMIT_ID |
| 91 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 92 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 93 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 94 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 95 | else |
| 96 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 97 | fi |
| 98 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 99 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 100 | echo " Nothing to be done." |
| 101 | else |
| 102 | echo " Update required." |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 103 | lxc exec $CONTAINER -- service osm-ro stop |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 104 | lxc exec $CONTAINER -- git -C /opt/openmano stash |
| 105 | lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase |
| 106 | lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID |
| 107 | lxc exec $CONTAINER -- git -C /opt/openmano stash pop |
| 108 | lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 109 | lxc exec $CONTAINER -- service osm-ro start |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 110 | fi |
| 111 | echo |
| 112 | |
| 113 | echo -e " Updating SO and UI" |
| 114 | CONTAINER="SO-ub" |
| 115 | MDG="SO" |
| 116 | INSTALL_FOLDER="" # To be filled in |
| 117 | echo -e " Fetching the repo" |
| 118 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 119 | BRANCH="" |
| 120 | BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'` |
| Jokin Garay | c17db01 | 2017-03-08 17:45:39 +0100 | [diff] [blame] | 121 | [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 122 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 123 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 124 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 125 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 126 | CHECKOUT_ID=$COMMIT_ID |
| 127 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 128 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 129 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 130 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 131 | else |
| 132 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 133 | fi |
| 134 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 135 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 136 | echo " Nothing to be done." |
| 137 | else |
| 138 | echo " Update required." |
| 139 | # Instructions to be added |
| 140 | # lxc exec SO-ub -- ... |
| 141 | fi |
| 142 | echo |
| 143 | } |
| 144 | |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 145 | function so_is_up() { |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 146 | if [ -n "$1" ]; then |
| 147 | SO_IP=$1 |
| 148 | else |
| 149 | SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'` |
| 150 | fi |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 151 | time=0 |
| 152 | step=5 |
| 153 | timelength=300 |
| 154 | while [ $time -le $timelength ] |
| 155 | do |
| Jeremy Mordkoff | 74fde89 | 2017-12-13 17:58:04 -0500 | [diff] [blame] | 156 | if [[ `curl -m 10 -k -X GET https://$SO_IP:8008/api/operational/vcs/info \ |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 157 | -H 'accept: application/vnd.yang.data+json' \ |
| 158 | -H 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 159 | -H 'cache-control: no-cache' 2> /dev/null | jq '.[].components.component_info[] | select(.component_name=="RW.Restconf")' 2>/dev/null | grep "RUNNING" | wc -l` -eq 1 ]] |
| 160 | then |
| 161 | echo "RW.Restconf running....SO is up" |
| 162 | return 0 |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 163 | fi |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 164 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 165 | sleep $step |
| 166 | echo -n "." |
| 167 | time=$((time+step)) |
| 168 | done |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 169 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 170 | FATAL "OSM Failed to startup. SO failed to startup" |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 171 | } |
| 172 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 173 | function vca_is_up() { |
| 174 | if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then |
| 175 | echo "VCA is up and running" |
| 176 | return 0 |
| 177 | fi |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 178 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 179 | FATAL "OSM Failed to startup. VCA failed to startup" |
| 180 | } |
| 181 | |
| 182 | function ro_is_up() { |
| 183 | if [ -n "$1" ]; then |
| 184 | RO_IP=$1 |
| 185 | else |
| 186 | RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'` |
| 187 | fi |
| 188 | time=0 |
| 189 | step=2 |
| 190 | timelength=20 |
| 191 | while [ $time -le $timelength ]; do |
| 192 | if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then |
| 193 | echo "RO is up and running" |
| 194 | return 0 |
| 195 | fi |
| 196 | sleep $step |
| 197 | echo -n "." |
| 198 | time=$((time+step)) |
| 199 | done |
| 200 | |
| 201 | FATAL "OSM Failed to startup. RO failed to startup" |
| 202 | } |
| 203 | |
| 204 | |
| 205 | function configure_RO(){ |
| 206 | . $OSM_DEVOPS/installers/export_ips |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 207 | echo -e " Configuring RO" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 208 | lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg |
| 209 | lxc exec RO -- service osm-ro restart |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 210 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 211 | ro_is_up |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 212 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 213 | lxc exec RO -- openmano tenant-delete -f osm >/dev/null |
| tierno | 15f4f22 | 2017-06-14 13:23:01 +0200 | [diff] [blame] | 214 | lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc |
| 215 | lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc |
| 216 | #lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc' |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 217 | } |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 218 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 219 | function configure_VCA(){ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 220 | echo -e " Configuring VCA" |
| 221 | JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 222 | echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | function configure_SOUI(){ |
| 226 | . $OSM_DEVOPS/installers/export_ips |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 227 | JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 228 | RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 229 | |
| 230 | echo -e " Configuring SO" |
| 231 | sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP |
| garciadeblas | 2f4c93b | 2017-04-10 18:12:12 +0200 | [diff] [blame] | 232 | sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local |
| Jeremy Mordkoff | 5cc6ccc | 2017-10-05 15:21:07 -0400 | [diff] [blame] | 233 | # make journaling persistent |
| 234 | lxc exec SO-ub -- mkdir -p /var/log/journal |
| 235 | lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal |
| 236 | lxc exec SO-ub -- systemctl restart systemd-journald |
| 237 | |
| Jeremy Mordkoff | 3b3edea | 2017-10-03 16:21:56 -0400 | [diff] [blame] | 238 | echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad |
| 239 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 240 | lxc exec SO-ub -- systemctl restart launchpad |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 241 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 242 | so_is_up $SO_CONTAINER_IP |
| 243 | |
| Jeremy Mordkoff | e475bb8 | 2017-12-13 16:35:28 -0500 | [diff] [blame] | 244 | #delete existing config agent if already configured |
| 245 | current=$(curl -k --request GET \ |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 246 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \ |
| 247 | --header 'accept: application/vnd.yang.data+json' \ |
| 248 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 249 | --header 'cache-control: no-cache' \ |
| Jeremy Mordkoff | 829106f | 2017-12-13 18:29:45 -0500 | [diff] [blame] | 250 | --header 'content-type: application/vnd.yang.data+json' ) |
| Jeremy Mordkoff | e475bb8 | 2017-12-13 16:35:28 -0500 | [diff] [blame] | 251 | |
| Jeremy Mordkoff | 74fde89 | 2017-12-13 17:58:04 -0500 | [diff] [blame] | 252 | if [ -n "$current" -a "$current" != "{}" ]; then |
| Jeremy Mordkoff | e475bb8 | 2017-12-13 16:35:28 -0500 | [diff] [blame] | 253 | curl -k --request DELETE \ |
| 254 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \ |
| 255 | --header 'accept: application/vnd.yang.data+json' \ |
| 256 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 257 | --header 'cache-control: no-cache' \ |
| 258 | --header 'content-type: application/vnd.yang.data+json' &> /dev/null |
| 259 | fi |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 260 | |
| 261 | result=$(curl -k --request POST \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 262 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ |
| 263 | --header 'accept: application/vnd.yang.data+json' \ |
| 264 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 265 | --header 'cache-control: no-cache' \ |
| 266 | --header 'content-type: application/vnd.yang.data+json' \ |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 267 | --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}') |
| 268 | [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 269 | |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 270 | #R1/R2 config line |
| 271 | #result=$(curl -k --request PUT \ |
| 272 | # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \ |
| 273 | # --header 'accept: application/vnd.yang.data+json' \ |
| 274 | # --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 275 | # --header 'cache-control: no-cache' \ |
| 276 | # --header 'content-type: application/vnd.yang.data+json' \ |
| 277 | # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }') |
| 278 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 279 | result=$(curl -k --request PUT \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 280 | --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 281 | --header 'accept: application/vnd.yang.data+json' \ |
| 282 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 283 | --header 'cache-control: no-cache' \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 284 | --header 'content-type: application/vnd.yang.data+json' \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 285 | --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}') |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 286 | [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result" |
| Jeremy Mordkoff | 2059b39 | 2017-10-03 17:34:10 -0400 | [diff] [blame] | 287 | |
| Jeremy Mordkoff | 34151f2 | 2017-10-04 19:45:37 -0400 | [diff] [blame] | 288 | result=$(curl -k --request PATCH \ |
| 289 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \ |
| 290 | --header 'accept: application/vnd.yang.data+json' \ |
| 291 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 292 | --header 'cache-control: no-cache' \ |
| 293 | --header 'content-type: application/vnd.yang.data+json' \ |
| 294 | --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }') |
| 295 | [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result" |
| 296 | |
| 297 | result=$(curl -k --request PATCH \ |
| 298 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \ |
| 299 | --header 'accept: application/vnd.yang.data+json' \ |
| 300 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 301 | --header 'cache-control: no-cache' \ |
| 302 | --header 'content-type: application/vnd.yang.data+json' \ |
| 303 | --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }') |
| 304 | [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result" |
| 305 | |
| Jeremy Mordkoff | f4b6e62 | 2017-10-04 12:05:41 -0400 | [diff] [blame] | 306 | lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF |
| 307 | auto lo:1 |
| 308 | iface lo:1 inet static |
| 309 | address $DEFAULT_IP |
| 310 | netmask 255.255.255.255 |
| 311 | EOF |
| 312 | lxc exec SO-ub ifup lo:1 |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 313 | } |
| Jeremy Mordkoff | 2059b39 | 2017-10-03 17:34:10 -0400 | [diff] [blame] | 314 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 315 | #Configure RO, VCA, and SO with the initial configuration: |
| 316 | # RO -> tenant:osm, logs to be sent to SO |
| 317 | # VCA -> juju-password |
| 318 | # SO -> route to Juju Controller, add RO account, add VCA account |
| 319 | function configure(){ |
| 320 | #Configure components |
| 321 | echo -e "\nConfiguring components" |
| 322 | configure_RO |
| 323 | configure_VCA |
| 324 | configure_SOUI |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 325 | } |
| 326 | |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 327 | function install_lxd() { |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 328 | sudo apt-get update |
| 329 | sudo apt-get install -y lxd |
| 330 | newgrp lxd |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 331 | lxd init --auto |
| 332 | lxd waitready |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 333 | lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false |
| 334 | DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}') |
| 335 | DEFAULT_MTU=$( ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 336 | lxc profile device set default eth0 mtu $DEFAULT_MTU |
| 337 | #sudo systemctl stop lxd-bridge |
| 338 | #sudo systemctl --system daemon-reload |
| 339 | #sudo systemctl enable lxd-bridge |
| 340 | #sudo systemctl start lxd-bridge |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| tierno | 53881d7 | 2017-04-25 11:58:57 +0200 | [diff] [blame] | 343 | function ask_user(){ |
| 344 | # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive |
| 345 | # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed |
| 346 | # Return: true(0) if user type 'yes'; false (1) if user type 'no' |
| 347 | read -e -p "$1" USER_CONFIRMATION |
| 348 | while true ; do |
| 349 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0 |
| 350 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1 |
| 351 | [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0 |
| 352 | [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1 |
| 353 | read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION |
| 354 | done |
| 355 | } |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 356 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 357 | function launch_container_from_lxd(){ |
| 358 | export OSM_MDG=$1 |
| 359 | OSM_load_config |
| 360 | export OSM_BASE_IMAGE=$2 |
| 361 | if ! container_exists $OSM_BUILD_CONTAINER; then |
| 362 | CONTAINER_OPTS="" |
| 363 | [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true" |
| 364 | [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true" |
| 365 | create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS |
| 366 | wait_container_up $OSM_BUILD_CONTAINER |
| 367 | fi |
| 368 | } |
| 369 | |
| 370 | function install_osmclient(){ |
| 371 | CLIENT_RELEASE=${RELEASE#"-R "} |
| 372 | CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" |
| 373 | CLIENT_REPOSITORY="stable" |
| 374 | [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian" |
| 375 | CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "} |
| 376 | key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY |
| 377 | curl $key_location | sudo apt-key add - |
| 378 | sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient" |
| 379 | sudo apt-get update |
| 380 | sudo apt-get install -y python-osmclient |
| 381 | export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'` |
| 382 | export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'` |
| 383 | echo -e "\nOSM client installed" |
| 384 | echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:" |
| 385 | echo " export OSM_HOSTNAME=${OSM_HOSTNAME}" |
| 386 | echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}" |
| 387 | } |
| 388 | |
| 389 | function install_from_lxdimages(){ |
| 390 | LXD_RELEASE=${RELEASE#"-R "} |
| 391 | LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")" |
| 392 | trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT |
| 393 | wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz |
| 394 | lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro |
| 395 | rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz |
| 396 | wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz |
| 397 | lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca |
| 398 | rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz |
| 399 | wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz |
| 400 | lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui |
| 401 | rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz |
| 402 | launch_container_from_lxd RO osm-ro |
| 403 | ro_is_up && track RO |
| 404 | launch_container_from_lxd VCA osm-vca |
| 405 | vca_is_up && track VCA |
| 406 | launch_container_from_lxd SO osm-soui |
| 407 | #so_is_up && track SOUI |
| 408 | track SOUI |
| 409 | } |
| 410 | |
| 411 | function dump_vars(){ |
| 412 | echo "DEVELOP=$DEVELOP" |
| 413 | echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE" |
| 414 | echo "UNINSTALL=$UNINSTALL" |
| 415 | echo "NAT=$NAT" |
| 416 | echo "UPDATE=$UPDATE" |
| 417 | echo "RECONFIGURE=$RECONFIGURE" |
| 418 | echo "TEST_INSTALLER=$TEST_INSTALLER" |
| 419 | echo "INSTALL_LXD=$INSTALL_LXD" |
| 420 | echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES" |
| 421 | echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE" |
| 422 | echo "RELEASE=$RELEASE" |
| 423 | echo "REPOSITORY=$REPOSITORY" |
| 424 | echo "REPOSITORY_BASE=$REPOSITORY_BASE" |
| 425 | echo "REPOSITORY_KEY=$REPOSITORY_KEY" |
| 426 | echo "NOCONFIGURE=$NOCONFIGURE" |
| 427 | echo "SHOWOPTS=$SHOWOPTS" |
| 428 | echo "Install from specific refspec (-b): $COMMIT_ID" |
| 429 | } |
| 430 | |
| 431 | function track(){ |
| 432 | ctime=`date +%s` |
| 433 | duration=$((ctime - SESSION_ID)) |
| 434 | url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}" |
| 435 | #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}" |
| 436 | event_name="bin" |
| 437 | [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src" |
| 438 | [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd" |
| 439 | event_name="${event_name}_$1" |
| 440 | url="${url}&event=${event_name}&ce_duration=${duration}" |
| 441 | wget -q -O /dev/null $url |
| 442 | } |
| 443 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 444 | UNINSTALL="" |
| 445 | DEVELOP="" |
| 446 | NAT="" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 447 | UPDATE="" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 448 | RECONFIGURE="" |
| 449 | TEST_INSTALLER="" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 450 | INSTALL_LXD="" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 451 | SHOWOPTS="" |
| 452 | COMMIT_ID="" |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 453 | ASSUME_YES="" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 454 | INSTALL_FROM_SOURCE="" |
| garciadeblas | 8244229 | 2017-11-16 14:48:12 +0100 | [diff] [blame] | 455 | RELEASE="-R ReleaseTHREE" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 456 | INSTALL_FROM_LXDIMAGES="" |
| 457 | LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd" |
| 458 | NOCONFIGURE="" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 459 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 460 | SESSION_ID=`date +%s` |
| 461 | |
| 462 | while getopts ":hy-:b:r:k:u:R:l:" o; do |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 463 | case "${o}" in |
| 464 | h) |
| 465 | usage && exit 0 |
| 466 | ;; |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 467 | b) |
| 468 | COMMIT_ID=${OPTARG} |
| 469 | ;; |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 470 | r) |
| 471 | REPOSITORY="-r ${OPTARG}" |
| 472 | ;; |
| 473 | R) |
| 474 | RELEASE="-R ${OPTARG}" |
| 475 | ;; |
| 476 | k) |
| 477 | REPOSITORY_KEY="-k ${OPTARG}" |
| 478 | ;; |
| 479 | u) |
| 480 | REPOSITORY_BASE="-u ${OPTARG}" |
| 481 | ;; |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 482 | l) |
| 483 | LXD_REPOSITORY_BASE="${OPTARG}" |
| 484 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 485 | -) |
| 486 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 487 | [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 488 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| 489 | [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue |
| 490 | [ "${OPTARG}" == "nat" ] && NAT="y" && continue |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 491 | [ "${OPTARG}" == "update" ] && UPDATE="y" && continue |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 492 | [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue |
| 493 | [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 494 | [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue |
| 495 | [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue |
| 496 | [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 497 | [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 498 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 499 | usage && exit 1 |
| 500 | ;; |
| 501 | \?) |
| 502 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 503 | usage && exit 1 |
| 504 | ;; |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 505 | y) |
| 506 | ASSUME_YES="y" |
| 507 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 508 | *) |
| 509 | usage && exit 1 |
| 510 | ;; |
| 511 | esac |
| 512 | done |
| 513 | |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 514 | if [ -n "$SHOWOPTS" ]; then |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 515 | dump_vars |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 516 | exit 0 |
| 517 | fi |
| 518 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 519 | # if develop, we force master |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 520 | [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 521 | |
| Mike Marchetti | 0d56760 | 2017-09-29 14:30:28 -0400 | [diff] [blame] | 522 | # forcing source from master removed. Now only install from source when explicit |
| 523 | # [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 524 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 525 | if [ -n "$TEST_INSTALLER" ]; then |
| 526 | echo -e "\nUsing local devops repo for OSM installation" |
| 527 | TEMPDIR="$(dirname $(realpath $(dirname $0)))" |
| 528 | else |
| 529 | echo -e "\nCreating temporary dir for OSM installation" |
| 530 | TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 531 | trap 'rm -rf "$TEMPDIR"' EXIT |
| 532 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 533 | |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 534 | need_packages="git jq" |
| 535 | for package in $need_packages; do |
| 536 | echo -e "Checking required packages: $package" |
| Mike Marchetti | d8577f5 | 2017-10-19 15:27:48 -0400 | [diff] [blame] | 537 | dpkg -l $package &>/dev/null \ |
| 538 | || ! echo -e " $package not installed.\nInstalling $package requires root privileges" \ |
| 539 | || sudo apt-get install -y $package \ |
| 540 | || FATAL "failed to install $package" |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 541 | done |
| 542 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 543 | if [ -z "$TEST_INSTALLER" ]; then |
| 544 | echo -e "\nCloning devops repo temporarily" |
| 545 | git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR |
| 546 | RC_CLONE=$? |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 547 | fi |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 548 | |
| 549 | echo -e "\nGuessing the current stable release" |
| Mike Marchetti | 91df835 | 2017-10-17 13:47:48 -0400 | [diff] [blame] | 550 | LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1` |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 551 | [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0 |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 552 | echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" |
| 553 | [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 554 | [ -z "$TEST_INSTALLER" ] && git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 555 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 556 | OSM_DEVOPS=$TEMPDIR |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 557 | OSM_JENKINS="$TEMPDIR/jenkins" |
| 558 | . $OSM_JENKINS/common/all_funcs |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 559 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 560 | [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 |
| 561 | [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0 |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 562 | [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0 |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 563 | [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 564 | |
| 565 | #Installation starts here |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 566 | echo -e "\nInstalling OSM from refspec: $COMMIT_ID" |
| 567 | if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then |
| tierno | 53881d7 | 2017-04-25 11:58:57 +0200 | [diff] [blame] | 568 | ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1 |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 569 | fi |
| 570 | |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 571 | echo -e "\nChecking required packages: wget, curl, tar" |
| 572 | 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-get install -y wget curl tar |
| 573 | |
| Jokin Garay | c0a6596 | 2017-03-09 14:51:48 +0100 | [diff] [blame] | 574 | echo -e "Checking required packages: lxd" |
| garciadeblas | d880f72 | 2017-04-07 20:14:57 +0200 | [diff] [blame] | 575 | lxd --version &>/dev/null || FATAL "lxd not present, exiting." |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 576 | [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 577 | |
| Mike Marchetti | b884a46 | 2017-10-05 13:28:33 -0400 | [diff] [blame] | 578 | wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README.txt &> /dev/null |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 579 | track start |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 580 | |
| Mike Marchetti | d1e08b9 | 2017-09-29 16:14:11 -0400 | [diff] [blame] | 581 | # use local devops for containers |
| 582 | export OSM_USE_LOCAL_DEVOPS=true |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 583 | if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 584 | echo -e "\nCreating the containers and building from source ..." |
| 585 | $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 586 | ro_is_up && track RO |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 587 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 588 | vca_is_up && track VCA |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 589 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')" |
| 590 | $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 591 | #so_is_up && track SOUI |
| 592 | track SOUI |
| 593 | elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo |
| 594 | echo -e "\nInstalling from lxd images ..." |
| 595 | install_from_lxdimages |
| 596 | else #install from binaries |
| 597 | echo -e "\nCreating the containers and installing from binaries ..." |
| 598 | $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed" |
| 599 | ro_is_up && track RO |
| 600 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed" |
| 601 | vca_is_up && track VCA |
| 602 | $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed" |
| 603 | $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed" |
| 604 | #so_is_up && track SOUI |
| 605 | track SOUI |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 606 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 607 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 608 | #Install iptables-persistent and configure NAT rules |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 609 | [ -z "$NOCONFIGURE" ] && nat |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 610 | |
| 611 | #Configure components |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 612 | [ -z "$NOCONFIGURE" ] && configure |
| 613 | |
| 614 | #Install osmclient |
| 615 | [ -z "$NOCONFIGURE" ] && install_osmclient |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 616 | |
| Mike Marchetti | b884a46 | 2017-10-05 13:28:33 -0400 | [diff] [blame] | 617 | wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README2.txt &> /dev/null |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 618 | track end |
| Jokin Garay | 3eb9ce7 | 2017-03-09 14:48:11 +0100 | [diff] [blame] | 619 | echo -e "\nDONE" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 620 | |