blob: 222ccad45c1aa23e2faf60e41e385dc49640df91 [file] [log] [blame]
Leslie Giles1a1c87e2016-09-27 09:51:56 -04001#!/usr/bin/env bash
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04002#
3# Copyright 2016 RIFT.IO Inc
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
Leslie Giles1a1c87e2016-09-27 09:51:56 -040017# Author(s): Jeremy Mordkoff, Lezz Giles
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040018# Creation Date: 08/29/2016
19#
20#
21
22# BUILD.sh
23#
24# This is a top-level build script for RIFT.io
25#
Leslie Giles1a1c87e2016-09-27 09:51:56 -040026# Arguments and options: use -h or --help
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040027#
28# dependencies -- requires sudo rights
29
Leslie Giles202103e2016-09-27 13:23:40 -040030# Defensive bash programming flags
31set -o errexit # Exit on any error
32trap 'echo ERROR: Command failed: \"$BASH_COMMAND\"' ERR
33set -o nounset # Expanding an unset variable is an error. Variables must be
34 # set before they can be used.
35
Leslie Giles1a1c87e2016-09-27 09:51:56 -040036###############################################################################
37# Options and arguments
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040038
Leslie Giles202103e2016-09-27 13:23:40 -040039# There
40params="$(getopt -o suhb: -l install-so,install-ui,no-mkcontainer,build-ui:,help --name "$0" -- "$@")"
Leslie Giles1a1c87e2016-09-27 09:51:56 -040041if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
42
43eval set -- $params
44
45installSO=false
46installUI=false
Leslie Giles202103e2016-09-27 13:23:40 -040047runMkcontainer=true
Leslie Giles1a1c87e2016-09-27 09:51:56 -040048UIPathToBuild=
49
50while true; do
51 case "$1" in
52 -s|--install-so) installSO=true; shift;;
53 -u|--install-ui) installUI=true; shift;;
54 -b|--build-ui) shift; UIPathToBuild=$1; shift;;
Leslie Giles202103e2016-09-27 13:23:40 -040055 --no-mkcontainer) runMkcontainer=false; shift;;
Leslie Giles1a1c87e2016-09-27 09:51:56 -040056 -h|--help)
57 echo
58 echo "NAME:"
59 echo " $0"
60 echo
61 echo "SYNOPSIS:"
62 echo " $0 -h|--help"
63 echo " $0 [-s] [-u|-b PATH-TO-UI-REPO] [PLATFORM_REPOSITORY] [PLATFORM_VERSION]"
64 echo
65 echo "DESCRIPTION:"
66 echo " Prepare current system to run SO and UI. By default, the system"
67 echo " is set up to support building SO and UI; optionally, either or"
68 echo " both SO and UI can be installed from a Debian package repository."
69 echo
70 echo " -s|--install-so: install SO from package"
71 echo " -u|--install-ui: install UI from package"
72 echo " -b|--build-ui PATH-TO-UI-REPO: build the UI in the specified repo"
Leslie Giles202103e2016-09-27 13:23:40 -040073 echo " --no-mkcontainer: do not run mkcontainer, used for debugging script"
Leslie Giles1a1c87e2016-09-27 09:51:56 -040074 echo " PLATFORM_REPOSITORY (optional): name of the RIFT.ware repository."
75 echo " PLATFORM_VERSION (optional): version of the platform packages to be installed."
76 echo
77 exit 0;;
78 --) shift; break;;
79 *) echo "Not implemented: $1" >&2; exit 1;;
80 esac
81done
82
83if $installUI && [[ $UIPathToBuild ]]; then
84 echo "Cannot both install and build the UI!"
85 exit 1
86fi
87
88if [[ $UIPathToBuild && ! -d $UIPathToBuild ]]; then
89 echo "Not a directory: $UIPathToBuild"
90 exit 1
91fi
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040092
Leslie Giles202103e2016-09-27 13:23:40 -040093# Turn this on after handling options, so the output doesn't get cluttered.
94set -x # Print commands before executing them
95
96###############################################################################
97# Find the platform
98if python -mplatform | grep -qi fedora; then
99 PLATFORM=fc20
100elif python -mplatform | grep -qi ubuntu; then
101 PLATFORM=ub16
102else
103 echo "Unknown platform"
104 exit 1
105fi
106
107###############################################################################
108# Set up repo and version
109
110if [[ $PLATFORM == ub16 ]]; then
111 PLATFORM_REPOSITORY=${1:-OSM}
112 PLATFORM_VERSION=${2:-4.3.1.0.49556}
113elif [[ $PLATFORM == fc20 ]]; then
114 PLATFORM_REPOSITORY=${1:-OSM} # change to OSM when published
115 PLATFORM_VERSION=${2:-4.3.1.0.49553-1}
116else
117 echo "Internal error: unknown platform $PLATFORM"
118 exit 1
119fi
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400120
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400121###############################################################################
122# Main block
123
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400124# must be run from the top of a workspace
125cd $(dirname $0)
126
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400127# inside RIFT.io this is an NFS mount
128# so just to be safe
129test -h /usr/rift && sudo rm -f /usr/rift
130
Leslie Giles202103e2016-09-27 13:23:40 -0400131if [[ $PLATFORM == ub16 ]]; then
132 # enable the right repos
133 curl http://repos.riftio.com/public/xenial-riftware-public-key | sudo apt-key add -
134 sudo curl -o /etc/apt/sources.list.d/${PLATFORM_REPOSITORY}.list http://buildtracker.riftio.com/repo_file/ub16/${PLATFORM_REPOSITORY}/
135 sudo apt-get update
136
137 # and install the tools
138 sudo apt remove -y rw.toolchain-rwbase tcpdump
139 sudo apt-get install -y rw.tools-container-tools rw.tools-scripts python
140elif [[ $PLATFORM == fc20 ]]; then
141 # get the container tools from the correct repository
142 sudo rm -f /etc/yum.repos.d/private.repo
143 sudo curl -o /etc/yum.repos.d/${PLATFORM_REPOSITORY}.repo \
144 http://buildtracker.riftio.com/repo_file/fc20/${PLATFORM_REPOSITORY}/
145 sudo yum install --assumeyes rw.tools-container-tools rw.tools-scripts
146else
147 echo "Internal error: unknown platform $PLATFORM"
148 exit 1
149fi
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400150
151# enable the OSM repository hosted by RIFT.io
152# this contains the RIFT platform code and tools
153# and install of the packages required to build and run
154# this module
Leslie Giles202103e2016-09-27 13:23:40 -0400155if $runMkcontainer; then
156 sudo /usr/rift/container_tools/mkcontainer --modes build --modes ext --repo ${PLATFORM_REPOSITORY}
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400157fi
158
Leslie Giles202103e2016-09-27 13:23:40 -0400159
160if [[ $PLATFORM == ub16 ]]; then
161 # install the RIFT platform code:
162 sudo apt-get install -y rw.toolchain-rwbase=${PLATFORM_VERSION} \
163 rw.toolchain-rwtoolchain=${PLATFORM_VERSION} \
164 rw.core.mgmt-mgmt=${PLATFORM_VERSION} \
165 rw.core.util-util=${PLATFORM_VERSION} \
166 rw.core.rwvx-rwvx=${PLATFORM_VERSION} \
167 rw.core.rwvx-rwdts=${PLATFORM_VERSION} \
168 rw.automation.core-RWAUTO=${PLATFORM_VERSION} \
169 rw.core.rwvx-rwha-1.0=${PLATFORM_VERSION}
170
171 sudo chmod 777 /usr/rift /usr/rift/usr/share
172
173 if $installSO; then
174 sudo apt-get install -y \
175 rw.core.mc-\*=${PLATFORM_VERSION}
176 fi
177
178 if $installUI; then
179 sudo apt-get install -y \
180 rw.ui-about=${PLATFORM_VERSION} \
181 rw.ui-logging=${PLATFORM_VERSION} \
182 rw.ui-skyquake=${PLATFORM_VERSION} \
183 rw.ui-accounts=${PLATFORM_VERSION} \
184 rw.ui-composer=${PLATFORM_VERSION} \
185 rw.ui-launchpad=${PLATFORM_VERSION} \
186 rw.ui-debug=${PLATFORM_VERSION} \
187 rw.ui-config=${PLATFORM_VERSION} \
188 rw.ui-dummy_component=${PLATFORM_VERSION}
189 fi
190elif [[ $PLATFORM == fc20 ]]; then
191
192 temp=$(mktemp -d /tmp/rw.XXX)
193 pushd $temp
194
195 # yum does not accept the --nodeps and --replacefiles options so we
196 # download first and then install
197 yumdownloader rw.toolchain-rwbase-${PLATFORM_VERSION} \
198 rw.toolchain-rwtoolchain-${PLATFORM_VERSION} \
199 rw.core.mgmt-mgmt-${PLATFORM_VERSION} \
200 rw.core.util-util-${PLATFORM_VERSION} \
201 rw.core.rwvx-rwvx-${PLATFORM_VERSION} \
202 rw.core.rwvx-rwha-1.0-${PLATFORM_VERSION} \
203 rw.core.rwvx-rwdts-${PLATFORM_VERSION} \
204 rw.automation.core-RWAUTO-${PLATFORM_VERSION}
205
206 # Install one at a time so that pre-installed packages will not cause a failure
207 for pkg in *rpm; do
208 # Check to see if the package is already installed; do not try to install
209 # it again if it does, since this causes rpm -i to return failure.
210 if rpm -q $(rpm -q -p $pkg) >/dev/null; then
211 echo "WARNING: package already installed: $pkg"
212 else
213 sudo rpm -i --replacefiles --nodeps $pkg
214 fi
215 done
216
217 popd
218 rm -rf $temp
219
220 # this file gets in the way of the one generated by the build
221 sudo rm -f /usr/rift/usr/lib/libmano_yang_gen.so
222
223
224 sudo chmod 777 /usr/rift /usr/rift/usr/share
225
226 if $installSO; then
227 sudo apt-get install -y \
228 rw.core.mc-\*-${PLATFORM_VERSION}
229 fi
230
231 if $installUI; then
232 sudo apt-get install -y \
233 rw.ui-about-${PLATFORM_VERSION} \
234 rw.ui-logging-${PLATFORM_VERSION} \
235 rw.ui-skyquake-${PLATFORM_VERSION} \
236 rw.ui-accounts-${PLATFORM_VERSION} \
237 rw.ui-composer-${PLATFORM_VERSION} \
238 rw.ui-launchpad-${PLATFORM_VERSION} \
239 rw.ui-debug-${PLATFORM_VERSION} \
240 rw.ui-config-${PLATFORM_VERSION} \
241 rw.ui-dummy_component-${PLATFORM_VERSION}
242 fi
243
244else
245 echo "Internal error: unknown platform $PLATFORM"
246 exit 1
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400247fi
248
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400249# install some base files used to create VNFs
250test -d /usr/rift/images || mkdir /usr/rift/images
251for file in Fedora-x86_64-20-20131211.1-sda-ping.qcow2 Fedora-x86_64-20-20131211.1-sda-pong.qcow2 Fedora-x86_64-20-20131211.1-sda.qcow2; do
252 test -f /usr/rift/images/$file || curl -o /usr/rift/images/$file http://repo.riftio.com/releases/open.riftio.com/4.3.1/$file
253done
254
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400255# If you are re-building SO, you just need to run
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400256# these two steps
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400257if ! $installSO; then
258 make -j16
259 sudo make install
260fi
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400261
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400262if [[ $UIPathToBuild ]]; then
263 make -C $UIPathToBuild -j16
264 sudo make -C $UIPathToBuild install
265fi
266
267echo "To run SO with UI please run:"
268echo 'sudo -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode'
269echo
270echo "To run SO without UI please run:"
Rajesh1b20e0c2016-09-26 18:01:15 -0400271echo 'sudo -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode --no-ui'