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