build_helper.bash 40.7 KB
Newer Older
1 2 3 4 5
#/*
# * 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
6
# * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
# * 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
# */
21 22 23 24 25
################################################################################
# file build_helper.bash
# brief
# author Lionel Gauthier and Navid Nikaein
# company Eurecom
26
# email: lionel.gauthier@eurecom.fr and navid.nikaein@eurecom.fr
27 28 29 30 31
#
#######################################
#            Helper Func
######################################

gauthier's avatar
gauthier committed
32 33 34 35 36 37 38 39 40 41 42
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`
43 44

set_build_from_makefile(){
45
    BUILD_FROM_MAKEFILE=$1
46
}
nikaeinn's avatar
nikaeinn committed
47

48
check_for_root_rights() {
49

50 51
  #  if [[ $EUID -ne $ROOT_EUID ]]; then
    if [ $USER != "root" ]; then
52
        SUDO="sudo -E "
53
        echo "Run as a sudoers"
gauthier's avatar
gauthier committed
54
        return 1
55 56
    else
        echo  "Run as a root"
gauthier's avatar
gauthier committed
57
        return 0
58 59 60 61 62
    fi
}

test_install_package() {
  # usage: test_install_package package_name
63

64 65
 if [ $# -eq 1 ]; then
      dpkg -s "$1" > /dev/null 2>&1 && {
66
          echo "$1 is installed."
67
      } || {
68
          echo "$1 is not installed."
gauthier's avatar
gauthier committed
69
          OAI_INSTALLED=0
70
          $SUDO apt-get install -y $@
71 72 73 74
      }
  fi
}

nikaeinn's avatar
nikaeinn committed
75
test_uninstall_package() {
76

nikaeinn's avatar
nikaeinn committed
77 78
 if [ $# -eq 1 ]; then
      dpkg -s "$1" > /dev/null 2>&1 && {
79 80
          $SUDO apt-get remove --assume-yes $1
          echo "$1 is uninstalled."
nikaeinn's avatar
nikaeinn committed
81
      } || {
82
          echo "$1 is not installed."
nikaeinn's avatar
nikaeinn committed
83 84 85
      }
  fi
}
86 87 88 89 90 91 92 93 94 95
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
96
        return 64  # 64-bit stuff here
97
    else
gauthier's avatar
gauthier committed
98
        if [ ${MACHINE_TYPE} = "i686" ]; then
99
            return 32 # 32-bit stuff here
100 101
        else
            return -1
gauthier's avatar
gauthier committed
102
        fi
103 104 105 106 107 108 109 110
    fi
}

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

####################################################
111
# 1. install the required packages
112 113 114
####################################################

make_certs(){
nikaeinn's avatar
nikaeinn committed
115 116

 # for certtificate generation
117
    rm -rf demoCA
nikaeinn's avatar
nikaeinn committed
118
    mkdir -m 777 -p demoCA
119 120
    echo 01 > demoCA/serial
    touch demoCA/index.txt
121

nikaeinn's avatar
nikaeinn committed
122
    echo "creating the certificate"
123

124
    user=$(whoami)
nikaeinn's avatar
nikaeinn committed
125
    HOSTNAME=$(hostname -f)
126 127

    echo "Creating certificate for user '$HOSTNAME'"
128

129 130
# 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
131

nikaeinn's avatar
nikaeinn committed
132 133 134 135 136
   # 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
137

138
    if [ ! -d /usr/local/etc/freeDiameter ];  then
gauthier's avatar
gauthier committed
139 140
        echo "Creating non existing directory: /usr/local/etc/freeDiameter/"
        $SUDO mkdir /usr/local/etc/freeDiameter/
141
    fi
142

nikaeinn's avatar
nikaeinn committed
143 144 145
    echo "Copying *.pem to /usr/local/etc/freeDiameter/"
    $SUDO cp *.pem /usr/local/etc/freeDiameter/
    mv *.pem bin/
146

147 148 149 150 151 152
# 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

}

153
check_install_nettle(){
154 155
    if [ ! -f ./.lock_oaibuild ]; then
	if [ $UBUNTU_REL = "12.04" ]; then
156 157
	    test_uninstall_package nettle-dev
	    test_uninstall_package nettle-bin
158

159 160 161 162
	    if [ ! -d /usr/local/src/ ]; then
		echo "/usr/local/src/ doesn't exist please create one"
		exit -1
	    fi
163

164 165 166 167
	    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
168

169
	    cd /usr/local/src/
170

171
	    echo "Downloading nettle archive"
172

173 174 175 176 177 178 179 180 181
	    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
182 183 184 185


	    $SUDO wget ftp://ftp.lysator.liu.se/pub/security/lsh/nettle-2.5.tar.gz
	    $SUDO gunzip nettle-2.5.tar.gz
186 187 188
	    $SUDO echo "Uncompressing nettle archive"
	    $SUDO tar -xf nettle-2.5.tar
	    cd nettle-2.5/
189
	    $SUDO ./configure --disable-openssl --enable-shared --prefix=/usr
190 191 192 193
	    if [ $? -ne 0 ]; then
		exit -1
	    fi
	    echo "Compiling nettle"
194 195 196
	    $SUDO make -j $NUM_CPU
	    $SUDO make check
	    $SUDO make install
197 198 199 200 201
	    cd ../
	fi
    fi
}

202
check_install_freediamter(){
203 204

    if [ $UBUNTU_REL = "12.04" ]; then
nikaeinn's avatar
nikaeinn committed
205

nikaeinn's avatar
nikaeinn committed
206 207 208 209
	if [ ! -d /usr/local/src/ ]; then
	    echo "/usr/local/src/ doesn't exist please create one"
	    exit -1
	fi
210

nikaeinn's avatar
nikaeinn committed
211 212 213 214
	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
215

nikaeinn's avatar
nikaeinn committed
216
	cd /usr/local/src/
217

nikaeinn's avatar
nikaeinn committed
218
	echo "Downloading nettle archive"
219

nikaeinn's avatar
nikaeinn committed
220 221 222 223 224 225 226 227 228
	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
229 230 231 232


	$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
233 234 235
	$SUDO echo "Uncompressing nettle archive"
	$SUDO tar -xf nettle-2.5.tar
	cd nettle-2.5/
236
	$SUDO ./configure --disable-openssl --enable-shared --prefix=/usr
nikaeinn's avatar
nikaeinn committed
237 238 239 240
	if [ $? -ne 0 ]; then
	    exit -1
	fi
	echo "Compiling nettle"
241 242 243
	$SUDO make -j $NUM_CPU
	$SUDO make check
	$SUDO make install
nikaeinn's avatar
nikaeinn committed
244
	cd ../
245
    fi
246

247
    echo "Downloading gnutls archive"
248

knopp's avatar
knopp committed
249 250
    if [ -f gnutls-3.1.23.tar.xz ];  then
	$SUDO rm -f gnutls-3.1.23.tar.xz
251
    fi
knopp's avatar
knopp committed
252 253
    if [ -d gnutls-3.1.23/ ];  then
	$SUDO rm -rf gnutls-3.1.23/
254
    fi
255

nikaeinn's avatar
nikaeinn committed
256
    test_uninstall_package libgnutls-dev
257 258

    $SUDO wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.23.tar.xz
knopp's avatar
knopp committed
259
    $SUDO tar -xf gnutls-3.1.23.tar.xz
nikaeinn's avatar
nikaeinn committed
260
    echo "Uncompressing gnutls archive ($PWD)"
knopp's avatar
knopp committed
261
    cd gnutls-3.1.23/
262 263 264 265 266
    $SUDO ./configure --prefix=/usr
    if [ $? -ne 0 ];   then
	exit -1
    fi
    echo "Compiling gnutls"
267 268
    $SUDO make -j $NUM_CPU
    $SUDO make install
269
    cd ../
270

271
    echo "Downloading freeDiameter archive"
272

273 274 275 276 277 278
    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
279 280 281

    $SUDO wget http://www.freediameter.net/hg/freeDiameter/archive/1.1.5.tar.gz
    $SUDO tar -xzf 1.1.5.tar.gz
282 283
    echo "Uncompressing freeDiameter archive"
    cd freeDiameter-1.1.5
284
    $SUDO patch -p1 < $OPENAIR3_DIR/S6A/freediameter/freediameter-1.1.5.patch
285 286
    $SUDO mkdir build
    cd build
287
    $SUDO cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ../
288 289 290 291
    if [ $? -ne 0 ];  then
	exit -1
    fi
    echo "Compiling freeDiameter"
292
    $SUDO make -j $NUM_CPU
293
#make help
294 295 296
    $SUDO make test
    $SUDO sudo make install

nikaeinn's avatar
nikaeinn committed
297
#    make_certs
298

299 300
}

nikaeinn's avatar
nikaeinn committed
301 302

test_is_host_reachable() {
gauthier's avatar
gauthier committed
303 304
    ping -c 1 $1 > /dev/null || { echo_fatal "$2 host $1 does not respond to ping" >&2 ; }
    echo_success "$2 host $1 is reachable"
nikaeinn's avatar
nikaeinn committed
305 306 307
}


308 309 310 311 312 313 314 315 316
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
317
                return 0
318 319 320 321 322
            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..."
323
    cd $OPENAIR3_DIR/S6A/freediameter
324
    ./make_certs.sh ${1:-'eur'}
325
    if [ $# -lt 2 ] ; then
gauthier's avatar
gauthier committed
326 327
        check_epc_s6a_certificate ${1:-'eur'}  2
        return $?
nikaeinn's avatar
nikaeinn committed
328 329
    else
       exit 1
330 331 332 333
    fi
}


334
check_hss_s6a_certificate() {
335
    if [ -d /usr/local/etc/freeDiameter ]; then
nikaeinn's avatar
nikaeinn committed
336 337
        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`
