| 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" |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 33 | echo -e " -p <path>: use specified repository path for lxd images" |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 34 | echo -e " --lightweight: install lightweight build of OSM" |
| peusterm | d74dc84 | 2018-01-24 15:32:17 +0100 | [diff] [blame] | 35 | echo -e " --vimemu: additionally fetch, build, and deploy the VIM emulator as a docker container" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 36 | echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch" |
| 37 | # echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)" |
| 38 | echo -e " --nat: install only NAT rules" |
| 39 | echo -e " --noconfigure: DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules" |
| 40 | # echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch" |
| 41 | echo -e " --showopts: print chosen options and exit (only for debugging)" |
| 42 | echo -e " -y: do not prompt for confirmation, assumes yes" |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 43 | echo -e " -D <devops path> use local devops installation path" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 44 | echo -e " -h / --help: print this help" |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 47 | #Uninstall OSM: remove containers |
| 48 | function uninstall(){ |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 49 | echo -e "\nUninstalling OSM" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 50 | if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then |
| 51 | $OSM_DEVOPS/jenkins/host/clean_container RO |
| 52 | $OSM_DEVOPS/jenkins/host/clean_container VCA |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 53 | $OSM_DEVOPS/jenkins/host/clean_container MON |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 54 | $OSM_DEVOPS/jenkins/host/clean_container SO |
| 55 | #$OSM_DEVOPS/jenkins/host/clean_container UI |
| 56 | else |
| 57 | lxc stop RO && lxc delete RO |
| 58 | lxc stop VCA && lxc delete VCA |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 59 | lxc stop MON && lxc delete MON |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 60 | lxc stop SO-ub && lxc delete SO-ub |
| 61 | fi |
| garciadeblas | 54e7eed | 2018-03-19 17:38:04 +0100 | [diff] [blame] | 62 | echo -e "\nDeleting imported lxd images if they exist" |
| 63 | lxc image show osm-ro &>/dev/null && lxc image delete osm-ro |
| 64 | lxc image show osm-vca &>/dev/null && lxc image delete osm-vca |
| 65 | lxc image show osm-soui &>/dev/null && lxc image delete osm-soui |
| garciadeblas | 429b9f8 | 2018-03-20 02:09:44 +0100 | [diff] [blame] | 66 | return 0 |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| garciadeblas | 831ee56 | 2018-04-30 10:02:21 +0200 | [diff] [blame] | 69 | #Uninstall lightweight OSM: remove dockers |
| 70 | function uninstall_lightweight(){ |
| 71 | echo -e "\nUninstalling lightweight OSM" |
| 72 | docker stack rm osm |
| 73 | COUNTER=0 |
| 74 | result=11 |
| 75 | while [ ${COUNTER} -lt 30 ]; do |
| 76 | sleep 1 |
| 77 | result=$(docker stack ps osm | wc -l) |
| 78 | #echo "Dockers running: $result" |
| 79 | if [ "${result}" == "0" ]; then |
| 80 | break |
| 81 | fi |
| 82 | let COUNTER=COUNTER+1 |
| 83 | done |
| 84 | if [ "${result}" == "0" ]; then |
| 85 | echo "All dockers of the stack osm were removed" |
| 86 | else |
| 87 | FATAL "Some dockers of the stack osm could not be removed. Could not uninstall OSM in single shot. Try to uninstall again" |
| 88 | fi |
| 89 | sleep 5 |
| 90 | docker image rm osm/ro |
| 91 | docker image rm osm/lcm |
| 92 | docker image rm osm/light-ui |
| 93 | docker image rm osm/nbi |
| 94 | docker image rm osm/mon |
| 95 | docker image rm osm/pm |
| 96 | return 0 |
| 97 | } |
| 98 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 99 | #Configure NAT rules, based on the current IP addresses of containers |
| 100 | function nat(){ |
| 101 | echo -e "\nChecking required packages: iptables-persistent" |
| 102 | dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \ |
| 103 | sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent |
| 104 | echo -e "\nConfiguring NAT rules" |
| 105 | echo -e " Required root privileges" |
| 106 | sudo $OSM_DEVOPS/installers/nat_osm |
| 107 | } |
| 108 | |
| Mike Marchetti | d8577f5 | 2017-10-19 15:27:48 -0400 | [diff] [blame] | 109 | function FATAL(){ |
| 110 | echo "FATAL error: Cannot install OSM due to \"$1\"" |
| 111 | exit 1 |
| 112 | } |
| 113 | |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 114 | #Update RO, SO and UI: |
| 115 | function update(){ |
| 116 | echo -e "\nUpdating components" |
| 117 | |
| 118 | echo -e " Updating RO" |
| 119 | CONTAINER="RO" |
| 120 | MDG="RO" |
| 121 | INSTALL_FOLDER="/opt/openmano" |
| 122 | echo -e " Fetching the repo" |
| 123 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 124 | BRANCH="" |
| 125 | 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] | 126 | [ -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] | 127 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 128 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 129 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 130 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 131 | CHECKOUT_ID=$COMMIT_ID |
| 132 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 133 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 134 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 135 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 136 | else |
| 137 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 138 | fi |
| 139 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 140 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 141 | echo " Nothing to be done." |
| 142 | else |
| 143 | echo " Update required." |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 144 | lxc exec $CONTAINER -- service osm-ro stop |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 145 | lxc exec $CONTAINER -- git -C /opt/openmano stash |
| 146 | lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase |
| 147 | lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID |
| 148 | lxc exec $CONTAINER -- git -C /opt/openmano stash pop |
| 149 | lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 150 | lxc exec $CONTAINER -- service osm-ro start |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 151 | fi |
| 152 | echo |
| 153 | |
| 154 | echo -e " Updating SO and UI" |
| 155 | CONTAINER="SO-ub" |
| 156 | MDG="SO" |
| 157 | INSTALL_FOLDER="" # To be filled in |
| 158 | echo -e " Fetching the repo" |
| 159 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 160 | BRANCH="" |
| 161 | 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] | 162 | [ -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] | 163 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 164 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 165 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 166 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 167 | CHECKOUT_ID=$COMMIT_ID |
| 168 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 169 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 170 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 171 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 172 | else |
| 173 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 174 | fi |
| 175 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 176 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 177 | echo " Nothing to be done." |
| 178 | else |
| 179 | echo " Update required." |
| 180 | # Instructions to be added |
| 181 | # lxc exec SO-ub -- ... |
| 182 | fi |
| 183 | echo |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 184 | echo -e "Updating MON Container" |
| 185 | CONTAINER="MON" |
| 186 | MDG="MON" |
| 187 | INSTALL_FOLDER="/root/MON" |
| 188 | echo -e " Fetching the repo" |
| 189 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 190 | BRANCH="" |
| 191 | BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'` |
| 192 | [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'" |
| 193 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 194 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 195 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 196 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 197 | CHECKOUT_ID=$COMMIT_ID |
| 198 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 199 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 200 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 201 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 202 | else |
| 203 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 204 | fi |
| 205 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 206 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 207 | echo " Nothing to be done." |
| 208 | else |
| 209 | echo " Update required." |
| 210 | fi |
| 211 | echo |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 212 | } |
| 213 | |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 214 | function so_is_up() { |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 215 | if [ -n "$1" ]; then |
| 216 | SO_IP=$1 |
| 217 | else |
| 218 | SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'` |
| 219 | fi |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 220 | time=0 |
| 221 | step=5 |
| 222 | timelength=300 |
| 223 | while [ $time -le $timelength ] |
| 224 | do |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 225 | if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \ |
| 226 | -H 'accept: application/vnd.yang.data+json' \ |
| 227 | -H 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 228 | -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 ]] |
| 229 | then |
| 230 | echo "RW.Restconf running....SO is up" |
| 231 | return 0 |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 232 | fi |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 233 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 234 | sleep $step |
| 235 | echo -n "." |
| 236 | time=$((time+step)) |
| 237 | done |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 238 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 239 | FATAL "OSM Failed to startup. SO failed to startup" |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 240 | } |
| 241 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 242 | function vca_is_up() { |
| 243 | if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then |
| 244 | echo "VCA is up and running" |
| 245 | return 0 |
| 246 | fi |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 247 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 248 | FATAL "OSM Failed to startup. VCA failed to startup" |
| 249 | } |
| 250 | |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 251 | function mon_is_up() { |
| 252 | if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then |
| 253 | echo "MON is up and running" |
| 254 | return 0 |
| 255 | fi |
| 256 | |
| 257 | FATAL "OSM Failed to startup. MON failed to startup" |
| 258 | } |
| 259 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 260 | function ro_is_up() { |
| 261 | if [ -n "$1" ]; then |
| 262 | RO_IP=$1 |
| 263 | else |
| 264 | RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'` |
| 265 | fi |
| 266 | time=0 |
| 267 | step=2 |
| 268 | timelength=20 |
| 269 | while [ $time -le $timelength ]; do |
| 270 | if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then |
| 271 | echo "RO is up and running" |
| 272 | return 0 |
| 273 | fi |
| 274 | sleep $step |
| 275 | echo -n "." |
| 276 | time=$((time+step)) |
| 277 | done |
| 278 | |
| 279 | FATAL "OSM Failed to startup. RO failed to startup" |
| 280 | } |
| 281 | |
| 282 | |
| 283 | function configure_RO(){ |
| 284 | . $OSM_DEVOPS/installers/export_ips |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 285 | echo -e " Configuring RO" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 286 | lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg |
| 287 | lxc exec RO -- service osm-ro restart |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 288 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 289 | ro_is_up |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 290 | |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 291 | lxc exec RO -- openmano tenant-delete -f osm >/dev/null |
| garciadeblas | 1b7107e | 2017-12-21 15:32:02 +0100 | [diff] [blame] | 292 | lxc exec RO -- openmano tenant-create osm > /dev/null |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 293 | lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc |
| tierno | 15f4f22 | 2017-06-14 13:23:01 +0200 | [diff] [blame] | 294 | lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc |
| garciadeblas | 1b7107e | 2017-12-21 15:32:02 +0100 | [diff] [blame] | 295 | lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc' |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 296 | } |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 297 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 298 | function configure_VCA(){ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 299 | echo -e " Configuring VCA" |
| 300 | JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 301 | 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] | 302 | } |
| 303 | |
| 304 | function configure_SOUI(){ |
| 305 | . $OSM_DEVOPS/installers/export_ips |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 306 | JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| garciadeblas | 1b7107e | 2017-12-21 15:32:02 +0100 | [diff] [blame] | 307 | RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'` |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 308 | |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 309 | echo -e " Configuring MON" |
| 310 | #Information to be added about SO socket for logging |
| 311 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 312 | echo -e " Configuring SO" |
| 313 | sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP |
| garciadeblas | 2f4c93b | 2017-04-10 18:12:12 +0200 | [diff] [blame] | 314 | 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] | 315 | # make journaling persistent |
| 316 | lxc exec SO-ub -- mkdir -p /var/log/journal |
| 317 | lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal |
| 318 | lxc exec SO-ub -- systemctl restart systemd-journald |
| 319 | |
| Jeremy Mordkoff | 3b3edea | 2017-10-03 16:21:56 -0400 | [diff] [blame] | 320 | echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad |
| 321 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 322 | lxc exec SO-ub -- systemctl restart launchpad |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 323 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 324 | so_is_up $SO_CONTAINER_IP |
| 325 | |
| 326 | #delete existing config agent (could be there on reconfigure) |
| 327 | curl -k --request DELETE \ |
| 328 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \ |
| 329 | --header 'accept: application/vnd.yang.data+json' \ |
| 330 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 331 | --header 'cache-control: no-cache' \ |
| 332 | --header 'content-type: application/vnd.yang.data+json' &> /dev/null |
| 333 | |
| 334 | result=$(curl -k --request POST \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 335 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ |
| 336 | --header 'accept: application/vnd.yang.data+json' \ |
| 337 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 338 | --header 'cache-control: no-cache' \ |
| 339 | --header 'content-type: application/vnd.yang.data+json' \ |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 340 | --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}') |
| 341 | [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 342 | |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 343 | #R1/R2 config line |
| 344 | #result=$(curl -k --request PUT \ |
| 345 | # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \ |
| 346 | # --header 'accept: application/vnd.yang.data+json' \ |
| 347 | # --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 348 | # --header 'cache-control: no-cache' \ |
| 349 | # --header 'content-type: application/vnd.yang.data+json' \ |
| 350 | # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }') |
| 351 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 352 | result=$(curl -k --request PUT \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 353 | --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 354 | --header 'accept: application/vnd.yang.data+json' \ |
| 355 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 356 | --header 'cache-control: no-cache' \ |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 357 | --header 'content-type: application/vnd.yang.data+json' \ |
| Mike Marchetti | 397a65d | 2017-10-02 22:36:16 -0400 | [diff] [blame] | 358 | --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] | 359 | [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result" |
| Jeremy Mordkoff | 2059b39 | 2017-10-03 17:34:10 -0400 | [diff] [blame] | 360 | |
| Jeremy Mordkoff | 34151f2 | 2017-10-04 19:45:37 -0400 | [diff] [blame] | 361 | result=$(curl -k --request PATCH \ |
| 362 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \ |
| 363 | --header 'accept: application/vnd.yang.data+json' \ |
| 364 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 365 | --header 'cache-control: no-cache' \ |
| 366 | --header 'content-type: application/vnd.yang.data+json' \ |
| 367 | --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }') |
| 368 | [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result" |
| 369 | |
| 370 | result=$(curl -k --request PATCH \ |
| 371 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \ |
| 372 | --header 'accept: application/vnd.yang.data+json' \ |
| 373 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 374 | --header 'cache-control: no-cache' \ |
| 375 | --header 'content-type: application/vnd.yang.data+json' \ |
| 376 | --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }') |
| 377 | [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result" |
| 378 | |
| Jeremy Mordkoff | f4b6e62 | 2017-10-04 12:05:41 -0400 | [diff] [blame] | 379 | lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF |
| 380 | auto lo:1 |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 381 | iface lo:1 inet static |
| Jeremy Mordkoff | f4b6e62 | 2017-10-04 12:05:41 -0400 | [diff] [blame] | 382 | address $DEFAULT_IP |
| 383 | netmask 255.255.255.255 |
| 384 | EOF |
| 385 | lxc exec SO-ub ifup lo:1 |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 386 | } |
| Jeremy Mordkoff | 2059b39 | 2017-10-03 17:34:10 -0400 | [diff] [blame] | 387 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 388 | #Configure RO, VCA, and SO with the initial configuration: |
| 389 | # RO -> tenant:osm, logs to be sent to SO |
| 390 | # VCA -> juju-password |
| 391 | # SO -> route to Juju Controller, add RO account, add VCA account |
| 392 | function configure(){ |
| 393 | #Configure components |
| 394 | echo -e "\nConfiguring components" |
| 395 | configure_RO |
| 396 | configure_VCA |
| 397 | configure_SOUI |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 398 | } |
| 399 | |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 400 | function install_lxd() { |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 401 | sudo apt-get update |
| 402 | sudo apt-get install -y lxd |
| 403 | newgrp lxd |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 404 | lxd init --auto |
| 405 | lxd waitready |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 406 | lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false |
| 407 | DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}') |
| garciadeblas | 749af85 | 2018-04-19 18:43:50 +0200 | [diff] [blame] | 408 | DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 409 | lxc profile device set default eth0 mtu $DEFAULT_MTU |
| 410 | #sudo systemctl stop lxd-bridge |
| 411 | #sudo systemctl --system daemon-reload |
| 412 | #sudo systemctl enable lxd-bridge |
| 413 | #sudo systemctl start lxd-bridge |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| tierno | 53881d7 | 2017-04-25 11:58:57 +0200 | [diff] [blame] | 416 | function ask_user(){ |
| 417 | # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive |
| 418 | # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed |
| 419 | # Return: true(0) if user type 'yes'; false (1) if user type 'no' |
| 420 | read -e -p "$1" USER_CONFIRMATION |
| 421 | while true ; do |
| 422 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0 |
| 423 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1 |
| 424 | [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0 |
| 425 | [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1 |
| 426 | read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION |
| 427 | done |
| 428 | } |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 429 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 430 | function launch_container_from_lxd(){ |
| 431 | export OSM_MDG=$1 |
| 432 | OSM_load_config |
| 433 | export OSM_BASE_IMAGE=$2 |
| 434 | if ! container_exists $OSM_BUILD_CONTAINER; then |
| 435 | CONTAINER_OPTS="" |
| 436 | [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true" |
| 437 | [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true" |
| 438 | create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS |
| 439 | wait_container_up $OSM_BUILD_CONTAINER |
| 440 | fi |
| 441 | } |
| 442 | |
| 443 | function install_osmclient(){ |
| 444 | CLIENT_RELEASE=${RELEASE#"-R "} |
| 445 | CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" |
| garciadeblas | a9ef099 | 2018-04-19 11:18:06 +0200 | [diff] [blame] | 446 | CLIENT_REPOSITORY=${REPOSITORY#"-r "} |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 447 | [ -z "$REPOSITORY_BASE" ] && REPOSITORY_BASE="-u https://osm-download.etsi.org/repository/osm/debian" |
| 448 | CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "} |
| 449 | key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY |
| 450 | curl $key_location | sudo apt-key add - |
| 451 | sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient" |
| 452 | sudo apt-get update |
| garciadeblas | 8db0ffd | 2018-04-20 11:56:34 +0200 | [diff] [blame] | 453 | sudo apt-get install -y python-pip |
| 454 | sudo -H pip install pip==9.0.3 |
| 455 | sudo -H pip install python-magic |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 456 | sudo apt-get install -y python-osmclient |
| garciadeblas | b7d8d80 | 2018-04-18 16:39:17 +0200 | [diff] [blame] | 457 | #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc |
| 458 | #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc |
| 459 | #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc |
| garciadeblas | feef887 | 2018-04-19 13:35:25 +0200 | [diff] [blame] | 460 | [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'` |
| 461 | [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'` |
| 462 | [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=localhost |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 463 | echo -e "\nOSM client installed" |
| 464 | echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:" |
| 465 | echo " export OSM_HOSTNAME=${OSM_HOSTNAME}" |
| garciadeblas | b7d8d80 | 2018-04-18 16:39:17 +0200 | [diff] [blame] | 466 | [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True" |
| 467 | [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}" |
| 468 | return 0 |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | function install_from_lxdimages(){ |
| 472 | LXD_RELEASE=${RELEASE#"-R "} |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 473 | if [ -n "$LXD_REPOSITORY_PATH" ]; then |
| 474 | LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH" |
| 475 | else |
| 476 | LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")" |
| 477 | trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT |
| 478 | fi |
| garciadeblas | 54e7eed | 2018-03-19 17:38:04 +0100 | [diff] [blame] | 479 | echo -e "\nDeleting previous lxd images if they exist" |
| 480 | lxc image show osm-ro &>/dev/null && lxc image delete osm-ro |
| 481 | lxc image show osm-vca &>/dev/null && lxc image delete osm-vca |
| 482 | lxc image show osm-soui &>/dev/null && lxc image delete osm-soui |
| 483 | echo -e "\nImporting osm-ro" |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 484 | [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 485 | lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro |
| 486 | rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz |
| garciadeblas | 54e7eed | 2018-03-19 17:38:04 +0100 | [diff] [blame] | 487 | echo -e "\nImporting osm-vca" |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 488 | [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 489 | lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca |
| 490 | rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz |
| garciadeblas | 54e7eed | 2018-03-19 17:38:04 +0100 | [diff] [blame] | 491 | echo -e "\nImporting osm-soui" |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 492 | [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 493 | lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui |
| 494 | rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz |
| 495 | launch_container_from_lxd RO osm-ro |
| 496 | ro_is_up && track RO |
| 497 | launch_container_from_lxd VCA osm-vca |
| 498 | vca_is_up && track VCA |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 499 | launch_container_from_lxd MON osm-mon |
| 500 | mon_is_up && track MON |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 501 | launch_container_from_lxd SO osm-soui |
| 502 | #so_is_up && track SOUI |
| 503 | track SOUI |
| 504 | } |
| 505 | |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 506 | function install_docker_ce() { |
| 507 | # installs and configures Docker CE |
| 508 | echo "Installing Docker CE ..." |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 509 | sudo apt-get -qq update |
| 510 | sudo apt-get install -y apt-transport-https ca-certificates software-properties-common |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 511 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - |
| 512 | sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |
| 513 | sudo apt-get -qq update |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 514 | sudo apt-get install -y docker-ce |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 515 | echo "Adding user to group 'docker'" |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 516 | sudo groupadd -f docker |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 517 | sudo usermod -aG docker $USER |
| 518 | echo "... Docker CE installation done" |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 519 | sleep 2 |
| 520 | sudo service docker restart |
| 521 | echo "... restarted Docker service" |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 522 | } |
| 523 | |
| garciadeblas | 4101260 | 2018-04-23 17:23:35 +0200 | [diff] [blame] | 524 | function install_docker_compose() { |
| 525 | # installs and configures docker-compose |
| 526 | echo "Installing Docker Compose ..." |
| 527 | sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose |
| 528 | sudo chmod +x /usr/local/bin/docker-compose |
| 529 | echo "... Docker Compose installation done" |
| 530 | } |
| 531 | |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 532 | function install_juju() { |
| 533 | echo "Installing juju" |
| 534 | sudo snap install juju --classic |
| 535 | sudo dpkg-reconfigure -p medium lxd |
| garciadeblas | db79732 | 2018-05-04 11:03:31 +0200 | [diff] [blame] | 536 | sg lxd -c "juju bootstrap localhost osm" |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 537 | echo "Finished installation of juju" |
| 538 | } |
| 539 | |
| 540 | function generate_docker_images() { |
| 541 | echo "Pulling and generating docker images" |
| 542 | newgrp docker << EONG |
| 543 | docker pull wurstmeister/kafka |
| 544 | docker pull wurstmeister/zookeeper |
| 545 | docker pull mongo |
| garciadeblas | 4101260 | 2018-04-23 17:23:35 +0200 | [diff] [blame] | 546 | docker pull mysql:5 |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 547 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON |
| 548 | docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon || ! echo "cannot build MON docker image" >&2 |
| 549 | docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm || ! echo "cannot build PM docker image" >&2 |
| 550 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI |
| Mike Marchetti | 00b76aa | 2018-04-18 14:09:50 -0400 | [diff] [blame] | 551 | docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi || ! echo "cannot build NBI docker image" >&2 |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 552 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO |
| 553 | docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro || ! echo "cannot build RO docker image" >&2 |
| 554 | docker build ${LWTEMPDIR}/RO/lcm -t osm/lcm || ! echo "cannot build LCM docker image" >&2 |
| 555 | git -C ${LWTEMPDIR} clone https://github.com/superfluidity/osm-light-ui.git |
| 556 | docker build ${LWTEMPDIR}/osm-light-ui -t osm/light-ui -f ${LWTEMPDIR}/osm-light-ui/code/docker/Dockerfile |
| 557 | EONG |
| 558 | echo "Finished generation of docker images" |
| 559 | } |
| 560 | |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 561 | function generate_docker_env_files() { |
| 562 | echo "Generating docker env files" |
| 563 | OSMLCM_VCA_HOST=`juju show-controller|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'` |
| garciadeblas | 7077be6 | 2018-05-03 15:06:24 +0200 | [diff] [blame] | 564 | OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'` |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 565 | MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32` |
| garciadeblas | 5de942e | 2018-04-19 15:25:23 +0200 | [diff] [blame] | 566 | echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" |sudo tee ${OSM_DEVOPS}/installers/docker/lcm.env |
| 567 | echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" |sudo tee -a ${OSM_DEVOPS}/installers/docker/lcm.env |
| 568 | echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro-db.env |
| 569 | echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |sudo tee ${OSM_DEVOPS}/installers/docker/ro.env |
| 570 | echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |sudo tee ${OSM_DEVOPS}/installers/docker/mon.env |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 571 | echo "Finished generation of docker env files" |
| 572 | } |
| 573 | |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 574 | function deploy_lightweight() { |
| 575 | echo "Deploying lightweight build" |
| 576 | newgrp docker << EONG |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 577 | docker swarm init --advertise-addr ${DEFAULT_IP} |
| garciadeblas | 749af85 | 2018-04-19 18:43:50 +0200 | [diff] [blame] | 578 | docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 579 | docker stack deploy -c ${OSM_DEVOPS}/installers/docker/docker-compose.yaml osm |
| garciadeblas | 4101260 | 2018-04-23 17:23:35 +0200 | [diff] [blame] | 580 | #docker-compose -f /usr/share/osm-devops/installers/docker/docker-compose.yaml up -d |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 581 | EONG |
| 582 | echo "Finished deployment of lightweight build" |
| 583 | } |
| 584 | |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 585 | function install_lightweight() { |
| 586 | echo "Installing lightweight build of OSM" |
| 587 | LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")" |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 588 | trap 'rm -rf "${LWTEMPDIR}"' EXIT |
| 589 | DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'` |
| 590 | DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` |
| garciadeblas | 749af85 | 2018-04-19 18:43:50 +0200 | [diff] [blame] | 591 | DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| garciadeblas | 63ac902 | 2018-05-03 11:49:00 +0200 | [diff] [blame] | 592 | need_packages_lw="lxd" |
| 593 | echo -e "Checking required packages: $need_packages_lw" |
| 594 | dpkg -l $need_packages_lw &>/dev/null \ |
| 595 | || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ |
| 596 | || sudo apt-get update \ |
| 597 | || FATAL "failed to run apt-get update" |
| 598 | dpkg -l $need_packages_lw &>/dev/null \ |
| 599 | || ! echo -e "Installing $need_packages_lw requires root privileges." \ |
| 600 | || sudo apt-get install -y $need_packages_lw \ |
| 601 | || FATAL "failed to install $need_packages_lw" |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 602 | install_juju |
| 603 | install_docker_ce |
| garciadeblas | 4101260 | 2018-04-23 17:23:35 +0200 | [diff] [blame] | 604 | #install_docker_compose |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 605 | generate_docker_images |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 606 | generate_docker_env_files |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 607 | deploy_lightweight |
| garciadeblas | b7d8d80 | 2018-04-18 16:39:17 +0200 | [diff] [blame] | 608 | install_osmclient |
| 609 | return 0 |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 610 | } |
| 611 | |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 612 | function install_vimemu() { |
| 613 | # install Docker |
| 614 | install_docker_ce |
| 615 | # clone vim-emu repository (attention: branch is currently master only) |
| 616 | echo "Cloning vim-emu repository ..." |
| 617 | git clone https://osm.etsi.org/gerrit/osm/vim-emu.git |
| 618 | # build vim-emu docker |
| 619 | echo "Building vim-emu Docker container..." |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 620 | sudo docker build -t vim-emu-img -f vim-emu/Dockerfile vim-emu/ |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 621 | # start vim-emu container as daemon |
| 622 | echo "Starting vim-emu Docker container 'vim-emu' ..." |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 623 | sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 624 | echo "Waiting for 'vim-emu' container to start ..." |
| 625 | sleep 5 |
| peusterm | e2c017e | 2018-02-07 11:51:11 +0100 | [diff] [blame] | 626 | export VIMEMU_HOSTNAME=$(sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu) |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 627 | echo "vim-emu running at ${VIMEMU_HOSTNAME} ..." |
| peusterm | d74dc84 | 2018-01-24 15:32:17 +0100 | [diff] [blame] | 628 | echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:" |
| 629 | echo " export OSM_HOSTNAME=${OSM_HOSTNAME}" |
| 630 | echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}" |
| 631 | echo -e "You might be interested in adding the following vim-emu env variables to your .bashrc file:" |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 632 | echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}" |
| 633 | echo -e "\nTo add the emulated VIM to OSM you should do:" |
| garciadeblas | 46e9959 | 2018-04-16 13:32:02 +0200 | [diff] [blame] | 634 | echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack" |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 635 | } |
| 636 | |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 637 | function dump_vars(){ |
| 638 | echo "DEVELOP=$DEVELOP" |
| 639 | echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE" |
| 640 | echo "UNINSTALL=$UNINSTALL" |
| 641 | echo "NAT=$NAT" |
| 642 | echo "UPDATE=$UPDATE" |
| 643 | echo "RECONFIGURE=$RECONFIGURE" |
| 644 | echo "TEST_INSTALLER=$TEST_INSTALLER" |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 645 | echo "INSTALL_VIMEMU=$INSTALL_VIMEMU" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 646 | echo "INSTALL_LXD=$INSTALL_LXD" |
| 647 | echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES" |
| 648 | echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE" |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 649 | echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH" |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 650 | echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 651 | echo "RELEASE=$RELEASE" |
| 652 | echo "REPOSITORY=$REPOSITORY" |
| 653 | echo "REPOSITORY_BASE=$REPOSITORY_BASE" |
| 654 | echo "REPOSITORY_KEY=$REPOSITORY_KEY" |
| 655 | echo "NOCONFIGURE=$NOCONFIGURE" |
| 656 | echo "SHOWOPTS=$SHOWOPTS" |
| 657 | echo "Install from specific refspec (-b): $COMMIT_ID" |
| 658 | } |
| 659 | |
| 660 | function track(){ |
| 661 | ctime=`date +%s` |
| 662 | duration=$((ctime - SESSION_ID)) |
| 663 | url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}" |
| 664 | #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}" |
| 665 | event_name="bin" |
| 666 | [ -n "$INSTALL_FROM_SOURCE" ] && event_name="src" |
| 667 | [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd" |
| 668 | event_name="${event_name}_$1" |
| 669 | url="${url}&event=${event_name}&ce_duration=${duration}" |
| 670 | wget -q -O /dev/null $url |
| 671 | } |
| 672 | |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 673 | UNINSTALL="" |
| 674 | DEVELOP="" |
| 675 | NAT="" |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 676 | UPDATE="" |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 677 | RECONFIGURE="" |
| 678 | TEST_INSTALLER="" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 679 | INSTALL_LXD="" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 680 | SHOWOPTS="" |
| 681 | COMMIT_ID="" |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 682 | ASSUME_YES="" |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 683 | INSTALL_FROM_SOURCE="" |
| garciadeblas | 8244229 | 2017-11-16 14:48:12 +0100 | [diff] [blame] | 684 | RELEASE="-R ReleaseTHREE" |
| garciadeblas | a9ef099 | 2018-04-19 11:18:06 +0200 | [diff] [blame] | 685 | REPOSITORY="-r stable" |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 686 | INSTALL_VIMEMU="" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 687 | INSTALL_FROM_LXDIMAGES="" |
| 688 | LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd" |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 689 | LXD_REPOSITORY_PATH="" |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 690 | INSTALL_LIGHTWEIGHT="" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 691 | NOCONFIGURE="" |
| Mike Marchetti | ca56c64 | 2017-12-16 16:04:52 -0500 | [diff] [blame] | 692 | RELEASE_DAILY="" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 693 | SESSION_ID=`date +%s` |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 694 | OSM_DEVOPS= |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 695 | |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 696 | while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 697 | case "${o}" in |
| 698 | h) |
| 699 | usage && exit 0 |
| 700 | ;; |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 701 | b) |
| 702 | COMMIT_ID=${OPTARG} |
| 703 | ;; |
| Mike Marchetti | 425f8ce | 2017-06-15 13:02:16 -0400 | [diff] [blame] | 704 | r) |
| 705 | REPOSITORY="-r ${OPTARG}" |
| 706 | ;; |
| 707 | R) |
| 708 | RELEASE="-R ${OPTARG}" |
| 709 | ;; |
| 710 | k) |
| 711 | REPOSITORY_KEY="-k ${OPTARG}" |
| 712 | ;; |
| 713 | u) |
| 714 | REPOSITORY_BASE="-u ${OPTARG}" |
| 715 | ;; |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 716 | l) |
| 717 | LXD_REPOSITORY_BASE="${OPTARG}" |
| 718 | ;; |
| garciadeblas | fc8f029 | 2018-04-02 16:55:29 +0200 | [diff] [blame] | 719 | p) |
| 720 | LXD_REPOSITORY_PATH="${OPTARG}" |
| 721 | ;; |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 722 | D) |
| 723 | OSM_DEVOPS="${OPTARG}" |
| 724 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 725 | -) |
| 726 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 727 | [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 728 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| 729 | [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue |
| 730 | [ "${OPTARG}" == "nat" ] && NAT="y" && continue |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 731 | [ "${OPTARG}" == "update" ] && UPDATE="y" && continue |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 732 | [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue |
| 733 | [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 734 | [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue |
| 735 | [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 736 | [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 737 | [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 738 | [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 739 | [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue |
| Mike Marchetti | ca56c64 | 2017-12-16 16:04:52 -0500 | [diff] [blame] | 740 | [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 741 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 742 | usage && exit 1 |
| 743 | ;; |
| 744 | \?) |
| 745 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 746 | usage && exit 1 |
| 747 | ;; |
| tierno | 2cc8e25 | 2017-03-08 17:12:05 +0100 | [diff] [blame] | 748 | y) |
| 749 | ASSUME_YES="y" |
| 750 | ;; |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 751 | *) |
| 752 | usage && exit 1 |
| 753 | ;; |
| 754 | esac |
| 755 | done |
| 756 | |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 757 | if [ -n "$SHOWOPTS" ]; then |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 758 | dump_vars |
| garciadeblas | a6ff986 | 2017-04-07 02:00:29 +0200 | [diff] [blame] | 759 | exit 0 |
| 760 | fi |
| 761 | |
| Mike Marchetti | ca56c64 | 2017-12-16 16:04:52 -0500 | [diff] [blame] | 762 | [ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master" |
| 763 | |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 764 | # if develop, we force master |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 765 | [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| Mike Marchetti | 6930bc0 | 2017-05-31 16:33:02 -0400 | [diff] [blame] | 766 | |
| Mike Marchetti | 0d56760 | 2017-09-29 14:30:28 -0400 | [diff] [blame] | 767 | # forcing source from master removed. Now only install from source when explicit |
| 768 | # [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y" |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 769 | |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 770 | if [ -z "$OSM_DEVOPS" ]; then |
| 771 | if [ -n "$TEST_INSTALLER" ]; then |
| 772 | echo -e "\nUsing local devops repo for OSM installation" |
| 773 | TEMPDIR="$(dirname $(realpath $(dirname $0)))" |
| 774 | else |
| 775 | echo -e "\nCreating temporary dir for OSM installation" |
| 776 | TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 777 | trap 'rm -rf "$TEMPDIR"' EXIT |
| 778 | fi |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 779 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 780 | |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 781 | need_packages="git jq wget curl tar" |
| 782 | echo -e "Checking required packages: $need_packages" |
| 783 | dpkg -l $need_packages &>/dev/null \ |
| 784 | || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ |
| 785 | || sudo apt-get update \ |
| 786 | || FATAL "failed to run apt-get update" |
| 787 | dpkg -l $need_packages &>/dev/null \ |
| 788 | || ! echo -e "Installing $need_packages requires root privileges." \ |
| 789 | || sudo apt-get install -y $need_packages \ |
| 790 | || FATAL "failed to install $need_packages" |
| Mike Marchetti | 2b95128 | 2017-10-10 15:43:15 -0400 | [diff] [blame] | 791 | |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 792 | if [ -z "$OSM_DEVOPS" ]; then |
| 793 | if [ -z "$TEST_INSTALLER" ]; then |
| 794 | echo -e "\nCloning devops repo temporarily" |
| 795 | git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR |
| 796 | RC_CLONE=$? |
| 797 | fi |
| 798 | |
| 799 | echo -e "\nGuessing the current stable release" |
| 800 | LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1` |
| 801 | [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0 |
| 802 | echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" |
| 803 | [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 804 | |
| 805 | if [ -n "$RELEASE_DAILY" ]; then |
| 806 | echo "Using master/HEAD devops" |
| 807 | git -C $TEMPDIR checkout master |
| 808 | elif [ -z "$TEST_INSTALLER" ]; then |
| 809 | git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS |
| 810 | fi |
| 811 | OSM_DEVOPS=$TEMPDIR |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 812 | fi |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 813 | |
| Mike Marchetti | 4de4849 | 2018-04-05 12:44:01 -0400 | [diff] [blame] | 814 | OSM_JENKINS="$OSM_DEVOPS/jenkins" |
| garciadeblas | 0fe45dd | 2016-10-04 07:54:17 +0200 | [diff] [blame] | 815 | . $OSM_JENKINS/common/all_funcs |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 816 | |
| garciadeblas | 831ee56 | 2018-04-30 10:02:21 +0200 | [diff] [blame] | 817 | [ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0 |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 818 | [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 |
| 819 | [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0 |
| garciadeblas | 2a38273 | 2017-01-12 12:11:14 +0100 | [diff] [blame] | 820 | [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0 |
| garciadeblas | d8718f1 | 2016-10-30 19:39:01 +0100 | [diff] [blame] | 821 | [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 822 | |
| 823 | #Installation starts here |
| garciadeblas | 14097dc | 2018-04-04 18:36:32 +0200 | [diff] [blame] | 824 | [ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0 |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 825 | echo -e "\nInstalling OSM from refspec: $COMMIT_ID" |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 826 | if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then |
| tierno | 53881d7 | 2017-04-25 11:58:57 +0200 | [diff] [blame] | 827 | ! 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] | 828 | fi |
| 829 | |
| Jokin Garay | c0a6596 | 2017-03-09 14:51:48 +0100 | [diff] [blame] | 830 | echo -e "Checking required packages: lxd" |
| garciadeblas | d880f72 | 2017-04-07 20:14:57 +0200 | [diff] [blame] | 831 | lxd --version &>/dev/null || FATAL "lxd not present, exiting." |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 832 | [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd |
| garciadeblas | 2a5a651 | 2016-12-19 10:19:52 +0100 | [diff] [blame] | 833 | |
| Mike Marchetti | 02a533a | 2018-04-05 21:23:33 -0400 | [diff] [blame] | 834 | wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 835 | track start |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 836 | |
| Mike Marchetti | d1e08b9 | 2017-09-29 16:14:11 -0400 | [diff] [blame] | 837 | # use local devops for containers |
| 838 | export OSM_USE_LOCAL_DEVOPS=true |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 839 | if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 840 | echo -e "\nCreating the containers and building from source ..." |
| 841 | $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] | 842 | ro_is_up && track RO |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 843 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 844 | vca_is_up && track VCA |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 845 | $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed" |
| 846 | mon_is_up && track MON |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 847 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')" |
| 848 | $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] | 849 | #so_is_up && track SOUI |
| 850 | track SOUI |
| 851 | elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo |
| 852 | echo -e "\nInstalling from lxd images ..." |
| 853 | install_from_lxdimages |
| 854 | else #install from binaries |
| 855 | echo -e "\nCreating the containers and installing from binaries ..." |
| 856 | $OSM_DEVOPS/jenkins/host/install RO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "RO install failed" |
| 857 | ro_is_up && track RO |
| 858 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed" |
| 859 | vca_is_up && track VCA |
| prithiv | 4a98a04 | 2017-12-05 23:19:39 +0000 | [diff] [blame] | 860 | $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed" |
| 861 | mon_is_up && track MON |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 862 | $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed" |
| 863 | $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed" |
| 864 | #so_is_up && track SOUI |
| 865 | track SOUI |
| garciadeblas | a1fc457 | 2017-04-24 19:08:21 +0200 | [diff] [blame] | 866 | fi |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 867 | |
| garciadeblas | 55490d4 | 2016-10-29 14:22:03 +0200 | [diff] [blame] | 868 | #Install iptables-persistent and configure NAT rules |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 869 | [ -z "$NOCONFIGURE" ] && nat |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 870 | |
| 871 | #Configure components |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 872 | [ -z "$NOCONFIGURE" ] && configure |
| 873 | |
| 874 | #Install osmclient |
| 875 | [ -z "$NOCONFIGURE" ] && install_osmclient |
| garciadeblas | 93c6131 | 2016-09-28 15:12:48 +0200 | [diff] [blame] | 876 | |
| peusterm | 3a3e7a5 | 2017-12-22 13:10:54 +0100 | [diff] [blame] | 877 | #Install vim-emu (optional) |
| 878 | if [ -n "$INSTALL_VIMEMU" ]; then |
| 879 | echo -e "\nInstalling vim-emu ..." |
| 880 | install_vimemu |
| 881 | fi |
| 882 | |
| Mike Marchetti | 02a533a | 2018-04-05 21:23:33 -0400 | [diff] [blame] | 883 | wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 884 | track end |
| Jokin Garay | 3eb9ce7 | 2017-03-09 14:48:11 +0100 | [diff] [blame] | 885 | echo -e "\nDONE" |
| garciadeblas | 0d934c1 | 2017-11-17 15:39:17 +0100 | [diff] [blame] | 886 | |