Merge branch 'v1.0'
[osm/SO.git] / BUILD.sh
1 #!/usr/bin/env bash
2 #
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 #
17 # Author(s): Jeremy Mordkoff, Lezz Giles
18 # Creation Date: 08/29/2016
19 #
20 #
21
22 # BUILD.sh
23 #
24 # This is a top-level build script for RIFT.io
25 #
26 # Arguments and options: use -h or --help
27 #
28 # dependencies -- requires sudo rights
29
30 # Defensive bash programming flags
31 set -o errexit # Exit on any error
32 trap 'echo ERROR: Command failed: \"$BASH_COMMAND\"' ERR
33 set -o nounset # Expanding an unset variable is an error. Variables must be
34 # set before they can be used.
35
36 ###############################################################################
37 # Options and arguments
38
39 # There
40 params="$(getopt -o suhb: -l install-so,install-ui,no-mkcontainer,build-ui:,help --name "$0" -- "$@")"
41 if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
42
43 eval set -- $params
44
45 installSO=false
46 installUI=false
47 runMkcontainer=true
48 UIPathToBuild=
49
50 while 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;;
55 --no-mkcontainer) runMkcontainer=false; shift;;
56 -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"
73 echo " --no-mkcontainer: do not run mkcontainer, used for debugging script"
74 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
81 done
82
83 if $installUI && [[ $UIPathToBuild ]]; then
84 echo "Cannot both install and build the UI!"
85 exit 1
86 fi
87
88 if [[ $UIPathToBuild && ! -d $UIPathToBuild ]]; then
89 echo "Not a directory: $UIPathToBuild"
90 exit 1
91 fi
92
93 # Turn this on after handling options, so the output doesn't get cluttered.
94 set -x # Print commands before executing them
95
96 ###############################################################################
97 # Find the platform
98 PYTHON=python
99 if [[ ! -f /usr/bin/python ]]; then
100 PYTHON=python3
101 fi
102
103 if $PYTHON -mplatform | grep -qi fedora; then
104 PLATFORM=fc20
105 elif $PYTHON -mplatform | grep -qi ubuntu; then
106 PLATFORM=ub16
107 else
108 echo "Unknown platform"
109 exit 1
110 fi
111
112 ###############################################################################
113 # Set up repo and version
114
115 if [[ $PLATFORM == ub16 ]]; then
116 PLATFORM_REPOSITORY=${1:-OSM}
117 PLATFORM_VERSION=${2:-4.3.1.0.53651}
118 elif [[ $PLATFORM == fc20 ]]; then
119 PLATFORM_REPOSITORY=${1:-OSM} # change to OSM when published
120 PLATFORM_VERSION=${2:-4.3.1.0.53651}
121 else
122 echo "Internal error: unknown platform $PLATFORM"
123 exit 1
124 fi
125
126 ###############################################################################
127 # Main block
128
129 # Disable apt-daily.service and apt-daily.timer
130
131 DAILY_TIMER='apt-daily.timer'
132 DAILY_SERVICE='apt-daily.service'
133 if [ $(systemctl is-active $DAILY_TIMER) = "active" ]
134 then
135 systemctl stop $DAILY_TIMER
136 systemctl disable $DAILY_TIMER
137 systemctl disable $DAILY_SERVICE
138 fi
139
140 # must be run from the top of a workspace
141 cd $(dirname $0)
142
143 # inside RIFT.io this is an NFS mount
144 # so just to be safe
145 test -h /usr/rift && sudo rm -f /usr/rift
146
147 if [[ $PLATFORM == ub16 ]]; then
148 # enable the right repos
149 curl http://repos.riftio.com/public/xenial-riftware-public-key | sudo apt-key add -
150 sudo curl -o /etc/apt/sources.list.d/${PLATFORM_REPOSITORY}.list http://buildtracker.riftio.com/repo_file/ub16/${PLATFORM_REPOSITORY}/
151 sudo apt-get update
152
153 # and install the tools
154 sudo apt remove -y rw.toolchain-rwbase tcpdump
155 sudo apt-get install -y rw.tools-container-tools rw.tools-scripts python
156 elif [[ $PLATFORM == fc20 ]]; then
157 # get the container tools from the correct repository
158 sudo rm -f /etc/yum.repos.d/private.repo
159 sudo curl -o /etc/yum.repos.d/${PLATFORM_REPOSITORY}.repo \
160 http://buildtracker.riftio.com/repo_file/fc20/${PLATFORM_REPOSITORY}/
161 sudo yum install --assumeyes rw.tools-container-tools rw.tools-scripts
162 else
163 echo "Internal error: unknown platform $PLATFORM"
164 exit 1
165 fi
166
167 # enable the OSM repository hosted by RIFT.io
168 # this contains the RIFT platform code and tools
169 # and install of the packages required to build and run
170 # this module
171 if $runMkcontainer; then
172 sudo apt-get install -y libxml2-dev libxslt-dev
173 sudo /usr/rift/container_tools/mkcontainer --modes build --modes ext --repo ${PLATFORM_REPOSITORY}
174 sudo pip3 install -y lxml==3.4.0
175 fi
176
177
178 if [[ $PLATFORM == ub16 ]]; then
179 # install the RIFT platform code:
180 sudo apt-get install -y --allow-downgrades rw.toolchain-rwbase=${PLATFORM_VERSION} \
181 rw.toolchain-rwtoolchain=${PLATFORM_VERSION} \
182 rw.core.mgmt-mgmt=${PLATFORM_VERSION} \
183 rw.core.util-util=${PLATFORM_VERSION} \
184 rw.core.rwvx-rwvx=${PLATFORM_VERSION} \
185 rw.core.rwvx-rwdts=${PLATFORM_VERSION} \
186 rw.automation.core-RWAUTO=${PLATFORM_VERSION} \
187 rw.core.rwvx-rwha-1.0=${PLATFORM_VERSION}
188
189 sudo apt-get install python-cinderclient
190
191 sudo chmod 777 /usr/rift /usr/rift/usr/share
192
193 if $installSO; then
194 sudo apt-get install -y \
195 rw.core.mc-\*=${PLATFORM_VERSION}
196 fi
197
198 if $installUI; then
199 sudo apt-get install -y \
200 rw.ui-about=${PLATFORM_VERSION} \
201 rw.ui-logging=${PLATFORM_VERSION} \
202 rw.ui-skyquake=${PLATFORM_VERSION} \
203 rw.ui-accounts=${PLATFORM_VERSION} \
204 rw.ui-composer=${PLATFORM_VERSION} \
205 rw.ui-launchpad=${PLATFORM_VERSION} \
206 rw.ui-debug=${PLATFORM_VERSION} \
207 rw.ui-config=${PLATFORM_VERSION} \
208 rw.ui-dummy_component=${PLATFORM_VERSION}
209 fi
210 elif [[ $PLATFORM == fc20 ]]; then
211
212 temp=$(mktemp -d /tmp/rw.XXX)
213 pushd $temp
214
215 # yum does not accept the --nodeps and --replacefiles options so we
216 # download first and then install
217 yumdownloader rw.toolchain-rwbase-${PLATFORM_VERSION} \
218 rw.toolchain-rwtoolchain-${PLATFORM_VERSION} \
219 rw.core.mgmt-mgmt-${PLATFORM_VERSION} \
220 rw.core.util-util-${PLATFORM_VERSION} \
221 rw.core.rwvx-rwvx-${PLATFORM_VERSION} \
222 rw.core.rwvx-rwha-1.0-${PLATFORM_VERSION} \
223 rw.core.rwvx-rwdts-${PLATFORM_VERSION} \
224 rw.automation.core-RWAUTO-${PLATFORM_VERSION}
225
226 # Install one at a time so that pre-installed packages will not cause a failure
227 for pkg in *rpm; do
228 # Check to see if the package is already installed; do not try to install
229 # it again if it does, since this causes rpm -i to return failure.
230 if rpm -q $(rpm -q -p $pkg) >/dev/null; then
231 echo "WARNING: package already installed: $pkg"
232 else
233 sudo rpm -i --replacefiles --nodeps $pkg
234 fi
235 done
236
237 popd
238 rm -rf $temp
239
240 # this file gets in the way of the one generated by the build
241 sudo rm -f /usr/rift/usr/lib/libmano_yang_gen.so
242
243
244 sudo chmod 777 /usr/rift /usr/rift/usr/share
245
246 if $installSO; then
247 sudo apt-get install -y \
248 rw.core.mc-\*-${PLATFORM_VERSION}
249 fi
250
251 if $installUI; then
252 sudo apt-get install -y \
253 rw.ui-about-${PLATFORM_VERSION} \
254 rw.ui-logging-${PLATFORM_VERSION} \
255 rw.ui-skyquake-${PLATFORM_VERSION} \
256 rw.ui-accounts-${PLATFORM_VERSION} \
257 rw.ui-composer-${PLATFORM_VERSION} \
258 rw.ui-launchpad-${PLATFORM_VERSION} \
259 rw.ui-debug-${PLATFORM_VERSION} \
260 rw.ui-config-${PLATFORM_VERSION} \
261 rw.ui-dummy_component-${PLATFORM_VERSION}
262 fi
263
264 else
265 echo "Internal error: unknown platform $PLATFORM"
266 exit 1
267 fi
268
269 # install some base files used to create VNFs
270 test -d /usr/rift/images || mkdir /usr/rift/images
271 for 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
272 test -f /usr/rift/images/$file || curl -o /usr/rift/images/$file http://repo.riftio.com/releases/open.riftio.com/4.3.1/$file
273 done
274
275 # If you are re-building SO, you just need to run
276 # these two steps
277 if ! $installSO; then
278 make -j16
279 sudo make install
280 fi
281
282 if [[ $UIPathToBuild ]]; then
283 make -C $UIPathToBuild -j16
284 sudo make -C $UIPathToBuild install
285 fi
286
287 echo "Creating Service ...."
288 sudo $(dirname $0)/create_launchpad_service
289