338 339 340
            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
341
                return 0
342
            else
343
                echo_error "Bad hss hostname found in cert file: "$full_hostname " hostname is "`hostname`
344 345 346 347 348
            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..."
349
    cd $OPENAIR3_DIR/OPENAIRHSS/conf
350 351
    ./make_certs.sh ${1:-'eur'}
    if [ $# -lt 2 ] ; then
gauthier's avatar
gauthier committed
352 353
        check_hss_s6a_certificate ${1:-'eur'} 2
        return $?
gauthier's avatar
gauthier committed
354 355
    else
       exit 1
nikaeinn's avatar
nikaeinn committed
356
    fi
357 358
}

359
check_install_usrp_uhd_driver(){
360
    if [ ! -f /etc/apt/sources.list.d/ettus.list ] ; then
gauthier's avatar
gauthier committed
361 362
        $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
363
    fi
364
    $SUDO apt-get install -t $UBUNTU_REL_NAME uhd
365 366
    test_install_package python
    test_install_package libboost-all-dev
367
    test_install_package libusb-1.0-0-dev
368 369 370
    #test_install_package uhd
}

371
check_install_oai_software() {
372 373

    if [ ! -f ./.lock_oaibuild ]; then
gauthier's avatar
gauthier committed
374
        $SUDO apt-get update
375
        if [ $UBUNTU_REL = "12.04" ]; then
gauthier's avatar
gauthier committed
376 377
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
378
        else
379 380
            test_install_package nettle-dev
            test_install_package nettle-bin
381 382 383 384
        fi
        test_install_package autoconf
        test_install_package automake
        test_install_package bison
gauthier's avatar
gauthier committed
385
        test_install_package build-essential
gauthier's avatar
gauthier committed
386
        test_install_package dialog
387
        test_install_package flex
gauthier's avatar
gauthier committed
388 389
        test_install_package gawk
        test_install_package gcc
390
        test_install_package gdb
gauthier's avatar
gauthier committed
391 392 393 394
        test_install_package make
        test_install_package cmake
        test_install_package openssh-client
        test_install_package openssh-server
395
        sudo service ssh start
396
        test_install_package unzip
gauthier's avatar
gauthier committed
397 398 399 400 401 402 403 404 405 406 407
        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
408
        test_install_package gdb
gauthier's avatar
gauthier committed
409 410 411 412 413 414 415 416
        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
417 418
        test_install_package liblapack-dev
        test_install_package liblapack-dev
419 420 421 422 423
#	if [ $MACHINE_ARCH = 64 ]; then
            test_install_package libconfig8-dev
#	else
#            test_install_package libconfig-dev
#	fi
gauthier's avatar
gauthier committed
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
        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
441
        test_install_package libssl-dev
gauthier's avatar
gauthier committed
442 443 444 445 446 447 448 449
        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
450

gauthier's avatar
gauthier committed
451
#        test_install_package libboost-all-dev
452 453

        if [ $OAI_INSTALLED = 1 ]; then
gauthier's avatar
gauthier committed
454
            touch ./.lock_oaibuild
455 456
        fi

457
     else
gauthier's avatar
gauthier committed
458
        echo_info "All the required packages installed: skip"
459 460
    fi

461
}
462

