Skip to content
Snippets Groups Projects
build_helper.bash 40.7 KiB
Newer Older
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# *      http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */
################################################################################
# file build_helper.bash
# brief
# author Lionel Gauthier and Navid Nikaein
# company Eurecom
# email: lionel.gauthier@eurecom.fr and navid.nikaein@eurecom.fr
#
#######################################
#            Helper Func
######################################

gauthier's avatar
 
gauthier committed
declare ROOT_UID=0
declare E_NOTROOT=67
declare NUM_CPU=`cat /proc/cpuinfo | grep processor | wc -l`
declare OAI_INSTALLED=1
declare PWD=`pwd`
declare USER=`whoami`
declare BUILD_FROM_MAKEFILE=0
declare SUDO=''
declare PW=''
declare UBUNTU_REL=`lsb_release -r | cut  -f2`
declare UBUNTU_REL_NAME=`lsb_release -cs`

set_build_from_makefile(){
    BUILD_FROM_MAKEFILE=$1
check_for_root_rights() {
  #  if [[ $EUID -ne $ROOT_EUID ]]; then
    if [ $USER != "root" ]; then
        echo "Run as a sudoers"
gauthier's avatar
 
gauthier committed
        return 1
    else
        echo  "Run as a root"
gauthier's avatar
 
gauthier committed
        return 0
    fi
}

test_install_package() {
  # usage: test_install_package package_name
 if [ $# -eq 1 ]; then
      dpkg -s "$1" > /dev/null 2>&1 && {
          echo "$1 is installed."
          echo "$1 is not installed."
gauthier's avatar
 
gauthier committed
          OAI_INSTALLED=0
nikaeinn's avatar
nikaeinn committed
test_uninstall_package() {
nikaeinn's avatar
nikaeinn committed
 if [ $# -eq 1 ]; then
      dpkg -s "$1" > /dev/null 2>&1 && {
          $SUDO apt-get remove --assume-yes $1
          echo "$1 is uninstalled."
nikaeinn's avatar
nikaeinn committed
      } || {
          echo "$1 is not installed."
test_command_install_script() {
  # usage: test_command_install_script searched_binary script_to_be_invoked_if_binary_not_found
  command -v $1 >/dev/null 2>&1 || { echo_warning "Program $1 is not installed. Trying installing it." >&2; bash $2; command -v $1 >/dev/null 2>&1 || { echo_fatal "Program $1 is not installed. Aborting." >&2; };}
  echo_success "$1 available"
}


check_for_machine_type(){
    MACHINE_TYPE=`uname -m`
    if [ ${MACHINE_TYPE} = "x86_64" ]; then
gauthier's avatar
 
gauthier committed
        return 64  # 64-bit stuff here
gauthier's avatar
 
gauthier committed
        if [ ${MACHINE_TYPE} = "i686" ]; then
            return 32 # 32-bit stuff here
gauthier's avatar
 
gauthier committed
        fi
    fi
}

####################################################
## OAI related functions
#####################################################

####################################################
# 1. install the required packages
####################################################

make_certs(){
nikaeinn's avatar
nikaeinn committed

 # for certtificate generation
    rm -rf demoCA
nikaeinn's avatar
nikaeinn committed
    mkdir -m 777 -p demoCA
    echo 01 > demoCA/serial
    touch demoCA/index.txt
nikaeinn's avatar
nikaeinn committed
    echo "creating the certificate"
    user=$(whoami)
nikaeinn's avatar
 
nikaeinn committed
    HOSTNAME=$(hostname -f)

    echo "Creating certificate for user '$HOSTNAME'"
# CA self certificate
    openssl req  -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out cacert.pem -keyout cakey.pem -subj /CN=eur/C=FR/ST=PACA/L=Aix/O=Eurecom/OU=CM
nikaeinn's avatar
 
nikaeinn committed
   # openssl genrsa -out user.key.pem 1024
    openssl genrsa -out hss.key.pem 1024
    #openssl req -new -batch -out user.csr.pem -key user.key.pem -subj /CN=$HOSTNAME.eur/C=FR/ST=PACA/L=Aix/O=Eurecom/OU=CM
    openssl req -new -batch -out hss.csr.pem -key hss.key.pem -subj /CN=hss.eur/C=FR/ST=PACA/L=Aix/O=Eurecom/OU=CM
    openssl ca -cert cacert.pem -keyfile cakey.pem -in hss.csr.pem -out hss.cert.pem -outdir . -batch
    if [ ! -d /usr/local/etc/freeDiameter ];  then
gauthier's avatar
 
gauthier committed
        echo "Creating non existing directory: /usr/local/etc/freeDiameter/"
        $SUDO mkdir /usr/local/etc/freeDiameter/
nikaeinn's avatar
 
nikaeinn committed
    echo "Copying *.pem to /usr/local/etc/freeDiameter/"
    $SUDO cp *.pem /usr/local/etc/freeDiameter/
    mv *.pem bin/
# openssl genrsa -out ubuntu.key.pem 1024
# openssl req -new -batch -x509 -out ubuntu.csr.pem -key ubuntu.key.pem -subj /CN=ubuntu.localdomain/C=FR/ST=BdR/L=Aix/O=fD/OU=Tests
# openssl ca -cert cacert.pem -keyfile cakey.pem -in ubuntu.csr.pem -out ubuntu.cert.pem -outdir . -batch

}

check_install_nettle(){
    if [ ! -f ./.lock_oaibuild ]; then
	if [ $UBUNTU_REL = "12.04" ]; then
	    test_uninstall_package nettle-dev
	    test_uninstall_package nettle-bin
	    if [ ! -d /usr/local/src/ ]; then
		echo "/usr/local/src/ doesn't exist please create one"
		exit -1
	    fi
	    if [ ! -w /usr/local/src/ ];  then
		echo "You don't have permissions to write to /usr/local/src/, installing as a sudoer"
		#	exit -1
	    fi
	    echo "Downloading nettle archive"
	    if [ -f nettle-2.5.tar.gz ]; then
		$SUDO rm -f nettle-2.5.tar.gz
	    fi
	    if [ -f nettle-2.5.tar ]; then
		$SUDO rm -f nettle-2.5.tar
	    fi
	    if [ -d nettle-2.5 ];  then
		$SUDO rm -rf nettle-2.5/
	    fi


	    $SUDO wget ftp://ftp.lysator.liu.se/pub/security/lsh/nettle-2.5.tar.gz
	    $SUDO gunzip nettle-2.5.tar.gz
	    $SUDO echo "Uncompressing nettle archive"
	    $SUDO tar -xf nettle-2.5.tar
	    cd nettle-2.5/
	    $SUDO ./configure --disable-openssl --enable-shared --prefix=/usr
	    if [ $? -ne 0 ]; then
		exit -1
	    fi
	    echo "Compiling nettle"
	    $SUDO make -j $NUM_CPU
	    $SUDO make check
	    $SUDO make install
check_install_freediamter(){

    if [ $UBUNTU_REL = "12.04" ]; then
nikaeinn's avatar
 
nikaeinn committed
	if [ ! -d /usr/local/src/ ]; then
	    echo "/usr/local/src/ doesn't exist please create one"
	    exit -1
	fi
nikaeinn's avatar
 
nikaeinn committed
	if [ ! -w /usr/local/src/ ];  then
	    echo "You don't have permissions to write to /usr/local/src/, installing as a sudoer"
#	exit -1
	fi
nikaeinn's avatar
 
nikaeinn committed
	cd /usr/local/src/
nikaeinn's avatar
 
nikaeinn committed
	echo "Downloading nettle archive"
nikaeinn's avatar
 
nikaeinn committed
	if [ -f nettle-2.5.tar.gz ]; then
	    $SUDO rm -f nettle-2.5.tar.gz
	fi
	if [ -f nettle-2.5.tar ]; then
	    $SUDO rm -f nettle-2.5.tar
	fi
	if [ -d nettle-2.5 ];  then
	    $SUDO rm -rf nettle-2.5/
	fi


	$SUDO wget ftp://ftp.lysator.liu.se/pub/security/lsh/nettle-2.5.tar.gz
	$SUDO gunzip nettle-2.5.tar.gz
nikaeinn's avatar
 
nikaeinn committed
	$SUDO echo "Uncompressing nettle archive"
	$SUDO tar -xf nettle-2.5.tar
	cd nettle-2.5/
	$SUDO ./configure --disable-openssl --enable-shared --prefix=/usr
nikaeinn's avatar
 
nikaeinn committed
	if [ $? -ne 0 ]; then
	    exit -1
	fi
	echo "Compiling nettle"
	$SUDO make -j $NUM_CPU
	$SUDO make check
	$SUDO make install
nikaeinn's avatar
 
nikaeinn committed
	cd ../
    echo "Downloading gnutls archive"
knopp's avatar
 
knopp committed
    if [ -f gnutls-3.1.23.tar.xz ];  then
	$SUDO rm -f gnutls-3.1.23.tar.xz
knopp's avatar
 
knopp committed
    if [ -d gnutls-3.1.23/ ];  then
	$SUDO rm -rf gnutls-3.1.23/
nikaeinn's avatar
nikaeinn committed
    test_uninstall_package libgnutls-dev

    $SUDO wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.23.tar.xz
knopp's avatar
 
knopp committed
    $SUDO tar -xf gnutls-3.1.23.tar.xz
nikaeinn's avatar
nikaeinn committed
    echo "Uncompressing gnutls archive ($PWD)"
knopp's avatar
 
knopp committed
    cd gnutls-3.1.23/
    $SUDO ./configure --prefix=/usr
    if [ $? -ne 0 ];   then
	exit -1
    fi
    echo "Compiling gnutls"
    $SUDO make -j $NUM_CPU
    $SUDO make install
    echo "Downloading freeDiameter archive"
    if [ -f 1.1.5.tar.gz ];  then
	$SUDO rm -f 1.1.5.tar.gz
    fi
    if [ -d freeDiameter-1.1.5/ ];   then
	$SUDO rm -rf freeDiameter-1.1.5/
    fi

    $SUDO wget http://www.freediameter.net/hg/freeDiameter/archive/1.1.5.tar.gz
    $SUDO tar -xzf 1.1.5.tar.gz
    echo "Uncompressing freeDiameter archive"
    cd freeDiameter-1.1.5
    $SUDO patch -p1 < $OPENAIR3_DIR/S6A/freediameter/freediameter-1.1.5.patch
    $SUDO mkdir build
    cd build
    $SUDO cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ../
    if [ $? -ne 0 ];  then
	exit -1
    fi
    echo "Compiling freeDiameter"
    $SUDO make -j $NUM_CPU
#make help
    $SUDO make test
    $SUDO sudo make install

nikaeinn's avatar
 
nikaeinn committed
#    make_certs
nikaeinn's avatar
nikaeinn committed

test_is_host_reachable() {
gauthier's avatar
gauthier committed
    ping -c 1 $1 > /dev/null || { echo_fatal "$2 host $1 does not respond to ping" >&2 ; }
    echo_success "$2 host $1 is reachable"
check_epc_s6a_certificate() {
    if [ -d /usr/local/etc/freeDiameter ]
    then
        if [ -f /usr/local/etc/freeDiameter/user.cert.pem ]
        then
            full_hostname=`cat /usr/local/etc/freeDiameter/user.cert.pem | grep "Subject" | grep "CN" | cut -d '=' -f6`
            if [ a$full_hostname == a`hostname`.${1:-'eur'} ]
            then
                echo_success "EPC S6A: Found valid certificate in /usr/local/etc/freeDiameter"
gauthier's avatar
gauthier committed
                return 0
            fi
        fi
    fi
    echo_error "EPC S6A: Did not find valid certificate in /usr/local/etc/freeDiameter"
    echo_warning "EPC S6A: generatting new certificate in /usr/local/etc/freeDiameter..."
    cd $OPENAIR3_DIR/S6A/freediameter
    ./make_certs.sh ${1:-'eur'}
gauthier's avatar
 
gauthier committed
        check_epc_s6a_certificate ${1:-'eur'}  2
        return $?
nikaeinn's avatar
nikaeinn committed
    else
       exit 1
    if [ -d /usr/local/etc/freeDiameter ]; then
nikaeinn's avatar
 
nikaeinn committed
        if [ -f /usr/local/etc/freeDiameter/hss.cert.pem ];  then
            full_hostname=`cat /usr/local/etc/freeDiameter/hss.cert.pem | grep "Subject" | grep "CN" | cut -d '=' -f6`
            if [ a$full_hostname == a`hostname`.${1:-'eur'} ]
            then
                echo_success "HSS S6A: Found valid certificate in /usr/local/etc/freeDiameter"
nikaeinn's avatar
 
nikaeinn committed
                return 0
                echo_error "Bad hss hostname found in cert file: "$full_hostname " hostname is "`hostname`
            fi
        fi
    fi
    echo_error "S6A: Did not find valid certificate in /usr/local/etc/freeDiameter"
    echo_warning "S6A: generatting new certificate in /usr/local/etc/freeDiameter..."
    cd $OPENAIR3_DIR/OPENAIRHSS/conf
    ./make_certs.sh ${1:-'eur'}
    if [ $# -lt 2 ] ; then
gauthier's avatar
 
gauthier committed
        check_hss_s6a_certificate ${1:-'eur'} 2
        return $?
gauthier's avatar
gauthier committed
    else
       exit 1
nikaeinn's avatar
 
nikaeinn committed
    fi
check_install_usrp_uhd_driver(){
    if [ ! -f /etc/apt/sources.list.d/ettus.list ] ; then
gauthier's avatar
 
gauthier committed
        $SUDO bash -c 'echo "deb http://files.ettus.com/binaries/uhd/repo/uhd/ubuntu/`lsb_release -cs` `lsb_release -cs` main" >> /etc/apt/sources.list.d/ettus.list'
        $SUDO apt-get update
    $SUDO apt-get install -t $UBUNTU_REL_NAME uhd
    test_install_package python
    test_install_package libboost-all-dev
    test_install_package libusb-1.0-0-dev
    #test_install_package uhd
}

check_install_oai_software() {

    if [ ! -f ./.lock_oaibuild ]; then
gauthier's avatar
 
gauthier committed
        $SUDO apt-get update
        if [ $UBUNTU_REL = "12.04" ]; then
gauthier's avatar
 
gauthier committed
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
            test_install_package nettle-dev
            test_install_package nettle-bin
        fi
        test_install_package autoconf
        test_install_package automake
        test_install_package bison
gauthier's avatar
 
gauthier committed
        test_install_package build-essential
gauthier's avatar
gauthier committed
        test_install_package dialog
        test_install_package flex
gauthier's avatar
 
gauthier committed
        test_install_package gawk
        test_install_package gcc
        test_install_package gdb
gauthier's avatar
 
gauthier committed
        test_install_package make
        test_install_package cmake
        test_install_package openssh-client
        test_install_package openssh-server
        test_install_package unzip
gauthier's avatar
 
gauthier committed
        test_install_package autoconf
        test_install_package automake
        test_install_package bison
        test_install_package build-essential
        test_install_package check
        test_install_package ethtool
        test_install_package flex
        test_install_package g++
        test_install_package gawk
        test_install_package gcc
        test_install_package gccxml
        test_install_package gdb
gauthier's avatar
 
gauthier committed
        test_install_package guile-2.0-dev
        test_install_package iperf
        test_install_package iproute
        test_install_package iptables
        test_install_package libatlas-base-dev
        test_install_package libatlas-dev
        test_install_package libblas3gf
        test_install_package libblas-dev
        test_install_package liblapack-dev
        test_install_package liblapack-dev
#	if [ $MACHINE_ARCH = 64 ]; then
            test_install_package libconfig8-dev
#	else
#            test_install_package libconfig-dev
#	fi
gauthier's avatar
 
gauthier committed
        test_install_package libforms-bin
        test_install_package libforms-dev
        test_install_package libgcrypt11-dev
        test_install_package libgmp-dev
        test_install_package libgtk-3-dev
        test_install_package libidn11-dev
        test_install_package libidn2-0-dev
        test_install_package libpgm-dev
        test_install_package libpgm-5.1-0
        test_install_package libpthread-stubs0-dev
        test_install_package libsctp1
        test_install_package libsctp-dev
        test_install_package libtasn1-3-dev
        test_install_package libxml2
        test_install_package libxml2-dev
#       test_install_package linux-headers-`uname -r`
        test_install_package openssl
        test_install_package libssl-dev
gauthier's avatar
 
gauthier committed
        test_install_package pkg-config
        test_install_package python-dev
        test_install_package python-pexpect
        test_install_package sshfs
        test_install_package subversion
        test_install_package valgrind
        test_install_package doxygen
        test_install_package graphviz
gauthier's avatar
 
gauthier committed
#        test_install_package libboost-all-dev

        if [ $OAI_INSTALLED = 1 ]; then
gauthier's avatar
 
gauthier committed
            touch ./.lock_oaibuild
gauthier's avatar
 
gauthier committed
        echo_info "All the required packages installed: skip"
check_install_hss_software() {
    if [ ! -f ./.lock_oaibuild ]; then
gauthier's avatar
 
gauthier committed
        $SUDO apt-get update
        if [ $UBUNTU_REL = "12.04" ]; then
gauthier's avatar
 
gauthier committed
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
            test_install_package nettle-dev
            test_install_package nettle-bin
        fi
	test_install_package autoconf
	test_install_package automake
	test_install_package bison
	test_install_package build-essential
	test_install_package cmake
	test_install_package cmake-curses-gui
gauthier's avatar
gauthier committed
    test_install_package dialog
    test_install_package dkms
	test_install_package flex
	test_install_package gawk
	test_install_package gcc
	test_install_package gdb
	test_install_package guile-2.0-dev
	test_install_package g++
	test_install_package libgmp-dev
	test_install_package libgcrypt11-dev
	test_install_package libidn11-dev
	test_install_package libidn2-0-dev
	test_install_package libmysqlclient-dev
	test_install_package libtasn1-3-dev
	test_install_package libsctp1
	test_install_package libsctp-dev
	test_install_package libxml2-dev
#	test_install_package linux-headers-`uname -r`
	test_install_package make
	test_install_package mysql-client
	test_install_package mysql-server-core-5.5
gauthier's avatar
 
gauthier committed
	test_install_package mysql-server
	test_install_package openssh-client
	test_install_package openssh-server
	test_install_package phpmyadmin
	test_install_package python-dev
	test_install_package sshfs
	test_install_package swig
	test_install_package unzip
nikaeinn's avatar
 
nikaeinn committed
#	test_install_package nettle-bin
#	test_install_package nettle-dev
	test_install_package valgrind
	if [ $OAI_INSTALLED = 1 ]; then
	    touch ./.lock_oaibuild
nikaeinn's avatar
 
nikaeinn committed
	echo_info "All the required packages installed: skip"
    if [ ! -f ./.lock_oaibuild ]; then
gauthier's avatar
 
gauthier committed
        $SUDO apt-get update
        if [ $UBUNTU_REL = "12.04" ]; then
gauthier's avatar
 
gauthier committed
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
            test_install_package nettle-dev
            test_install_package nettle-bin
gauthier's avatar
 
gauthier committed
        test_install_package autoconf
        test_install_package automake
        test_install_package bison
        test_install_package build-essential
        test_install_package check
        test_install_package cmake
        test_install_package cmake-curses-gui
gauthier's avatar
gauthier committed
        test_install_package dialog
gauthier's avatar
 
gauthier committed
        test_install_package ethtool
        test_install_package flex
        test_install_package g++
        test_install_package gawk
        test_install_package gcc
        test_install_package gccxml
        test_install_package gdb
gauthier's avatar
 
gauthier committed
        test_install_package guile-2.0-dev
        test_install_package gtkwave
        test_install_package iperf
        test_install_package iproute
        test_install_package iptables
gauthier's avatar
gauthier committed
        test_install_package iptables-dev
gauthier's avatar
 
gauthier committed
        test_install_package libatlas-base-dev
        test_install_package libatlas-dev
        test_install_package libblas
        test_install_package libblas-dev
#       if [ $MACHINE_ARCH = 64 ]; then
            test_install_package libconfig8-dev
gauthier's avatar
 
gauthier committed
#        else
nikaeinn's avatar
 
nikaeinn committed
#            test_install_package libconfig-dev
gauthier's avatar
 
gauthier committed
#       fi
        test_install_package libforms-bin
        test_install_package libforms-dev
        test_install_package libgcrypt11-dev
        test_install_package libgmp-dev
        test_install_package libgtk-3-dev
        test_install_package libidn11-dev
        test_install_package libidn2-0-dev
        test_install_package libmysqlclient-dev
        test_install_package libpgm-dev
        test_install_package libpthread-stubs0-dev
        test_install_package libsctp1
        test_install_package libsctp-dev
gauthier's avatar
 
gauthier committed
        test_install_package libssl-dev
gauthier's avatar
 
gauthier committed
        test_install_package libtasn1-3-dev
        test_install_package libtool
gauthier's avatar
 
gauthier committed
        test_install_package libxml2
        test_install_package libxml2-dev
#        test_install_package linux-headers-`uname -r`
        test_install_package make
        test_install_package openssh-client
        test_install_package openssh-server
nikaeinn's avatar
nikaeinn committed
        $SUDO service ssh start
gauthier's avatar
 
gauthier committed
        test_install_package openssl
        test_install_package openvpn
        test_install_package pkg-config
        test_install_package python-dev
        test_install_package sshfs
        test_install_package subversion
        test_install_package swig
        test_install_package tshark
        test_install_package uml-utilities
        test_install_package unzip
        test_install_package valgrind
        test_install_package vlan

        if [ $OAI_INSTALLED = 1 ]; then
gauthier's avatar
 
gauthier committed
            touch ./.lock_oaibuild
gauthier's avatar
 
gauthier committed
        echo_info "All the required packages installed: skip"
}

check_install_asn1c(){
    test_command_install_script   "asn1c" "$OPENAIR_TARGETS/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO"
    # One mor check about version of asn1c
    ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE="ASN.1 Compiler, v0.9.24"
    ASN1C_COMPILER_VERSION_MESSAGE=`asn1c -h 2>&1 | grep -i ASN\.1\ Compiler`
    ##ASN1C_COMPILER_VERSION_MESSAGE=`trim $ASN1C_COMPILER_VERSION_MESSAGE`
    if [ "$ASN1C_COMPILER_VERSION_MESSAGE" != "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE" ]; then
      #  diff <(echo -n "$ASN1C_COMPILER_VERSION_MESSAGE") <(echo -n "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE")
        echo_error "Version of asn1c is not the required one, do you want to install the required one (overwrite installation) ? (Y/n)"
        echo_error "$ASN1C_COMPILER_VERSION_MESSAGE"
        while read -r -n 1 -s answer; do
gauthier's avatar
 
gauthier committed
            if [[ $answer = [YyNn] ]]; then
                [[ $answer = [Yy] ]] && $OPENAIR_TARGETS/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO
                [[ $answer = [Nn] ]] && echo_error "Version of asn1c is not the required one, exiting." && exit 1
                break
gauthier's avatar
 
gauthier committed
            fi
}

#################################################
################################################
compile_hss() {
    cd $OPENAIR3_DIR/OPENAIRHSS
gauthier's avatar
 
gauthier committed
    if [ "$1" -eq 1 ]; then
        echo_info "build a clean HSS"
        rm -rfv obj*
        rm -rfv m4
        rm -rfv .autom4*
        rm -fv configure
nikaeinn's avatar
 
nikaeinn committed
    fi
gauthier's avatar
 
gauthier committed

    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
    if [ ! -n "$OBJ_DIR" ]; then
        OBJ_DIR="objs"
gauthier's avatar
 
gauthier committed
        mkdir --verbose -m 777 ./$OBJ_DIR
    else
        OBJ_DIR=`basename $OBJ_DIR`
    fi
gauthier's avatar
 
gauthier committed
    if [ ! -f "$OBJ_DIR"/Makefile ]; then
        if [ ! -d m4 ]; then
            mkdir --verbose -m 777 m4
        fi
        echo_success "Invoking autogen"
        ./autogen.sh
        if [ $? -ne 0 ]; then
            return 1
        fi
        cd $OBJ_DIR
gauthier's avatar
 
gauthier committed
        echo_success "Invoking configure"
gauthier's avatar
 
gauthier committed
        if [ $? -ne 0 ]; then
            return 1
        fi
gauthier's avatar
 
gauthier committed

    if [ -f Makefile ];  then
gauthier's avatar
 
gauthier committed
        echo_success "Compiling..."
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
nikaeinn's avatar
 
nikaeinn committed
            return 1
        echo_error "Configure failed, aborting"
    cd $OPENAIR3_DIR
nikaeinn's avatar
 
nikaeinn committed
    if [ $1 = 1 ]; then
gauthier's avatar
 
gauthier committed
        echo_info "build a clean EPC"
        bash_exec "rm -rf objs"
nikaeinn's avatar
 
nikaeinn committed
    fi
    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
    if [ ! -n "$OBJ_DIR" ]; then
        OBJ_DIR="objs"
        bash_exec "mkdir -m 777 ./$OBJ_DIR"
        echo_success "Created $OBJ_DIR directory"
    else
        OBJ_DIR=`basename $OBJ_DIR`
    fi
    if [ ! -f $OBJ_DIR/Makefile ]; then
        if [ ! -n "m4" ]; then
            mkdir -m 777 m4
        fi
        bash_exec "autoreconf -i -f"
        echo_success "Invoking autogen"
        bash_exec "libtoolize"
        bash_exec "./autogen.sh"
        cd ./$OBJ_DIR
        echo_success "Invoking configure"
        if [ $DEBUG -ne 0 ]; then
            ../configure --enable-debug --enable-standalone-epc --enable-gtp1u-in-kernel LDFLAGS=-L/usr/local/lib
        else
            ../configure                --enable-standalone-epc --enable-gtp1u-in-kernel LDFLAGS=-L/usr/local/lib
        fi
    else
        cd ./$OBJ_DIR
    fi

nikaeinn's avatar
 
nikaeinn committed
#    pkill oai_epc
#    pkill tshark

    if [ -f Makefile ]; then
        echo_success "Compiling..."
        make -j $NUM_CPU
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
nikaeinn's avatar
 
nikaeinn committed
            return 1
gauthier's avatar
 
gauthier committed
            cp -pf ./OAI_EPC/oai_epc  $OPENAIR_TARGETS/bin
gauthier's avatar
 
gauthier committed
        fi
    else
        echo_error "Configure failed, exiting"
nikaeinn's avatar
 
nikaeinn committed
        return 1
    cd $OPENAIR3_DIR/GTPV1-U/GTPUAH;
    make
    if [ $? -ne 0 ]; then
        echo_error "Build GTPUAH module failed, exiting"
        return 1
nikaeinn's avatar
nikaeinn committed
       	$SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
        $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
    cd $OPENAIR3_DIR/GTPV1-U/GTPURH;
    make
    if [ $? -ne 0 ]; then
        echo_error "Build GTPURH module failed, exiting"
        return 1
nikaeinn's avatar
nikaeinn committed
       $SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
       $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
gauthier's avatar
 
gauthier committed
compile_exmimo2_driver() {
    cd $OPENAIR_TARGETS/ARCH/EXMIMO/DRIVER/eurecom && make clean && make   || exit 1
    cd $OPENAIR_TARGETS/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT && make clean && make   || exit 1
    # TO DO CHECKS...
}


compile_ltesoftmodem() {
    cd $OPENAIR_TARGETS/RT/USER
    if [ -f Makefile ];  then
gauthier's avatar
 
gauthier committed
        rm -f ./lte-softmodem
gauthier's avatar
 
gauthier committed
        echo "LTE softmodem compiling directives: $SOFTMODEM_DIRECTIVES"
        if [ $OAI_CLEAN -ne 0 ]; then
            echo "Cleaning LTE softmodem"
            make cleanall > /dev/null 2>&1
        fi
        make -j $NUM_CPU $SOFTMODEM_DIRECTIVES
        if [ $? -ne 0 ]; then
            # to locate easily compilation error in log file
            make  $SOFTMODEM_DIRECTIVES
        if [ $? -ne 0 ]; then
            if [ ! -f ./lte-softmodem ]; then
gauthier's avatar
 
gauthier committed
                echo_error "Build lte-softmodem failed, returning"
                return 1
gauthier's avatar
 
gauthier committed
                cp -pf ./lte-softmodem  $OPENAIR_TARGETS/bin
gauthier's avatar
 
gauthier committed
                return 0
gauthier's avatar
 
gauthier committed
        else
gauthier's avatar
 
gauthier committed
            cp -pf ./lte-softmodem  $OPENAIR_TARGETS/bin
gauthier's avatar
 
gauthier committed
            return 0
        fi
    else
        echo_error "make file for oai softmodem not found, returning"
        return 1
    fi
}

compile_oaisim() {
    cd $OPENAIR_TARGETS/SIMU/USER
    if [ -f Makefile ]; then
nikaeinn's avatar
nikaeinn committed
        echo "Compiling for oaisim  target ($OAISIM_DIRECTIVES)"
gauthier's avatar
 
gauthier committed
        make cleanall > /dev/null
        make -j $NUM_CPU $OAISIM_DIRECTIVES
        if [ $? -ne 0 ]; then
            echo_error "Build oaisim failed, returning"
            return 1
gauthier's avatar
 
gauthier committed
            cp -pf ./oaisim $OPENAIR_TARGETS/bin
gauthier's avatar
 
gauthier committed
            return 0
        fi
    else
        echo_error "Makefile not found for oaisim target, returning"
        return 1
    fi
}

compile_unisim() {
    cd $OPENAIR1_DIR/SIMULATION/LTE_PHY
    if [ -f Makefile ]; then
nikaeinn's avatar
nikaeinn committed
        echo "Compiling for UNISIM target ..."
gauthier's avatar
 
gauthier committed
        make cleanall
        if [ $? -ne 0 ]; then
            echo_error "Build unisim failed, returning"
            return 1
gauthier's avatar
 
gauthier committed
            cp -pf ./dlsim     $OPENAIR_TARGETS/bin
            cp -pf ./ulsim     $OPENAIR_TARGETS/bin
            cp -pf ./pucchsim  $OPENAIR_TARGETS/bin
            cp -pf ./prachsim  $OPENAIR_TARGETS/bin
            cp -pf ./pdcchsim  $OPENAIR_TARGETS/bin
            cp -pf ./pbchsim   $OPENAIR_TARGETS/bin
            cp -pf ./mbmssim   $OPENAIR_TARGETS/bin
gauthier's avatar
 
gauthier committed
            return 0
        fi
    else
        echo_error "Configure failed, exiting"
        return 1
    fi
}
gauthier's avatar
gauthier committed

compile_nas_tools() {

    export NVRAM_DIR=$OPENAIR_TARGETS/bin
gauthier's avatar
gauthier committed
    cd $NVRAM_DIR
gauthier's avatar
gauthier committed
        if [ ! -f /tmp/nas_cleaned ]; then
            echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools veryveryclean"
            make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools veryveryclean
gauthier's avatar
gauthier committed
        fi
        echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all"
        make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all
        rm .ue.nvram0
        rm .usim.nvram0
gauthier's avatar
gauthier committed
        touch /tmp/nas_cleaned
}


compile_ue_ip_nw_driver() {
    cd $OPENAIR2_DIR && make ue_ip.ko
}

################################################
# 1. check if the executable functions exist
###############################################

check_for_ltesoftmodem_executable() {
    if [ ! -f $OPENAIR_TARGETS/RT/USER/lte-softmodem ];   then
        echo_error "Cannot find lte-softmodem executable object in directory $OPENAIR_TARGETS/RT/USER"
        echo_error "Check the compilation logs in bin/install_log.txt"
gauthier's avatar
 
gauthier committed
        exit 1
    fi
}

check_for_epc_executable() {
    if [ ! -f $OPENAIR3_DIR/objs/OAI_EPC/oai_epc ]; then
        echo_error "Cannot find oai_epc executable object in directory $OPENAIR3_DIR/objs/OAI_EPC/"
gauthier's avatar
gauthier committed
        echo_fatal "Please make sure you have compiled OAI EPC with --enable-standalone-epc option"
nikaeinn's avatar
 
nikaeinn committed
check_for_hss_executable() {
    if [ ! -f $OPENAIR3_DIR/OPENAIRHSS/objs/openair-hss ]; then
        echo_error "Cannot find openair-hss executable object in directory $OPENAIR3_DIR/OPENAIRHSS/objs/"
gauthier's avatar
gauthier committed
        echo_fatal "Please make sure you have compiled OAI HSS"
nikaeinn's avatar
 
nikaeinn committed
    fi
}

check_for_sgw_executable() {
    if [ ! -f $OPENAIR3_DIR/objs/OAI_SGW/oai_sgw ]; then
        echo_error "Cannot find oai_sgw executable object in directory $OPENAIR3_DIR/OPENAIRMME/objs/OAI_SGW/"
        echo_fatal "Please make sure you have compiled OAI EPC without --enable-standalone-epc option"
    fi
}

check_for_oaisim_executable() {
    if [ ! -f $OPENAIR_TARGETS/SIMU/USER/oaisim ]; then
        echo_error "Cannot find oaisim executable object in directory $OPENAIR_TARGETS/SIMU/USER"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_dlsim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/dlsim ];  then
        echo_error "Cannot find dlsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_ulsim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/ulsim ]; then
        echo_error "Cannot find ulsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_pucchsim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/pucchsim ]; then
        echo_error "Cannot find pucchsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_prachsim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/prachsim ]; then
        echo_error "Cannot find prachsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_pdcchsim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/pdcchsim ]; then
        echo_error "Cannot find pdcchsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_pbchsim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/pbchsim ]; then
        echo_error "Cannot find pbchsim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
    fi
}

check_for_mbmssim_executable() {
    if [ ! -f $OPENAIR1_DIR/SIMULATION/LTE_PHY/mbmssim ]; then
        echo_error "Cannot find mbmssim executable object in directory $OPENAIR1_DIR/SIMULATION/LTE_PHY"
        echo_error "Check the compilation logs in bin/install_log.txt"
gauthier's avatar
gauthier committed
check_for_nas_ue_executable() {
    if [ ! -f $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/UserProcess ]; then
        echo_error "Cannot find UserProcess executable object in directory  $OPENAIR3_DIR/NAS/EURECOM-NAS/bin"
gauthier's avatar
gauthier committed
        echo_fatal "Check the compilation logs in bin/install_log.txt"
    fi
}

nikaeinn's avatar
nikaeinn committed
################################################
# 1. check if the executable functions exist
###############################################

gauthier's avatar
gauthier committed
# arg1 is RT
gauthier's avatar
gauthier committed
# arg3 is ENB_S1
nikaeinn's avatar
nikaeinn committed
install_ltesoftmodem() {
    # RT
    if [ $1 = "RTAI" ]; then
gauthier's avatar
gauthier committed
        if [ ! -f /tmp/init_rt_done.tmp ]; then
nikaeinn's avatar
nikaeinn committed
            echo_info "  8.1 Insert RTAI modules"
nikaeinn's avatar
nikaeinn committed
            $SUDO insmod /usr/realtime/modules/rtai_hal.ko     > /dev/null 2>&1
            $SUDO insmod /usr/realtime/modules/rtai_sched.ko   > /dev/null 2>&1
            $SUDO insmod /usr/realtime/modules/rtai_sem.ko     > /dev/null 2>&1
            $SUDO insmod /usr/realtime/modules/rtai_fifos.ko   > /dev/null 2>&1
            $SUDO insmod /usr/realtime/modules/rtai_mbx.ko     > /dev/null 2>&1
            $SUDO touch /tmp/init_rt_done.tmp
            $SUDO chmod 666 /tmp/init_rt_done.tmp
nikaeinn's avatar
nikaeinn committed
        else
nikaeinn's avatar
nikaeinn committed
            echo_warning "  8.1 RTAI modules already inserted"
nikaeinn's avatar
nikaeinn committed
    #HW
    if [ $2 = "EXMIMO" ]; then
nikaeinn's avatar
nikaeinn committed
	echo_info "  8.2 [EXMIMO] creating RTAI fifos"
	for i in `seq 0 64`; do
nikaeinn's avatar
nikaeinn committed
	    have_rtfX=`ls /dev/ |grep -c rtf$i`;
	    if [ "$have_rtfX" -eq 0 ] ; then
		$SUDO mknod -m 666 /dev/rtf$i c 150 $i;
nikaeinn's avatar
nikaeinn committed
	    fi;
	done
	echo_info "  8.3 [EXMIMO] Build lte-softmodemdrivers"
	cd $OPENAIR_TARGETS/ARCH/EXMIMO/DRIVER/eurecom && make clean && make  # || exit 1
	cd $OPENAIR_TARGETS/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT && make clean && make  # || exit 1
nikaeinn's avatar
nikaeinn committed
	echo_info "  8.4 [EXMIMO] Setup RF card"
	cd $OPENAIR_TARGETS/RT/USER