blob: 0f9a6c6d601ddc395a42bac55a09a21a124ef796 [file] [log] [blame]
tiernoa7f744d2018-09-10 11:04:31 +02001#!/bin/bash
2
3##
4# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5# This file is part of openmano
6# All Rights Reserved.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
19#
20##
21
22# author: Alfonso Tierno
23
24# It uses following env, if not provided filling by default
25[ -z "$GIT_OSMIM_URL" ] && GIT_OSMIM_URL=https://osm.etsi.org/gerrit/osm/IM.git
26[ -z "$DEVELOP" ] && DEVELOP=""
27# folder where RO is installed
28[ -z "$BASEFOLDER" ] && HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]})) && BASEFOLDER=$(dirname $HERE)
29[ -z "$SUDO_USER" ] && SUDO_USER="$USER"
30[ -z "$NO_PACKAGES" ] && NO_PACKAGES=""
31[ -z "$_DISTRO" ] && _DISTRO="Ubuntu"
32
33
34su $SUDO_USER -c "git -C ${BASEFOLDER} clone ${GIT_OSMIM_URL} IM" ||
35 ! echo "Error cannot clone from '${GIT_OSMIM_URL}'" >&2 || exit 1
36if [[ -n $COMMIT_ID ]] ; then
37 echo -e "Installing osm-IM from refspec: $COMMIT_ID"
38 su $SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout $COMMIT_ID" ||
39 ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OSMIM_URL}'" >&2 || exit 1
40elif [[ -z $DEVELOP ]]; then
41 LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/IM" tag -l "v[0-9]*" | sort -V | tail -n1`
42 echo -e "Installing osm-IM from refspec: tags/${LATEST_STABLE_TAG}"
43 su $SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout tags/${LATEST_STABLE_TAG}" ||
44 ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OSMIM_URL}'" >&2 || exit 1
45else
46 echo -e "Installing osm-IM from refspec: master"
47fi
48
49# Install debian dependencies before setup.py
50if [[ -z "$NO_PACKAGES" ]]
51then
52 # apt-get update
53 # apt-get install -y git python-pip
54 # pip2 install pip==9.0.3
55 pip2 install pyangbind || exit 1
56fi
57
58PYBINDPLUGIN=$(python2 -c 'import pyangbind; import os; print "%s/plugin" % os.path.dirname(pyangbind.__file__)')
59su $SUDO_USER -c 'mkdir -p "'${BASEFOLDER}/IM/osm_im'"'
60su $SUDO_USER -c 'touch "'${BASEFOLDER}/IM/osm_im/__init__.py'"'
61# wget -q https://raw.githubusercontent.com/RIFTIO/RIFT.ware/RIFT.ware-4.4.1/modules/core/util/yangtools/yang/rw-pb-ext.yang -O "${BASEFOLDER}/IM/models/yang/rw-pb-ext.yang"
62for target in vnfd nsd ; do
63 pyang -Werror --path "${BASEFOLDER}/IM/models/yang" --plugindir "${PYBINDPLUGIN}" -f pybind \
64 -o "${BASEFOLDER}/IM/osm_im/${target}.py" "${BASEFOLDER}/IM/models/yang/${target}.yang"
65done
66
67pip2 install -e "${BASEFOLDER}/IM" || ! echo "ERROR installing python-osm-im library!!!" >&2 || exit 1