blob: 2fad21455c3fba7da3e2d1b5b4804e28ed28af34 [file] [log] [blame]
tiernoa7f744d2018-09-10 11:04:31 +02001#!/bin/bash
2
3##
tierno92021022018-09-12 16:29:23 +02004# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U.
tiernoa7f744d2018-09-10 11:04:31 +02005# 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
tierno92021022018-09-12 16:29:23 +020033function usage(){
34 echo -e "usage: sudo -E $0 [OPTIONS]"
35 echo -e "Install last stable source code of osm-im and the needed packages"
36 echo -e " OPTIONS"
37 echo -e " -h --help: show this help"
38 echo -e " -b REFSPEC: install from source code using a specific branch (master, v2.0, ...) or tag"
39 echo -e " -b master (main branch)"
40 echo -e " -b v2.0 (v2.0 branch)"
41 echo -e " -b tags/v1.1.0 (a specific tag)"
42 echo -e " ..."
43 echo -e " --develop: install last master version for developers"
44 echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This" \
45 "avoid wasting time if you are sure requires packages are present e.g. because of a previous installation"
46}
47while getopts ":b:h-:" o; do
48 case "${o}" in
49 b)
50 export COMMIT_ID=${OPTARG}
51 ;;
52 h)
53 usage && exit 0
54 ;;
55 -)
56 [ "${OPTARG}" == "help" ] && usage && exit 0
57 [ "${OPTARG}" == "develop" ] && export DEVELOP="y" && continue
58 [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue
59 [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue
60 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
61 exit 1
62 ;;
63 \?)
64 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
65 exit 1
66 ;;
67 :)
68 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
69 exit 1
70 ;;
71 *)
72 usage >&2
73 exit 1
74 ;;
75 esac
76done
tiernoa7f744d2018-09-10 11:04:31 +020077
78su $SUDO_USER -c "git -C ${BASEFOLDER} clone ${GIT_OSMIM_URL} IM" ||
79 ! echo "Error cannot clone from '${GIT_OSMIM_URL}'" >&2 || exit 1
80if [[ -n $COMMIT_ID ]] ; then
81 echo -e "Installing osm-IM from refspec: $COMMIT_ID"
82 su $SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout $COMMIT_ID" ||
83 ! echo "Error cannot checkout '$COMMIT_ID' from '${GIT_OSMIM_URL}'" >&2 || exit 1
84elif [[ -z $DEVELOP ]]; then
85 LATEST_STABLE_TAG=`git -C "${BASEFOLDER}/IM" tag -l "v[0-9]*" | sort -V | tail -n1`
86 echo -e "Installing osm-IM from refspec: tags/${LATEST_STABLE_TAG}"
87 su $SUDO_USER -c "git -C ${BASEFOLDER}/IM checkout tags/${LATEST_STABLE_TAG}" ||
88 ! echo "Error cannot checkout 'tags/${LATEST_STABLE_TAG}' from '${GIT_OSMIM_URL}'" >&2 || exit 1
89else
90 echo -e "Installing osm-IM from refspec: master"
91fi
92
93# Install debian dependencies before setup.py
94if [[ -z "$NO_PACKAGES" ]]
95then
96 # apt-get update
97 # apt-get install -y git python-pip
98 # pip2 install pip==9.0.3
99 pip2 install pyangbind || exit 1
100fi
101
102PYBINDPLUGIN=$(python2 -c 'import pyangbind; import os; print "%s/plugin" % os.path.dirname(pyangbind.__file__)')
103su $SUDO_USER -c 'mkdir -p "'${BASEFOLDER}/IM/osm_im'"'
104su $SUDO_USER -c 'touch "'${BASEFOLDER}/IM/osm_im/__init__.py'"'
105# 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"
106for target in vnfd nsd ; do
107 pyang -Werror --path "${BASEFOLDER}/IM/models/yang" --plugindir "${PYBINDPLUGIN}" -f pybind \
108 -o "${BASEFOLDER}/IM/osm_im/${target}.py" "${BASEFOLDER}/IM/models/yang/${target}.yang"
109done
110
tierno92021022018-09-12 16:29:23 +0200111pip2 install -e "${BASEFOLDER}/IM" || ! echo "ERROR installing python-osm-im library!!!" >&2 || exit 1