463
check_install_hss_software() {
464
    if [ ! -f ./.lock_oaibuild ]; then
gauthier's avatar
gauthier committed
465
        $SUDO apt-get update
466
        if [ $UBUNTU_REL = "12.04" ]; then
gauthier's avatar
gauthier committed
467 468
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
469
        else
470 471
            test_install_package nettle-dev
            test_install_package nettle-bin
472 473 474 475
        fi
	test_install_package autoconf
	test_install_package automake
	test_install_package bison
476 477
	test_install_package build-essential
	test_install_package cmake
478
	test_install_package cmake-curses-gui
gauthier's avatar
gauthier committed
479 480
    test_install_package dialog
    test_install_package dkms
481
	test_install_package flex
482 483
	test_install_package gawk
	test_install_package gcc
484 485
	test_install_package gdb
	test_install_package guile-2.0-dev
486
	test_install_package g++
487 488 489 490 491 492 493 494 495 496
	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`
497
	test_install_package make
498 499
	test_install_package mysql-client
	test_install_package mysql-server-core-5.5
gauthier's avatar
gauthier committed
500
	test_install_package mysql-server
501 502
	test_install_package openssh-client
	test_install_package openssh-server
503
        sudo service ssh start
504
	test_install_package phpmyadmin
505
	test_install_package python-dev
506
	test_install_package sshfs
507 508
	test_install_package swig
	test_install_package unzip
nikaeinn's avatar
nikaeinn committed
509 510
#	test_install_package nettle-bin
#	test_install_package nettle-dev
511
	test_install_package valgrind
512

513
	if [ $OAI_INSTALLED = 1 ]; then
514
	    touch ./.lock_oaibuild
515 516
	fi

517
    else
nikaeinn's avatar
nikaeinn committed
518
	echo_info "All the required packages installed: skip"
519
    fi
520 521 522 523 524

}

check_install_epc_software() {

525
    if [ ! -f ./.lock_oaibuild ]; then
gauthier's avatar
gauthier committed
526
        $SUDO apt-get update
527
        if [ $UBUNTU_REL = "12.04" ]; then
gauthier's avatar
gauthier committed
528 529
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
530
        else
531 532
            test_install_package nettle-dev
            test_install_package nettle-bin
533
        fi
gauthier's avatar
gauthier committed
534 535 536 537 538 539 540
        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
541
        test_install_package dialog
gauthier's avatar
gauthier committed
542 543 544 545 546 547
        test_install_package ethtool
        test_install_package flex
        test_install_package g++
        test_install_package gawk
        test_install_package gcc
        test_install_package gccxml
548
        test_install_package gdb
gauthier's avatar
gauthier committed
549 550 551 552 553
        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
554
        test_install_package iptables-dev
gauthier's avatar
gauthier committed
555 556 557 558 559
        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
560
            test_install_package libconfig8-dev
gauthier's avatar
gauthier committed
561
#        else
nikaeinn's avatar
nikaeinn committed
562
#            test_install_package libconfig-dev
gauthier's avatar
gauthier committed
563 564 565 566 567 568 569 570 571 572 573 574 575
#       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
576
        test_install_package libssl-dev
gauthier's avatar
gauthier committed
577
        test_install_package libtasn1-3-dev
578
        test_install_package libtool
gauthier's avatar
gauthier committed
579 580 581 582 583 584
        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
585
        $SUDO service ssh start
gauthier's avatar
gauthier committed
586 587 588 589 590 591 592 593 594 595 596 597
        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
598 599

        if [ $OAI_INSTALLED = 1 ]; then
gauthier's avatar
gauthier committed
600
            touch ./.lock_oaibuild
601 602
        fi

603
    else
gauthier's avatar
gauthier committed
604
        echo_info "All the required packages installed: skip"
605
    fi
606

607 608 609
}

check_install_asn1c(){
610

611
    test_command_install_script   "asn1c" "$OPENAIR_TARGETS/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO"
612

613
    # One mor check about version of asn1c
614 615
    ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE="ASN.1 Compiler, v0.9.24"
    ASN1C_COMPILER_VERSION_MESSAGE=`asn1c -h 2>&1 | grep -i ASN\.1\ Compiler`
616
    ##ASN1C_COMPILER_VERSION_MESSAGE=`trim $ASN1C_COMPILER_VERSION_MESSAGE`
617
    if [ "$ASN1C_COMPILER_VERSION_MESSAGE" != "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE" ]; then
618
      #  diff <(echo -n "$ASN1C_COMPILER_VERSION_MESSAGE") <(echo -n "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE")
619 620 621
        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
622
            if [[ $answer = [YyNn] ]]; then
623
                [[ $answer = [Yy] ]] && $OPENAIR_TARGETS/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO
624 625
                [[ $answer = [Nn] ]] && echo_error "Version of asn1c is not the required one, exiting." && exit 1
                break
gauthier's avatar
gauthier committed
626
            fi
627 628
        done
    fi
629

630 631 632
}

#################################################
633
# 2. compile
634 635
################################################
compile_hss() {
636
    cd $OPENAIR3_DIR/OPENAIRHSS
637

gauthier's avatar
gauthier committed
638 639 640 641 642 643
    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
644
    fi
gauthier's avatar
gauthier committed
645 646

    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
647

648 649
    if [ ! -n "$OBJ_DIR" ]; then
        OBJ_DIR="objs"
gauthier's avatar
gauthier committed
650
        mkdir --verbose -m 777 ./$OBJ_DIR
651 652 653
    else
        OBJ_DIR=`basename $OBJ_DIR`
    fi
654

gauthier's avatar
gauthier committed
655 656 657
    if [ ! -f "$OBJ_DIR"/Makefile ]; then
        if [ ! -d m4 ]; then
            mkdir --verbose -m 777 m4
658 659
        fi
        echo_success "Invoking autogen"
660 661 662 663 664
        ./autogen.sh
        if [ $? -ne 0 ]; then
            return 1
        fi
        cd $OBJ_DIR
gauthier's avatar
gauthier committed
665
        echo_success "Invoking configure"
666
        ../configure
gauthier's avatar
gauthier committed
667 668 669
        if [ $? -ne 0 ]; then
            return 1
        fi
670
    else
671
        cd $OBJ_DIR
672
    fi
gauthier's avatar
gauthier committed
673

674
    if [ -f Makefile ];  then
gauthier's avatar
gauthier committed
675
        echo_success "Compiling..."
676
        make ; #-j $NUM_CPU
677 678
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
nikaeinn's avatar
nikaeinn committed
679
            return 1
680
        else
681
            return 0
682 683
        fi
    else
684
        echo_error "Configure failed, aborting"
685
    fi
686
    return 1
687 688 689 690
}


compile_epc() {
691
    cd $OPENAIR3_DIR
nikaeinn's avatar
nikaeinn committed
692
    if [ $1 = 1 ]; then
gauthier's avatar
gauthier committed
693
        echo_info "build a clean EPC"
694
        bash_exec "rm -rf objs"
nikaeinn's avatar
nikaeinn committed
695
    fi
696 697 698 699 700 701 702 703 704 705 706 707
    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
708
        bash_exec "autoreconf -i -f"
709
        echo_success "Invoking autogen"
710
        bash_exec "libtoolize"
711
        bash_exec "./autogen.sh"
712 713
        cd ./$OBJ_DIR
        echo_success "Invoking configure"
714
        if [ $DEBUG -ne 0 ]; then
715 716 717 718
            ../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
719 720 721 722
    else
        cd ./$OBJ_DIR
    fi

nikaeinn's avatar
nikaeinn committed
723 724
#    pkill oai_epc
#    pkill tshark
725 726 727 728 729 730

    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
731
            return 1
732
        else
gauthier's avatar
gauthier committed
733
            cp -pf ./OAI_EPC/oai_epc  $OPENAIR_TARGETS/bin
gauthier's avatar
gauthier committed
734
        fi
735 736
    else
        echo_error "Configure failed, exiting"
nikaeinn's avatar
nikaeinn committed
737
        return 1
738
    fi
739

740
    cd $OPENAIR3_DIR/GTPV1-U/GTPUAH;
741 742 743 744
    make
    if [ $? -ne 0 ]; then
        echo_error "Build GTPUAH module failed, exiting"
        return 1
745
    else
nikaeinn's avatar
nikaeinn committed
746 747
       	$SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
        $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
748
    fi
749

750
    cd $OPENAIR3_DIR/GTPV1-U/GTPURH;
751 752 753 754
    make
    if [ $? -ne 0 ]; then
        echo_error "Build GTPURH module failed, exiting"
        return 1
755
    else
nikaeinn's avatar
nikaeinn committed
756 757
       $SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
       $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
758 759
    fi
    return 0
760 761
}

gauthier's avatar
gauthier committed
762 763 764 765 766 767 768
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...
}


769 770 771
compile_ltesoftmodem() {
    cd $OPENAIR_TARGETS/RT/USER
    if [ -f Makefile ];  then
gauthier's avatar
gauthier committed
772
        rm -f ./lte-softmodem
gauthier's avatar
gauthier committed
773 774 775 776 777 778 779 780 781
        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
782
        fi
783
        if [ $? -ne 0 ]; then
784
            if [ ! -f ./lte-softmodem ]; then
gauthier's avatar
gauthier committed
785 786
                echo_error "Build lte-softmodem failed, returning"
                return 1
787
            else
gauthier's avatar
gauthier committed
788
                cp -pf ./lte-softmodem  $OPENAIR_TARGETS/bin
gauthier's avatar
gauthier committed
789
                return 0
790
            fi
gauthier's avatar
gauthier committed
791
        else
gauthier's avatar
gauthier committed
792
            cp -pf ./lte-softmodem  $OPENAIR_TARGETS/bin
gauthier's avatar
gauthier committed
793
            return 0
794 795 796 797 798 799 800 801 802 803
        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
804
        echo "Compiling for oaisim  target ($OAISIM_DIRECTIVES)"
gauthier's avatar
gauthier committed
805
        make cleanall > /dev/null
806
        make -j $NUM_CPU $OAISIM_DIRECTIVES
807 808 809
        if [ $? -ne 0 ]; then
            echo_error "Build oaisim failed, returning"
            return 1
810
        else
gauthier's avatar
gauthier committed
811
            cp -pf ./oaisim $OPENAIR_TARGETS/bin
gauthier's avatar
gauthier committed
812
            return 0
813 814 815 816 817 818 819 820 821 822
        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
823
        echo "Compiling for UNISIM target ..."
gauthier's avatar
gauthier committed
824
        make cleanall
825
        make  -j $NUM_CPU all
826 827 828
        if [ $? -ne 0 ]; then
            echo_error "Build unisim failed, returning"
            return 1
829
        else
gauthier's avatar
gauthier committed
830 831 832 833 834 835 836
            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
837
            return 0
838 839 840 841 842 843
        fi
    else
        echo_error "Configure failed, exiting"
        return 1
    fi
}
gauthier's avatar
gauthier committed
844 845 846 847

compile_nas_tools() {

    export NVRAM_DIR=$OPENAIR_TARGETS/bin
848

gauthier's avatar
gauthier committed
849
    cd $NVRAM_DIR
850

gauthier's avatar
gauthier committed
851
        if [ ! -f /tmp/nas_cleaned ]; then
852 853
            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
854
        fi
855 856
        echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all"
        make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all
857 858
        rm .ue.nvram0
        rm .usim.nvram0
gauthier's avatar
gauthier committed
859 860 861 862 863 864 865 866
        touch /tmp/nas_cleaned
}


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

867 868 869 870 871 872 873
################################################
# 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"
874
        echo_error "Check the compilation logs in bin/install_log.txt"
gauthier's avatar
gauthier committed
875
        exit 1
876 877 878 879
    fi
}

check_for_epc_executable() {
880 881
    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
882
        echo_fatal "Please make sure you have compiled OAI EPC with --enable-standalone-epc option"
883 884 885
    fi
}

nikaeinn's avatar
nikaeinn committed
886
check_for_hss_executable() {
887 888
    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
889
        echo_fatal "Please make sure you have compiled OAI HSS"
nikaeinn's avatar
nikaeinn committed
890 891 892
    fi
}

893
check_for_sgw_executable() {
894
    if [ ! -f $OPENAIR3_DIR/objs/OAI_SGW/oai_sgw ]; then
895 896 897 898 899 900 901 902
        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"
903
        echo_error "Check the compilation logs in bin/install_log.txt"
904 905 906 907 908 909
    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"
910
        echo_error "Check the compilation logs in bin/install_log.txt"
911 912 913 914 915 916
    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"
917
        echo_error "Check the compilation logs in bin/install_log.txt"
918 919 920 921 922 923
    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"
924
        echo_error "Check the compilation logs in bin/install_log.txt"
925 926 927 928 929 930
    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"
931
        echo_error "Check the compilation logs in bin/install_log.txt"
932 933 934 935 936 937
    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"
938
        echo_error "Check the compilation logs in bin/install_log.txt"
939 940 941 942 943 944
    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"
945
        echo_error "Check the compilation logs in bin/install_log.txt"
946 947 948 949 950 951
    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"
952
        echo_error "Check the compilation logs in bin/install_log.txt"
953 954
    fi
}
nikaeinn's avatar
nikaeinn committed
955

gauthier's avatar
gauthier committed
956
check_for_nas_ue_executable() {
957 958
    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
959 960 961 962
        echo_fatal "Check the compilation logs in bin/install_log.txt"
    fi
}

nikaeinn's avatar
nikaeinn committed
963 964 965 966
################################################
# 1. check if the executable functions exist
###############################################

gauthier's avatar
gauthier committed
967
# arg1 is RT
968
# arg2 is HW
gauthier's avatar
gauthier committed
969
# arg3 is ENB_S1
nikaeinn's avatar
nikaeinn committed
970 971
install_ltesoftmodem() {
    # RT
972
    if [ $1 = "RTAI" ]; then
gauthier's avatar
gauthier committed
973
        if [ ! -f /tmp/init_rt_done.tmp ]; then
nikaeinn's avatar
nikaeinn committed
974
            echo_info "  8.1 Insert RTAI modules"
nikaeinn's avatar
nikaeinn committed
975 976 977 978 979 980 981
            $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
982
        else
nikaeinn's avatar
nikaeinn committed
983
            echo_warning "  8.1 RTAI modules already inserted"
nikaeinn's avatar
nikaeinn committed
984 985
        fi
    fi
nikaeinn's avatar
nikaeinn committed
986
    #HW
987
    if [ $2 = "EXMIMO" ]; then
nikaeinn's avatar
nikaeinn committed
988
	echo_info "  8.2 [EXMIMO] creating RTAI fifos"
989
	for i in `seq 0 64`; do
nikaeinn's avatar
nikaeinn committed
990
	    have_rtfX=`ls /dev/ |grep -c rtf$i`;
991 992
	    if [ "$have_rtfX" -eq 0 ] ; then
		$SUDO mknod -m 666 /dev/rtf$i c 150 $i;
nikaeinn's avatar
nikaeinn committed
993 994 995 996 997
	    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
998

nikaeinn's avatar
nikaeinn committed
999 1000 1001
	echo_info "  8.4 [EXMIMO] Setup RF card"
	cd $OPENAIR_TARGETS/RT/USER
	. ./init_exmimo2.sh
1002
    else
nikaeinn's avatar
nikaeinn committed
1003 1004 1005 1006
	if [ $2 = "USRP" ]; then
	    echo_info "  8.2 [USRP] "
	fi

nikaeinn's avatar
nikaeinn committed
1007
    fi
1008

nikaeinn's avatar
nikaeinn committed
1009
    # ENB_S1
1010
    if [ $3 = 0 ]; then
gauthier's avatar
gauthier committed
1011 1012
        cd $OPENAIR2_DIR && make clean && make nasmesh_netlink.ko  #|| exit 1
        cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make  # || exit 1
nikaeinn's avatar
nikaeinn committed
1013
    fi
1014

nikaeinn's avatar
nikaeinn committed
1015 1016
}

gauthier's avatar
gauthier committed
1017
# arg1 is ENB_S1 'boolean'
nikaeinn's avatar
nikaeinn committed
1018
install_oaisim() {
1019
   if [ $1 = 0 ]; then
gauthier's avatar
gauthier committed
1020 1021 1022 1023 1024
       cd $OPENAIR2_DIR && make clean && make nasmesh_netlink.ko  #|| exit 1
       cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make  # || exit 1
   else
       compile_ue_ip_nw_driver
       install_nas_tools
1025 1026
   fi

nikaeinn's avatar
nikaeinn committed
1027
}
1028

gauthier's avatar
gauthier committed
1029 1030 1031

install_nas_tools() {
    cd $OPENAIR_TARGETS/bin
1032 1033
    if [ ! -f .ue.nvram0 ]; then
        echo_success "generate .ue_emm.nvram0 .ue.nvram0"
1034
        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --gen
gauthier's avatar
gauthier committed
1035 1036
    fi

1037 1038
    if [ ! -f .usim.nvram0 ]; then
        echo_success "generate .usim.nvram0"
1039
        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --gen
gauthier's avatar
gauthier committed
1040
    fi
1041 1042
    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --print
    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --print
gauthier's avatar
gauthier committed
1043 1044
}

nikaeinn's avatar
nikaeinn committed
1045
install_nasmesh(){
1046
    echo_success "LOAD NASMESH IP DRIVER FOR UE AND eNB"
nikaeinn's avatar
nikaeinn committed
1047 1048 1049 1050 1051 1052
    (cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make)
    (cd $OPENAIR2_DIR && make clean && make nasmesh_netlink_address_fix.ko)
    $SUDO rmmod nasmesh
    $SUDO insmod $OPENAIR2_DIR/NAS/DRIVER/MESH/nasmesh.ko
}

1053 1054 1055 1056 1057 1058
##################################
# create HSS DB
################################

# arg 1 is mysql user      (root)
# arg 2 is mysql password  (linux)
gauthier's avatar
gauthier committed
1059 1060 1061
# arg 3 is hss username    (hssadmin)
# arg 4 is hss password    (admin)
# arg 5 is database name   (oai_db)
1062
create_hss_database(){
gauthier's avatar
gauthier committed
1063
    EXPECTED_ARGS=5
1064 1065
    E_BADARGS=65
    MYSQL=`which mysql`
nikaeinn's avatar
nikaeinn committed
1066
    rv=0
1067 1068
    if [ $# -ne $EXPECTED_ARGS ]
    then
gauthier's avatar
gauthier committed
1069
        echo_fatal "Usage: $0 dbuser dbpass hssuser hsspass databasename"
gauthier's avatar
gauthier committed
1070
        rv=1
1071 1072
    fi

1073
    set_openair_env
1074

gauthier's avatar
gauthier committed
1075 1076 1077 1078 1079
    # removed %
    #Q1="GRANT ALL PRIVILEGES ON *.* TO '$3'@'%' IDENTIFIED BY '$4' WITH GRANT OPTION;"
    Q1="GRANT ALL PRIVILEGES ON *.* TO '$3'@'localhost' IDENTIFIED BY '$4' WITH GRANT OPTION;"
    Q2="FLUSH PRIVILEGES;"
    SQL="${Q1}${Q2}"
1080 1081
    $MYSQL -u $1 --password=$2 -e "$SQL"
    if [ $? -ne 0 ]; then
gauthier's avatar
gauthier committed
1082
       echo_error "$3 permissions failed"
gauthier's avatar
gauthier committed
1083
       return 1
1084
    else
gauthier's avatar
gauthier committed
1085
       echo_success "$3 permissions succeeded"
1086
    fi
1087 1088


gauthier's avatar
gauthier committed
1089 1090 1091 1092 1093 1094 1095 1096 1097
    Q1="CREATE DATABASE IF NOT EXISTS ${BTICK}$5${BTICK};"
    SQL="${Q1}"
    $MYSQL -u $3 --password=$4 -e "$SQL"
    if [ $? -ne 0 ]; then
       echo_error "$5 creation failed"
       return 1
    else
       echo_success "$5 creation succeeded"
    fi
1098 1099


gauthier's avatar
gauthier committed
1100
    # test if tables have been created
gauthier's avatar
gauthier committed
1101
    mysql -u $3 --password=$4  -e "desc $5.users" > /dev/null 2>&1
1102 1103

    if [ $? -eq 1 ]; then
1104
        $MYSQL -u $3 --password=$4 $5 < $OPENAIR3_DIR/OPENAIRHSS/db/oai_db.sql
gauthier's avatar
gauthier committed
1105
        if [ $? -ne 0 ]; then
gauthier's avatar
gauthier committed
1106
            echo_error "$5 tables creation failed"
gauthier's avatar
gauthier committed
1107 1108
            return 1
        else
gauthier's avatar
gauthier committed
1109
            echo_success "$5 tables creation succeeded"
gauthier's avatar
gauthier committed
1110
        fi
1111
    fi
1112

gauthier's avatar
gauthier committed
1113
    return 0
1114 1115
}

1116
################################
1117
# set_openair_env
1118 1119 1120
###############################
set_openair_env(){

1121 1122 1123
    fullpath=`readlink -f $BASH_SOURCE`
    [ -f "/.$fullpath" ] || fullpath=`readlink -f $PWD/$fullpath`
    openair_path=${fullpath%/targets/*}
1124
    openair_path=${openair_path%/openair3/*}
1125 1126 1127
    openair_path=${openair_path%/openair[123]/*}

    export OPENAIR_DIR=$openair_path
1128
    export OPENAIR_HOME=$openair_path
1129 1130 1131
    export OPENAIR1_DIR=$openair_path/openair1
    export OPENAIR2_DIR=$openair_path/openair2
    export OPENAIR3_DIR=$openair_path/openair3
1132
    export OPENAIR3_DIR=$openair_path/openair3
1133
    export OPENAIR_TARGETS=$openair_path/targets
1134 1135

}
1136 1137 1138 1139 1140 1141 1142

########################################
### print help
######################################

print_help(){
    echo_success "Name : build_oai  - install and build OAI"
gauthier's avatar
gauthier committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
    echo_success "Usage: build_oai.bash -a -b -c -d -e RTAI -m -r REL8 -s -t OAISIM -w EXMIMO -x"
    echo_success "-a | --doxygen                          : Enable doxygen for documentation (default disabled)"
    echo_success "-b | --disable-s1                       : Disable S1 interface for eNB (default enabled)"
    echo_success "-c | --clean                            : Enable clean OAI build (default disabled)"
    echo_success "-C | --config-file                      : Set the config file local path"
    echo_success "-d | --debug                            : Enable debug mode (default disabled)"
    echo_success "-D | --disable-check-installed-software : Disable the checking of installed software (default is check)"
    echo_success "-e | --realtime                         : Set realtime mode: RTAI, NONE (default NONE)"
    echo_success "-g | --run-with-gdb                     : Run the executable built by this script with gdb"
    echo_success "-K | --itti-dump-file                   : Set the execution events trace file"
    echo_success "-l | --build-target                     : Set the LTE build target: ENB,EPC,HSS,NONE (default ENB)"
    echo_success "-m | --build-from-makefile              : Enable build from the makefile (default disabled)"
    echo_success "-r | --3gpp-release                     : Set the release: REL8, REL10 (default REL8)"
1156
    echo_success "-p | --wireshark                        : enable wireshark interface for L2 pdus"
gauthier's avatar
gauthier committed
1157 1158 1159 1160 1161 1162 1163
    echo_success "-R | --run                              : Run the executable built by this script"
    echo_success "-s | --check                            : Enable OAI testing and sanity check (default disabled)"
    echo_success "-t | --enb-build-target                 : Set the eNB build target: ALL, SOFTMODEM,OAISIM,UNISIM (default ALL)"
    echo_success "-V | --vcd                              : Log vcd events"
    echo_success "-w | --hardware                         : Set the hardware platform: EXMIMO, USRP (also installs UHD driver), ETHERNET, NONE, (default EXMIMO)"
    echo_success "-x | --xforms                           : Enable xforms (default disabled)"
    echo_success "-z | --defaults                         : Set the default build options"
1164
}
nikaeinn's avatar
nikaeinn committed
1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179

print_help_perf(){
    echo_success "Name : perf_oai  generate traffic and evaluate the performance "
    echo_success "Usage: perf_oai.bash -l ITG "
    echo_success "-l | --perf-app               : Set Performance evaluation app: ITGS, ITGD,PING, OTG-OAISIM, OTG-CBA, (default PING)"
    echo_success "-m | --owd                    : enable D-ITG one-way-delay meter (default disabled)"
    echo_success "-e | --duration               : set the duration of the experiment (default 60000ms)"
    echo_success "-i | --idt-dist               : set the distribution of the inter-departure time: CONSTANT, UNIFORM,EXPONENTIAL (default CONSTANT)"
    echo_success "-s | --ps-dist                : set the distribution of the inter-departure time (default CONSTANT, available options: UNIFORM,EXPONENTIAL)"
    echo_success "-d | --dst                    : set the destination address (default 127.0.0.1)"
    echo_success "-p | --dst-port               : set the destination address (default NONE)"
    echo_success "-t | --test                   : enable test mode to validate the functionality (default disabled)"
    echo_success "-k | --keep-log-file          : keep the log files (default disabled)"

}
1180
###############################
1181
## echo and  family
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
###############################
black='\E[30m'
red='\E[31m'
green='\E[32m'
yellow='\E[33m'
blue='\E[34m'
magenta='\E[35m'
cyan='\E[36m'
white='\E[37m'
reset_color='\E[00m'


cecho()   # Color-echo
# arg1 = message
# arg2 = color
{
    local default_msg="No Message."
    message=${1:-$default_msg}
    color=${2:-$green}
1201
    if [ $BUILD_FROM_MAKEFILE = 0 ]; then
1202 1203
	echo -e -n "$color$message$reset_color"
	echo
1204
    else
1205 1206
	echo "$message"
    fi
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
    return
}

echo_error() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
        done
        cecho "$my_string" $red
}

echo_fatal() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
        done
        echo_error "$my_string"
    exit -1
}

echo_warning() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
    done
    cecho "$my_string" $yellow
}

echo_success() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
    done
    cecho "$my_string" $green
}
nikaeinn's avatar
nikaeinn committed
1250 1251 1252 1253 1254 1255 1256 1257 1258
echo_info() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
    done
    cecho "$my_string" $blue
}
1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308

bash_exec() {
    output=$($1 2>&1)
    result=$?
    if [ $result -eq 0 ]; then
        echo_success "$1"
    else
        echo_error "$1: $output"
    fi
}


wait_process_started () {
    if  [ -z "$1" ]; then
        echo_error "WAITING FOR PROCESS START: NO PROCESS"
        return 1
    fi
    ps -C $1 > /dev/null 2>&1
    while [ $? -ne 0 ]; do
        echo_warning "WAITING FOR $1 START"
        sleep 2
        ps -C $1 > /dev/null 2>&1
    done
    echo_success "PROCESS $1 STARTED"
    return 0
}

is_process_started () {
    if  [ -z "$1" ]; then
        echo_error "WAITING FOR PROCESS START: NO PROCESS"
        return 1
    fi
    ps -C $1 > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        echo_success "PROCESS $1 NOT STARTED"
        return 1
    fi
    echo_success "PROCESS $1 STARTED"
    return 0
}

assert() {
    # If condition false
    # exit from script with error message
    E_PARAM_ERR=98
    E_PARAM_FAILED=99

    if [ -z "$2" ] ; then # Not enought parameters passed.
        return $E_PARAM_ERR
    fi
1309

1310 1311 1312 1313 1314 1315
    lineno=$2
    if [ ! $1 ]; then
        echo_error "Assertion failed:  \"$1\""
        echo_fatal "File \"$0\", line $lineno"
    fi
}