blob: df17d8107317f04187570a34193e75f0a228b0d9 [file] [log] [blame]
Leslie Giles1a1c87e2016-09-27 09:51:56 -04001#!/usr/bin/env bash
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04002#
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -04003# Copyright 2016,2017 RIFT.IO Inc
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -04004#
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#
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040024# This is a top-level build script for OSM SO or UI
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040025#
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
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040030MODULE=SO
31
Leslie Giles202103e2016-09-27 13:23:40 -040032# Defensive bash programming flags
33set -o errexit # Exit on any error
34trap 'echo ERROR: Command failed: \"$BASH_COMMAND\"' ERR
35set -o nounset # Expanding an unset variable is an error. Variables must be
36 # set before they can be used.
37
Leslie Giles1a1c87e2016-09-27 09:51:56 -040038###############################################################################
39# Options and arguments
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040040
Leslie Giles202103e2016-09-27 13:23:40 -040041# There
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040042params="$(getopt -o h -l install,help --name "$0" -- "$@")"
Leslie Giles1a1c87e2016-09-27 09:51:56 -040043if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
44
45eval set -- $params
46
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040047installFromPackages=false
Leslie Giles1a1c87e2016-09-27 09:51:56 -040048
49while true; do
50 case "$1" in
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040051 --install) installFromPackages=true; shift;;
Leslie Giles1a1c87e2016-09-27 09:51:56 -040052 -h|--help)
53 echo
54 echo "NAME:"
55 echo " $0"
56 echo
57 echo "SYNOPSIS:"
58 echo " $0 -h|--help"
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040059 echo " $0 [--install] [PLATFORM_REPOSITORY] [PLATFORM_VERSION]"
Leslie Giles1a1c87e2016-09-27 09:51:56 -040060 echo
61 echo "DESCRIPTION:"
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040062 echo " Prepare current system to run $MODULE. By default, the system"
63 echo " is set up to support building $MODULE; optionally, "
64 echo " $MODULE can be installed from a Debian package repository."
Leslie Giles1a1c87e2016-09-27 09:51:56 -040065 echo
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040066 echo " --install: install $MODULE from package"
Leslie Giles1a1c87e2016-09-27 09:51:56 -040067 echo " PLATFORM_REPOSITORY (optional): name of the RIFT.ware repository."
68 echo " PLATFORM_VERSION (optional): version of the platform packages to be installed."
69 echo
70 exit 0;;
71 --) shift; break;;
72 *) echo "Not implemented: $1" >&2; exit 1;;
73 esac
74done
75
Leslie Giles202103e2016-09-27 13:23:40 -040076# Turn this on after handling options, so the output doesn't get cluttered.
77set -x # Print commands before executing them
78
79###############################################################################
Leslie Giles202103e2016-09-27 13:23:40 -040080# Set up repo and version
81
Jeremy Mordkoff614b61b2017-10-16 13:36:23 -040082PLATFORM_REPOSITORY=${1:-OSM3}
83PLATFORM_VERSION=${2:-5.2.0.1.71454}
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040084
Leslie Giles1a1c87e2016-09-27 09:51:56 -040085###############################################################################
86# Main block
87
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040088# must be run from the top of a workspace
89cd $(dirname $0)
90
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040091# enable the right repos
92curl http://repos.riftio.com/public/xenial-riftware-public-key | sudo apt-key add -
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -040093
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -040094# always use the same file name so that updates will overwrite rather than enable a second repo
95sudo curl -o /etc/apt/sources.list.d/rift.list http://buildtracker.riftio.com/repo_file/ub16/${PLATFORM_REPOSITORY}/
96sudo apt-get update
97
98sudo apt install -y --allow-downgrades rw.tools-container-tools=${PLATFORM_VERSION} rw.tools-scripts=${PLATFORM_VERSION}
99
100if $installFromPackages; then
101
102 # Install module and platform from packages
103 sudo -H /usr/rift/container_tools/mkcontainer --modes $MODULE --repo ${PLATFORM_REPOSITORY} --rw-version ${PLATFORM_VERSION}
104
Leslie Giles202103e2016-09-27 13:23:40 -0400105else
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400106
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400107 # Install environment to build module
108 sudo -H /usr/rift/container_tools/mkcontainer --modes $MODULE-dev --repo ${PLATFORM_REPOSITORY} --rw-version ${PLATFORM_VERSION}
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400109
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400110 # Build and install module
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400111 make -j16
112 sudo make install
Jeremy Mordkoff6f07e6f2016-09-07 18:56:51 -0400113
Leslie Giles1a1c87e2016-09-27 09:51:56 -0400114fi
115
Jeremy Mordkoff4870d0e2017-09-30 20:28:33 -0400116if [[ $MODULE == SO ]]; then
117 echo "Creating Service ...."
118 sudo /usr/rift/bin/create_launchpad_service
119fi
120
Jeremy Mordkoffe4f094b2016-12-02 16:39:37 -0500121