build_helper.bash 41.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
################################################################################
#   OpenAirInterface
#   Copyright(c) 1999 - 2014 Eurecom
#
#    OpenAirInterface is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#
#    OpenAirInterface is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with OpenAirInterface.The full GNU General Public License is
#    included in this distribution in the file called "COPYING". If not,
#    see <http://www.gnu.org/licenses/>.
#
#  Contact Information
#  OpenAirInterface Admin: openair_admin@eurecom.fr
#  OpenAirInterface Tech : openair_tech@eurecom.fr
24
#  OpenAirInterface Dev  : openair4g-devel@lists.eurecom.fr
25 26 27 28 29 30 31 32 33 34 35 36 37 38
#
#  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
#
################################################################################
# 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
39 40 41 42 43 44 45 46 47 48 49
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`
50 51 52 53

set_build_from_makefile(){
    BUILD_FROM_MAKEFILE=$1   
}
nikaeinn's avatar
nikaeinn committed
54

55
check_for_root_rights() {
56 57 58
    
  #  if [[ $EUID -ne $ROOT_EUID ]]; then
    if [ $USER != "root" ]; then
59
        SUDO="sudo -E "
gauthier's avatar
gauthier committed
60 61
        echo "Run as a sudoers" 
        return 1
62
    else 
gauthier's avatar
gauthier committed
63 64
        echo  "Run as a root" 
        return 0
65 66 67 68 69 70 71 72 73 74 75
    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
76
          OAI_INSTALLED=0
77
          $SUDO apt-get install -y $@
78 79 80 81
      }
  fi
}

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

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

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

make_certs(){
nikaeinn's avatar
nikaeinn committed
122 123

 # for certtificate generation
124
    rm -rf demoCA
nikaeinn's avatar
nikaeinn committed
125
    mkdir -m 777 -p demoCA
126 127
    echo 01 > demoCA/serial
    touch demoCA/index.txt
nikaeinn's avatar
nikaeinn committed
128 129 130
    
    echo "creating the certificate"
    
131
    user=$(whoami)
nikaeinn's avatar
nikaeinn committed
132
    HOSTNAME=$(hostname -f)
133 134 135 136 137 138

    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
139 140 141 142 143
   # 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
144 145
    
    if [ ! -d /usr/local/etc/freeDiameter ];  then
gauthier's avatar
gauthier committed
146 147
        echo "Creating non existing directory: /usr/local/etc/freeDiameter/"
        $SUDO mkdir /usr/local/etc/freeDiameter/
148 149
    fi
    
nikaeinn's avatar
nikaeinn committed
150 151 152
    echo "Copying *.pem to /usr/local/etc/freeDiameter/"
    $SUDO cp *.pem /usr/local/etc/freeDiameter/
    mv *.pem bin/
153 154 155 156 157 158 159
    
# 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

}

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
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
	    
	    cd /usr/local/src/
	    
	    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 
	    cd ../
	fi
    fi
}

209 210
check_install_freediamter(){
    
nikaeinn's avatar
nikaeinn committed
211
    if [ $UBUNTU_REL = "12.04" ]; then 
nikaeinn's avatar
nikaeinn committed
212

nikaeinn's avatar
nikaeinn committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
	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
	
	cd /usr/local/src/
	
	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 
	cd ../
252 253 254 255
    fi
    
    echo "Downloading gnutls archive"
    
knopp's avatar
knopp committed
256 257
    if [ -f gnutls-3.1.23.tar.xz ];  then
	$SUDO rm -f gnutls-3.1.23.tar.xz
258
    fi
knopp's avatar
knopp committed
259 260
    if [ -d gnutls-3.1.23/ ];  then
	$SUDO rm -rf gnutls-3.1.23/
261
    fi
nikaeinn's avatar
nikaeinn committed
262
    
nikaeinn's avatar
nikaeinn committed
263
    test_uninstall_package libgnutls-dev
nikaeinn's avatar
nikaeinn committed
264
    
knopp's avatar
knopp committed
265 266
    $SUDO wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.23.tar.xz 
    $SUDO tar -xf gnutls-3.1.23.tar.xz
nikaeinn's avatar
nikaeinn committed
267
    echo "Uncompressing gnutls archive ($PWD)"
knopp's avatar
knopp committed
268
    cd gnutls-3.1.23/
269 270 271 272 273 274 275 276
    $SUDO ./configure --prefix=/usr
    if [ $? -ne 0 ];   then
	exit -1
    fi
    echo "Compiling gnutls"
    $SUDO make -j $NUM_CPU 
    $SUDO make install 
    cd ../
nikaeinn's avatar
nikaeinn committed
277
    
278 279 280 281 282 283 284 285 286 287 288 289 290
    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
291
    $SUDO patch -p1 < $OPENAIR3_DIR/S6A/freediameter/freediameter-1.1.5.patch 
292 293 294 295 296 297 298 299 300 301 302 303
    $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
304
#    make_certs
305 306 307
   
}

nikaeinn's avatar
nikaeinn committed
308 309

test_is_host_reachable() {
gauthier's avatar
gauthier committed
310 311
    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
312 313 314
}


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


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

366 367
check_install_usrp_uhd_driver(){
    if [ ! -f /etc/apt/sources.list.d/ettus.list ] ; then 
gauthier's avatar
gauthier committed
368 369
        $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
370 371
    fi 
    $SUDO apt-get install -t $UBUNTU_REL_NAME uhd
372 373 374
    test_install_package python 
    test_install_package libboost-all-dev 
    test_install_package libusb-1.0-0-dev
375 376 377
    #test_install_package uhd
}

378 379 380
check_install_oai_software() {
    
    if [ ! -f ./.lock_oaibuild ]; then 
gauthier's avatar
gauthier committed
381 382 383 384
        $SUDO apt-get update
        if [ $UBUNTU_REL = "12.04" ]; then 
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
385 386 387
        else 
            test_install_package nettle-dev
            test_install_package nettle-bin
gauthier's avatar
gauthier committed
388 389 390 391 392
        fi 
        test_install_package autoconf 
        test_install_package automake 
        test_install_package bison 
        test_install_package build-essential
gauthier's avatar
gauthier committed
393
        test_install_package dialog
gauthier's avatar
gauthier committed
394 395 396 397 398 399 400 401
        test_install_package flex 
        test_install_package gawk
        test_install_package gcc
        test_install_package gdb 
        test_install_package make
        test_install_package cmake
        test_install_package openssh-client
        test_install_package openssh-server
402
        sudo service ssh start
gauthier's avatar
gauthier committed
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
        test_install_package unzip 
        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 
        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
424 425 426 427 428
#	if [ $MACHINE_ARCH = 64 ]; then
            test_install_package libconfig8-dev
#	else
#            test_install_package libconfig-dev
#	fi
gauthier's avatar
gauthier committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
        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 
        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
455
	
gauthier's avatar
gauthier committed
456
#        test_install_package libboost-all-dev
457
	
gauthier's avatar
gauthier committed
458 459 460
        if [ $OAI_INSTALLED = 1 ]; then 
            touch ./.lock_oaibuild
        fi 
461 462
    
     else
gauthier's avatar
gauthier committed
463
        echo_info "All the required packages installed: skip"
464 465 466
    fi 
    
}
467

468 469
check_install_hss_software() {
    if [ ! -f ./.lock_oaibuild ]; then 
gauthier's avatar
gauthier committed
470 471 472 473
        $SUDO apt-get update
        if [ $UBUNTU_REL = "12.04" ]; then 
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
474 475 476
        else 
            test_install_package nettle-dev
            test_install_package nettle-bin
gauthier's avatar
gauthier committed
477
        fi 
478 479 480 481 482 483
	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
484 485
    test_install_package dialog
    test_install_package dkms
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
	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 
nikaeinn's avatar
nikaeinn committed
501
#	test_install_package linux-headers-`uname -r` 
502
	test_install_package make
gauthier's avatar
gauthier committed
503
	test_install_package mysql-client 
504
	test_install_package mysql-server-core-5.5 
gauthier's avatar
gauthier committed
505
	test_install_package mysql-server
506 507
	test_install_package openssh-client
	test_install_package openssh-server
508
        sudo service ssh start
509 510 511 512 513
	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
514 515
#	test_install_package nettle-bin
#	test_install_package nettle-dev
516 517 518 519 520
	test_install_package valgrind 

	if [ $OAI_INSTALLED = 1 ]; then 
	    touch ./.lock_oaibuild
	fi 
nikaeinn's avatar
nikaeinn committed
521
	
522
    else
nikaeinn's avatar
nikaeinn committed
523
	echo_info "All the required packages installed: skip"
524 525 526 527 528 529 530
    fi 

}

check_install_epc_software() {

    if [ ! -f ./.lock_oaibuild ]; then 
gauthier's avatar
gauthier committed
531 532 533 534
        $SUDO apt-get update
        if [ $UBUNTU_REL = "12.04" ]; then 
            test_uninstall_package nettle-dev
            test_uninstall_package nettle-bin
535 536 537
        else 
            test_install_package nettle-dev
            test_install_package nettle-bin
gauthier's avatar
gauthier committed
538 539 540 541 542 543 544 545
        fi 
        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
546
        test_install_package dialog
gauthier's avatar
gauthier committed
547 548 549 550 551 552 553 554 555 556 557 558
        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 
        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
559
        test_install_package iptables-dev
gauthier's avatar
gauthier committed
560 561 562 563 564
        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
565
            test_install_package libconfig8-dev
gauthier's avatar
gauthier committed
566
#        else
nikaeinn's avatar
nikaeinn committed
567
#            test_install_package libconfig-dev
gauthier's avatar
gauthier committed
568 569 570 571 572 573 574 575 576 577 578 579 580
#       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
581
        test_install_package libssl-dev
gauthier's avatar
gauthier committed
582
        test_install_package libtasn1-3-dev
gauthier's avatar
gauthier committed
583
        test_install_package libtool 
gauthier's avatar
gauthier committed
584 585 586 587 588 589
        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
590
        $SUDO service ssh start
gauthier's avatar
gauthier committed
591 592 593 594 595 596 597 598 599 600 601 602
        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
603
	
gauthier's avatar
gauthier committed
604 605 606
        if [ $OAI_INSTALLED = 1 ]; then 
            touch ./.lock_oaibuild
        fi 
nikaeinn's avatar
nikaeinn committed
607
    
608
    else
gauthier's avatar
gauthier committed
609
        echo_info "All the required packages installed: skip"
610
    fi 
611

612 613 614 615
}

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

#################################################
# 2. compile 
################################################
compile_hss() {
641
    cd $OPENAIR3_DIR/OPENAIRHSS
gauthier's avatar
gauthier committed
642 643 644 645 646 647 648
    
    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
649
    fi
gauthier's avatar
gauthier committed
650 651 652

    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
    
653 654
    if [ ! -n "$OBJ_DIR" ]; then
        OBJ_DIR="objs"
gauthier's avatar
gauthier committed
655
        mkdir --verbose -m 777 ./$OBJ_DIR
656 657 658
    else
        OBJ_DIR=`basename $OBJ_DIR`
    fi
659
    
gauthier's avatar
gauthier committed
660 661 662
    if [ ! -f "$OBJ_DIR"/Makefile ]; then
        if [ ! -d m4 ]; then
            mkdir --verbose -m 777 m4
663 664
        fi
        echo_success "Invoking autogen"
665 666 667 668 669
        ./autogen.sh
        if [ $? -ne 0 ]; then
            return 1
        fi
        cd $OBJ_DIR
gauthier's avatar
gauthier committed
670
        echo_success "Invoking configure"
671
        ../configure 
gauthier's avatar
gauthier committed
672 673 674
        if [ $? -ne 0 ]; then
            return 1
        fi
675
    else
676
        cd $OBJ_DIR
677
    fi
gauthier's avatar
gauthier committed
678

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


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

nikaeinn's avatar
nikaeinn committed
728 729
#    pkill oai_epc
#    pkill tshark
730 731 732 733 734 735

    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
736 737
            return 1
        else 
gauthier's avatar
gauthier committed
738
            cp -pf ./OAI_EPC/oai_epc  $OPENAIR_TARGETS/bin
gauthier's avatar
gauthier committed
739
        fi
740 741
    else
        echo_error "Configure failed, exiting"
nikaeinn's avatar
nikaeinn committed
742
        return 1
743
    fi
744
    
745
    cd $OPENAIR3_DIR/GTPV1-U/GTPUAH;
746 747 748 749 750
    make
    if [ $? -ne 0 ]; then
        echo_error "Build GTPUAH module failed, exiting"
        return 1
    else 
nikaeinn's avatar
nikaeinn committed
751 752
       	$SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
        $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
753 754
    fi
    
755
    cd $OPENAIR3_DIR/GTPV1-U/GTPURH;
756 757 758 759 760
    make
    if [ $? -ne 0 ]; then
        echo_error "Build GTPURH module failed, exiting"
        return 1
    else 
nikaeinn's avatar
nikaeinn committed
761 762
       $SUDO cp -pfv ./Bin/libxt_*.so /lib/xtables
       $SUDO cp -pfv ./Bin/*.ko $OPENAIR_TARGETS/bin
763 764
    fi
    return 0
765 766
}

gauthier's avatar
gauthier committed
767 768 769 770 771 772 773
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...
}


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

compile_nas_tools() {

    export NVRAM_DIR=$OPENAIR_TARGETS/bin
    
    cd $NVRAM_DIR
    
        if [ ! -f /tmp/nas_cleaned ]; then
857 858
            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
859
        fi
860 861
        echo_success "make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all"
        make --directory=$OPENAIR3_DIR/NAS/EURECOM-NAS/tools all
gauthier's avatar
gauthier committed
862 863 864 865 866 867 868 869 870 871
        rm .ue.nvram
        rm .usim.nvram
        touch /tmp/nas_cleaned
}


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

872 873 874 875 876 877 878
################################################
# 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"
879
        echo_error "Check the compilation logs in bin/install_log.txt"
gauthier's avatar
gauthier committed
880
        exit 1
881 882 883 884
    fi
}

check_for_epc_executable() {
885 886
    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
887
        echo_fatal "Please make sure you have compiled OAI EPC with --enable-standalone-epc option"
888 889 890
    fi
}

nikaeinn's avatar
nikaeinn committed
891
check_for_hss_executable() {
892 893
    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
894
        echo_fatal "Please make sure you have compiled OAI HSS"
nikaeinn's avatar
nikaeinn committed
895 896 897
    fi
}

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

gauthier's avatar
gauthier committed
961
check_for_nas_ue_executable() {
962 963
    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
964 965 966 967
        echo_fatal "Check the compilation logs in bin/install_log.txt"
    fi
}

nikaeinn's avatar
nikaeinn committed
968 969 970 971
################################################
# 1. check if the executable functions exist
###############################################

gauthier's avatar
gauthier committed
972 973 974
# arg1 is RT
# arg2 is HW 
# arg3 is ENB_S1
nikaeinn's avatar
nikaeinn committed
975 976 977
install_ltesoftmodem() {
    # RT
    if [ $1 = "RTAI" ]; then 
gauthier's avatar
gauthier committed
978
        if [ ! -f /tmp/init_rt_done.tmp ]; then
nikaeinn's avatar
nikaeinn committed
979
            echo_info "  8.1 Insert RTAI modules"
nikaeinn's avatar
nikaeinn committed
980 981 982 983 984 985 986
            $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
987
        else
nikaeinn's avatar
nikaeinn committed
988
            echo_warning "  8.1 RTAI modules already inserted"
nikaeinn's avatar
nikaeinn committed
989 990
        fi
    fi
nikaeinn's avatar
nikaeinn committed
991 992 993 994 995 996
    #HW
    if [ $2 = "EXMIMO" ]; then 
	echo_info "  8.2 [EXMIMO] creating RTAI fifos"
	for i in `seq 0 64`; do 
	    have_rtfX=`ls /dev/ |grep -c rtf$i`;
	    if [ "$have_rtfX" -eq 0 ] ; then 
nikaeinn's avatar
nikaeinn committed
997
		$SUDO mknod -m 666 /dev/rtf$i c 150 $i; 
nikaeinn's avatar
nikaeinn committed
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
	    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
	
	echo_info "  8.4 [EXMIMO] Setup RF card"
	cd $OPENAIR_TARGETS/RT/USER
	. ./init_exmimo2.sh
    else 
	if [ $2 = "USRP" ]; then
	    echo_info "  8.2 [USRP] "
	fi

nikaeinn's avatar
nikaeinn committed
1012 1013
    fi
    
nikaeinn's avatar
nikaeinn committed
1014 1015
    # ENB_S1
    if [ $3 = 0 ]; then 
gauthier's avatar
gauthier committed
1016 1017
        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
1018
    fi
nikaeinn's avatar
nikaeinn committed
1019 1020 1021
    
}

gauthier's avatar
gauthier committed
1022
# arg1 is ENB_S1 'boolean'
nikaeinn's avatar
nikaeinn committed
1023 1024
install_oaisim() {
   if [ $1 = 0 ]; then 
gauthier's avatar
gauthier committed
1025 1026 1027 1028 1029
       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
nikaeinn's avatar
nikaeinn committed
1030 1031 1032
   fi 
   
}
1033

gauthier's avatar
gauthier committed
1034 1035 1036 1037 1038

install_nas_tools() {
    cd $OPENAIR_TARGETS/bin
    if [ ! -f .ue.nvram ]; then
        echo_success "generate .ue_emm.nvram .ue.nvram"
1039
        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --gen
gauthier's avatar
gauthier committed
1040 1041 1042 1043
    fi

    if [ ! -f .usim.nvram ]; then
        echo_success "generate .usim.nvram"
1044
        $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --gen
gauthier's avatar
gauthier committed
1045
    fi
1046 1047
    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/ue_data --print
    $OPENAIR3_DIR/NAS/EURECOM-NAS/bin/usim_data --print
gauthier's avatar
gauthier committed
1048 1049
}

nikaeinn's avatar
nikaeinn committed
1050 1051 1052 1053 1054 1055 1056 1057
install_nasmesh(){
    echo_success "LOAD NASMESH IP DRIVER FOR UE AND eNB" 
    (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
}

1058 1059 1060 1061 1062 1063
##################################
# create HSS DB
################################

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

1078
    set_openair_env
1079
    
gauthier's avatar
gauthier committed
1080 1081 1082 1083 1084
    # 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}"
1085 1086
    $MYSQL -u $1 --password=$2 -e "$SQL"
    if [ $? -ne 0 ]; then
gauthier's avatar
gauthier committed
1087
       echo_error "$3 permissions failed"
gauthier's avatar
gauthier committed
1088
       return 1
1089
    else
gauthier's avatar
gauthier committed
1090
       echo_success "$3 permissions succeeded"
1091 1092
    fi
    
gauthier's avatar
gauthier committed
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
    
    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
    
    
gauthier's avatar
gauthier committed
1105
    # test if tables have been created
gauthier's avatar
gauthier committed
1106
    mysql -u $3 --password=$4  -e "desc $5.users" > /dev/null 2>&1
gauthier's avatar
gauthier committed
1107 1108
    
    if [ $? -eq 1 ]; then 
1109
        $MYSQL -u $3 --password=$4 $5 < $OPENAIR3_DIR/OPENAIRHSS/db/oai_db.sql
gauthier's avatar
gauthier committed
1110
        if [ $? -ne 0 ]; then
gauthier's avatar
gauthier committed
1111
            echo_error "$5 tables creation failed"
gauthier's avatar
gauthier committed
1112 1113
            return 1
        else
gauthier's avatar
gauthier committed
1114
            echo_success "$5 tables creation succeeded"
gauthier's avatar
gauthier committed
1115
        fi
1116 1117
    fi
    
gauthier's avatar
gauthier committed
1118
    return 0
1119 1120
}

1121
################################
1122
# set_openair_env
1123 1124 1125
###############################
set_openair_env(){

1126 1127 1128
    fullpath=`readlink -f $BASH_SOURCE`
    [ -f "/.$fullpath" ] || fullpath=`readlink -f $PWD/$fullpath`
    openair_path=${fullpath%/targets/*}
1129
    openair_path=${openair_path%/openair3/*}
1130 1131 1132
    openair_path=${openair_path%/openair[123]/*}

    export OPENAIR_DIR=$openair_path
1133
    export OPENAIR_HOME=$openair_path
1134 1135 1136
    export OPENAIR1_DIR=$openair_path/openair1
    export OPENAIR2_DIR=$openair_path/openair2
    export OPENAIR3_DIR=$openair_path/openair3
1137
    export OPENAIR3_DIR=$openair_path/openair3
1138
    export OPENAIR_TARGETS=$openair_path/targets
1139 1140

}
1141 1142 1143 1144 1145 1146 1147

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

print_help(){
    echo_success "Name : build_oai  - install and build OAI"
gauthier's avatar
gauthier committed
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
    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)"
1161
    echo_success "-p | --wireshark                        : enable wireshark interface for L2 pdus"
gauthier's avatar
gauthier committed
1162 1163 1164 1165 1166 1167 1168
    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"
1169
}
nikaeinn's avatar
nikaeinn committed
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184

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)"

}
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
###############################
## echo and  family 
###############################
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}
1206 1207 1208 1209 1210 1211
    if [ $BUILD_FROM_MAKEFILE = 0 ]; then 
	echo -e -n "$color$message$reset_color"
	echo
    else 
	echo "$message"
    fi
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 1250 1251 1252 1253 1254
    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
1255 1256 1257 1258 1259 1260 1261 1262 1263
echo_info() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
    done
    cecho "$my_string" $blue
}
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 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320

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
    
    lineno=$2
    if [ ! $1 ]; then
        echo_error "Assertion failed:  \"$1\""
        echo_fatal "File \"$0\", line $lineno"
    fi
}