| 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" |
| 20 | echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 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" |
| 23 | echo -e " -R <release>: use specified release for osm packages" |
| 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 | a1fc457 | 2017-04-24 19:08:21 +0200 | [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)" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 30 | echo -e " ..." |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 31 | 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] | 32 | echo -e " --nat: install only NAT rules" |
| garciadeblas | fc43c9d | 2017-03-01 13:25:11 +0100 | [diff] [blame] | 33 | # echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch" |
| 34 | echo -e " --showopts: print chosen options and exit (only for debugging)" |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 35 | echo -e " -y: do not prompt for confirmation, assumes yes" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 36 | echo -e " -h / --help: print this help" |
| 37 | } |
| 38 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 39 | #Uninstall OSM: remove containers |
| 40 | function uninstall(){ |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 41 | echo -e "\nUninstalling OSM" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 42 | if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then |
| 43 | $OSM_DEVOPS/jenkins/host/clean_container RO |
| 44 | $OSM_DEVOPS/jenkins/host/clean_container VCA |
| 45 | $OSM_DEVOPS/jenkins/host/clean_container SO |
| 46 | #$OSM_DEVOPS/jenkins/host/clean_container UI |
| 47 | else |
| 48 | lxc stop RO && lxc delete RO |
| 49 | lxc stop VCA && lxc delete VCA |
| 50 | lxc stop SO-ub && lxc delete SO-ub |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | #Configure NAT rules, based on the current IP addresses of containers |
| 55 | function nat(){ |
| 56 | echo -e "\nChecking required packages: iptables-persistent" |
| 57 | dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \ |
| 58 | sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent |
| 59 | echo -e "\nConfiguring NAT rules" |
| 60 | echo -e " Required root privileges" |
| 61 | sudo $OSM_DEVOPS/installers/nat_osm |
| 62 | } |
| 63 | |
| Mike Marchetti | d8577f5 | 2017-10-19 15:27:48 -0400 | [diff] [blame] | 64 | function FATAL(){ |
| 65 | echo "FATAL error: Cannot install OSM due to \"$1\"" |
| 66 | exit 1 |
| 67 | } |
| 68 | |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 69 | #Update RO, SO and UI: |
| 70 | function update(){ |
| 71 | echo -e "\nUpdating components" |
| 72 | |
| 73 | echo -e " Updating RO" |
| 74 | CONTAINER="RO" |
| 75 | MDG="RO" |
| 76 | INSTALL_FOLDER="/opt/openmano" |
| 77 | echo -e " Fetching the repo" |
| 78 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 79 | BRANCH="" |
| 80 | 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] | 81 | [ -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] | 82 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 83 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 84 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 85 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 86 | CHECKOUT_ID=$COMMIT_ID |
| 87 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 88 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 89 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 90 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 91 | else |
| 92 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 93 | fi |
| 94 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 95 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 96 | echo " Nothing to be done." |
| 97 | else |
| 98 | echo " Update required." |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 99 | lxc exec $CONTAINER -- service osm-ro stop |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 100 | lxc exec $CONTAINER -- git -C /opt/openmano stash |
| 101 | lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase |
| 102 | lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID |
| 103 | lxc exec $CONTAINER -- git -C /opt/openmano stash pop |
| 104 | lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 105 | lxc exec $CONTAINER -- service osm-ro start |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 106 | fi |
| 107 | echo |
| 108 | |
| 109 | echo -e " Updating SO and UI" |
| 110 | CONTAINER="SO-ub" |
| 111 | MDG="SO" |
| 112 | INSTALL_FOLDER="" # To be filled in |
| 113 | echo -e " Fetching the repo" |
| 114 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 115 | BRANCH="" |
| 116 | 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] | 117 | [ -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] | 118 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 119 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 120 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 121 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 122 | CHECKOUT_ID=$COMMIT_ID |
| 123 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 124 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 125 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 126 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 127 | else |
| 128 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 129 | fi |
| 130 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 131 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 132 | echo " Nothing to be done." |
| 133 | else |
| 134 | echo " Update required." |
| 135 | # Instructions to be added |
| 136 | # lxc exec SO-ub -- ... |
| 137 | fi |
| 138 | echo |
| 139 | } |
| 140 | |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 141 | function so_is_up() { |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 142 | SO_IP=$1 |
| 143 | time=0 |
| 144 | step=5 |
| 145 | timelength=300 |
| 146 | while [ $time -le $timelength ] |
| 147 | do |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 148 | if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \ |
| 149 | -H 'accept: application/vnd.yang.data+json' \ |
| 150 | -H 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 151 | -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 ]] |
| 152 | then |
| 153 | echo "RW.Restconf running....SO is up" |
| 154 | return 0 |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 155 | fi |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 156 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 157 | sleep $step |
| 158 | echo -n "." |
| 159 | time=$((time+step)) |
| 160 | done |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 161 | |
| 162 | FATAL "OSM Failed to startup" |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 163 | } |
| 164 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 165 | #Configure VCA, SO and RO with the initial configuration: |
| 166 | # RO -> tenant:osm, logs to be sent to SO |
| 167 | # VCA -> juju-password |
| 168 | # SO -> route to Juju Controller, add RO account, add VCA account |
| 169 | function configure(){ |
| 170 | #Configure components |
| 171 | echo -e "\nConfiguring components" |
| 172 | . $OSM_DEVOPS/installers/export_ips |
| 173 | |
| 174 | echo -e " Configuring RO" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 175 | lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg |
| 176 | lxc exec RO -- service osm-ro restart |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 177 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 178 | time=0; step=2; timelength=20; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 179 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 180 | lxc exec RO -- openmano tenant-delete -f osm >/dev/null |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 181 | RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` |
| tierno | 15f4f22 | 2017-06-14 13:23:01 +0200 | [diff] [blame] | 182 | lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc |
| 183 | lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc |
| 184 | #lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc' |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 185 | |
| 186 | echo -e " Configuring VCA" |
| 187 | JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 188 | echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password |
| 189 | JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| 190 | |
| 191 | echo -e " Configuring SO" |
| 192 | sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP |
| garciadeblas | 2f4c93b | 2017-04-10 18:12:12 +0200 | [diff] [blame] | 193 | 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] | 194 | |
| 195 | # make journaling persistent |
| 196 | lxc exec SO-ub -- mkdir -p /var/log/journal |
| 197 | lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal |
| 198 | lxc exec SO-ub -- systemctl restart systemd-journald |
| 199 | |
| Jeremy Mordkoff | 3b3edea | 2017-10-03 16:21:56 -0400 | [diff] [blame] | 200 | echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad |
| 201 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 202 | lxc exec SO-ub -- systemctl restart launchpad |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 203 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 204 | so_is_up $SO_CONTAINER_IP |
| 205 | |
| 206 | #delete existing config agent (could be there on reconfigure) |
| 207 | curl -k --request DELETE \ |
| 208 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \ |
| 209 | --header 'accept: application/vnd.yang.data+json' \ |
| 210 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 211 | --header 'cache-control: no-cache' \ |
| 212 | --header 'content-type: application/vnd.yang.data+json' &> /dev/null |
| 213 | |
| 214 | result=$(curl -k --request POST \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 215 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ |
| 216 | --header 'accept: application/vnd.yang.data+json' \ |
| 217 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 218 | --header 'cache-control: no-cache' \ |
| 219 | --header 'content-type: application/vnd.yang.data+json' \ |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 220 | --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}') |
| 221 | [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 222 | |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 223 | #R1/R2 config line |
| 224 | #result=$(curl -k --request PUT \ |
| 225 | # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \ |
| 226 | # --header 'accept: application/vnd.yang.data+json' \ |
| 227 | # --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 228 | # --header 'cache-control: no-cache' \ |
| 229 | # --header 'content-type: application/vnd.yang.data+json' \ |
| 230 | # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }') |
| 231 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 232 | result=$(curl -k --request PUT \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 233 | --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 234 | --header 'accept: application/vnd.yang.data+json' \ |
| 235 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 236 | --header 'cache-control: no-cache' \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 237 | --header 'content-type: application/vnd.yang.data+json' \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 238 | --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] | 239 | [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result" |
| Jeremy Mordkoff | 2059b39 | 2017-10-03 17:34:10 -0400 | [diff] [blame] | 240 | |
| Jeremy Mordkoff | 34151f2 | 2017-10-04 19:45:37 -0400 | [diff] [blame] | 241 | result=$(curl -k --request PATCH \ |
| 242 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \ |
| 243 | --header 'accept: application/vnd.yang.data+json' \ |
| 244 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 245 | --header 'cache-control: no-cache' \ |
| 246 | --header 'content-type: application/vnd.yang.data+json' \ |
| 247 | --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }') |
| 248 | [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result" |
| 249 | |
| 250 | result=$(curl -k --request PATCH \ |
| 251 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \ |
| 252 | --header 'accept: application/vnd.yang.data+json' \ |
| 253 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 254 | --header 'cache-control: no-cache' \ |
| 255 | --header 'content-type: application/vnd.yang.data+json' \ |
| 256 | --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }') |
| 257 | [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result" |
| 258 | |
| Jeremy Mordkoff | f4b6e62 | 2017-10-04 12:05:41 -0400 | [diff] [blame] | 259 | lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF |
| 260 | auto lo:1 |
| 261 | iface lo:1 inet static |
| 262 | address $DEFAULT_IP |
| 263 | netmask 255.255.255.255 |
| 264 | EOF |
| 265 | lxc exec SO-ub ifup lo:1 |
| Jeremy Mordkoff | 2059b39 | 2017-10-03 17:34:10 -0400 | [diff] [blame] | 266 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 269 | function install_lxd() { |
| 270 | lxd init --auto |
| 271 | lxd waitready |
| 272 | systemctl stop lxd-bridge |
| 273 | systemctl --system daemon-reload |
| 274 | systemctl enable lxd-bridge |
| 275 | systemctl start lxd-bridge |
| 276 | } |
| 277 | |
| tierno | 53881d7 | 2017-04-25 11:58:57 +0200 | [diff] [blame] | 278 | function ask_user(){ |
| 279 | # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive |
| 280 | # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed |
| 281 | # Return: true(0) if user type 'yes'; false (1) if user type 'no' |
| 282 | read -e -p "$1" USER_CONFIRMATION |
| 283 | while true ; do |
| 284 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0 |
| 285 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1 |
| 286 | [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0 |
| 287 | [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1 |
| 288 | read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION |
| 289 | done |
| 290 | } |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 291 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 292 | UNINSTALL="" |
| 293 | DEVELOP="" |
| 294 | NAT="" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 295 | UPDATE="" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 296 | RECONFIGURE="" |
| 297 | TEST_INSTALLER="" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 298 | LXD="" |
| 299 | SHOWOPTS="" |
| 300 | COMMIT_ID="" |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 301 | ASSUME_YES="" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 302 | INSTALL_FROM_SOURCE="" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 303 | |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 304 | while getopts ":hy-:b:r:k:u:R:" o; do |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 305 | case "${o}" in |
| 306 | h) |
| 307 | usage && exit 0 |
| 308 | ;; |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 309 | b) |
| 310 | COMMIT_ID=${OPTARG} |
| 311 | ;; |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 312 | r) |
| 313 | REPOSITORY="-r ${OPTARG}" |
| 314 | ;; |
| 315 | R) |
| 316 | RELEASE="-R ${OPTARG}" |
| 317 | ;; |
| 318 | k) |
| 319 | REPOSITORY_KEY="-k ${OPTARG}" |
| 320 | ;; |
| 321 | u) |
| 322 | REPOSITORY_BASE="-u ${OPTARG}" |
| 323 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 324 | -) |
| 325 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 326 | [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 327 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| 328 | [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue |
| 329 | [ "${OPTARG}" == "nat" ] && NAT="y" && continue |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 330 | [ "${OPTARG}" == "update" ] && UPDATE="y" && continue |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 331 | [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue |
| 332 | [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 333 | [ "${OPTARG}" == "lxd" ] && LXD="y" && continue |
| 334 | [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 335 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 336 | usage && exit 1 |
| 337 | ;; |
| 338 | \?) |
| 339 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 340 | usage && exit 1 |
| 341 | ;; |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 342 | y) |
| 343 | ASSUME_YES="y" |
| 344 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 345 | *) |
| 346 | usage && exit 1 |
| 347 | ;; |
| 348 | esac |
| 349 | done |
| 350 | |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 351 | if [ -n "$SHOWOPTS" ]; then |
| 352 | echo "DEVELOP=$DEVELOP" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 353 | echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE" |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 354 | echo "UNINSTALL=$UNINSTALL" |
| 355 | echo "NAT=$NAT" |
| 356 | echo "UPDATE=$UPDATE" |
| 357 | echo "RECONFIGURE=$RECONFIGURE" |
| 358 | echo "TEST_INSTALLER=$TEST_INSTALLER" |
| 359 | echo "LXD=$LXD" |
| 360 | echo "SHOWOPTS=$SHOWOPTS" |
| 361 | echo "Install from specific refspec (-b): $COMMIT_ID" |
| 362 | exit 0 |
| 363 | fi |
| 364 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 365 | # if develop, we force master |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 366 | [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 367 | |
| Mike Marchetti | 0d56760 | 2017-09-29 14:30:28 -0400 | [diff] [blame] | 368 | # forcing source from master removed. Now only install from source when explicit |
| 369 | # [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 370 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 371 | if [ -n "$TEST_INSTALLER" ]; then |
| 372 | echo -e "\nUsing local devops repo for OSM installation" |
| 373 | TEMPDIR="$(dirname $(realpath $(dirname $0)))" |
| 374 | else |
| 375 | echo -e "\nCreating temporary dir for OSM installation" |
| 376 | TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 377 | trap 'rm -rf "$TEMPDIR"' EXIT |
| 378 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 379 | |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 380 | need_packages="git jq" |
| 381 | for package in $need_packages; do |
| 382 | echo -e "Checking required packages: $package" |
| Mike Marchetti | d8577f5 | 2017-10-19 15:27:48 -0400 | [diff] [blame] | 383 | dpkg -l $package &>/dev/null \ |
| 384 | || ! echo -e " $package not installed.\nInstalling $package requires root privileges" \ |
| 385 | || sudo apt-get install -y $package \ |
| 386 | || FATAL "failed to install $package" |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 387 | done |
| 388 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 389 | if [ -z "$TEST_INSTALLER" ]; then |
| 390 | echo -e "\nCloning devops repo temporarily" |
| 391 | git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR |
| 392 | RC_CLONE=$? |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 393 | fi |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 394 | |
| 395 | echo -e "\nGuessing the current stable release" |
| Mike Marchetti | 91df835 | 2017-10-17 13:47:48 -0400 | [diff] [blame] | 396 | 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] | 397 | [ -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] | 398 | echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" |
| 399 | [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 400 | [ -z "$TEST_INSTALLER" ] && git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 401 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 402 | OSM_DEVOPS=$TEMPDIR |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 403 | OSM_JENKINS="$TEMPDIR/jenkins" |
| 404 | . $OSM_JENKINS/common/all_funcs |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 405 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 406 | [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 |
| 407 | [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0 |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 408 | [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0 |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 409 | [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 410 | |
| 411 | #Installation starts here |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 412 | echo -e "\nInstalling OSM from refspec: $COMMIT_ID" |
| 413 | if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then |
| tierno | 53881d7 | 2017-04-25 11:58:57 +0200 | [diff] [blame] | 414 | ! 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] | 415 | fi |
| 416 | |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 417 | echo -e "\nChecking required packages: wget, curl, tar" |
| 418 | 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 |
| 419 | |
| Jokin Garay | c0a6596 | 2017-03-09 14:51:48 +0100 | [diff] [blame] | 420 | echo -e "Checking required packages: lxd" |
| garciadeblas | d880f72 | 2017-04-07 20:14:57 +0200 | [diff] [blame] | 421 | lxd --version &>/dev/null || FATAL "lxd not present, exiting." |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 422 | [ -n "$LXD" ] && echo -e "\nConfiguring lxd" && install_lxd |
| 423 | |
| Mike Marchetti | b884a46 | 2017-10-05 13:28:33 -0400 | [diff] [blame] | 424 | wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README.txt &> /dev/null |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 425 | |
| Mike Marchetti | d1e08b9 | 2017-09-29 16:14:11 -0400 | [diff] [blame] | 426 | # use local devops for containers |
| 427 | export OSM_USE_LOCAL_DEVOPS=true |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 428 | if [ -z "$INSTALL_FROM_SOURCE" ]; then |
| 429 | echo -e "\nCreating the containers and installing from binaries ..." |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 430 | $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 431 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed" |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 432 | $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed" |
| 433 | $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 434 | else #install from source |
| 435 | echo -e "\nCreating the containers and building from source ..." |
| 436 | $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')" |
| 437 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed" |
| 438 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')" |
| 439 | $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')" |
| 440 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 441 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 442 | #Install iptables-persistent and configure NAT rules |
| 443 | nat |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 444 | |
| 445 | #Configure components |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 446 | configure |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 447 | |
| Mike Marchetti | b884a46 | 2017-10-05 13:28:33 -0400 | [diff] [blame] | 448 | wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README2.txt &> /dev/null |
| Jokin Garay | 3eb9ce7 | 2017-03-09 14:48:11 +0100 | [diff] [blame] | 449 | echo -e "\nDONE" |