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