build_helper.bash 33.4 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
################################################################################
#   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
#  OpenAirInterface Dev  : openair4g-devel@eurecom.fr
#
#  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
######################################

ROOT_UID=0
E_NOTROOT=67
NUM_CPU=`cat /proc/cpuinfo | grep processor | wc -l`
OAI_INSTALLED=1
43
PWD=`pwd`
44 45 46 47
USER=`whoami`
BUILD_FROM_MAKEFILE=0
SUDO=''
PW=''
Navid Nikaein's avatar
 
Navid Nikaein committed
48
UBUNTU_REL=`lsb_release -r | cut  -f2`
49
UBUNTU_REL_NAME=`lsb_release -cs`
50 51 52 53

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

55
check_for_root_rights() {
56 57 58
    
  #  if [[ $EUID -ne $ROOT_EUID ]]; then
    if [ $USER != "root" ]; then
59
       	SUDO="sudo -E "
60
	echo "Run as a sudoers" 
61 62
	return 1
    else 
63
	echo  "Run as a root" 
64 65 66 67 68 69 70 71 72 73 74 75 76
	return 0
    fi
}

test_install_package() {
  # usage: test_install_package package_name
 
 if [ $# -eq 1 ]; then
      dpkg -s "$1" > /dev/null 2>&1 && {
          echo "$1 is installed." 
      } || {
          echo "$1 is not installed." 
	  OAI_INSTALLED=0
77
          $SUDO apt-get install -y $@
78 79 80 81
      }
  fi
}

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

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

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

make_certs(){
122 123

 # for certtificate generation
124
    rm -rf demoCA
125
    mkdir -m 777 -p demoCA
126 127
    echo 01 > demoCA/serial
    touch demoCA/index.txt
128 129 130
    
    echo "creating the certificate"
    
131
    user=$(whoami)
Navid Nikaein's avatar
 
Navid Nikaein 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
    
Navid Nikaein's avatar
 
Navid Nikaein 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 146 147 148 149
    
    if [ ! -d /usr/local/etc/freeDiameter ];  then
	echo "Creating non existing directory: /usr/local/etc/freeDiameter/"
	$SUDO mkdir /usr/local/etc/freeDiameter/
    fi
    
Navid Nikaein's avatar
 
Navid Nikaein 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(){
    
Navid Nikaein's avatar
 
Navid Nikaein committed
211
    if [ $UBUNTU_REL = "12.04" ]; then 
212

Navid Nikaein's avatar
 
Navid Nikaein 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 256 257 258 259 260 261
    fi
    
    echo "Downloading gnutls archive"
    
    if [ -f gnutls-3.1.0.tar.xz ];  then
	$SUDO rm -f gnutls-3.1.0.tar.xz
    fi
    if [ -d gnutls-3.1.0/ ];  then
	$SUDO rm -rf gnutls-3.1.0/
    fi
Navid Nikaein's avatar
 
Navid Nikaein committed
262
    
263
    test_uninstall_package libgnutls-dev
Navid Nikaein's avatar
 
Navid Nikaein committed
264
    
265 266
    $SUDO wget ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.0.tar.xz 
    $SUDO tar -xf gnutls-3.1.0.tar.xz
267
    echo "Uncompressing gnutls archive ($PWD)"
268 269 270 271 272 273 274 275 276
    cd gnutls-3.1.0/
    $SUDO ./configure --prefix=/usr
    if [ $? -ne 0 ];   then
	exit -1
    fi
    echo "Compiling gnutls"
    $SUDO make -j $NUM_CPU 
    $SUDO make install 
    cd ../
Navid Nikaein's avatar
 
Navid Nikaein committed
277
    
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
    echo "Downloading freeDiameter archive"
    
    if [ -f 1.1.5.tar.gz ];  then
	$SUDO rm -f 1.1.5.tar.gz
    fi
    if [ -d freeDiameter-1.1.5/ ];   then
	$SUDO rm -rf freeDiameter-1.1.5/
    fi
    
    $SUDO wget http://www.freediameter.net/hg/freeDiameter/archive/1.1.5.tar.gz 
    $SUDO tar -xzf 1.1.5.tar.gz 
    echo "Uncompressing freeDiameter archive"
    cd freeDiameter-1.1.5
    $SUDO patch -p1 < $OPENAIRCN_DIR/S6A/freediameter/freediameter-1.1.5.patch 
    $SUDO mkdir build
    cd build
    $SUDO cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ../ 
    if [ $? -ne 0 ];  then
	exit -1
    fi
    echo "Compiling freeDiameter"
    $SUDO make -j $NUM_CPU 
#make help
    $SUDO make test 
    $SUDO sudo make install 
  
Navid Nikaein's avatar
 
Navid Nikaein committed
304
#    make_certs
305 306 307 308
   
}

check_s6a_certificate() {
Navid Nikaein's avatar
 
Navid Nikaein committed
309
    cnt=0
310
    if [ -d /usr/local/etc/freeDiameter ]; then
Navid Nikaein's avatar
 
Navid Nikaein committed
311 312 313 314
        if [ -f /usr/local/etc/freeDiameter/hss.cert.pem ];  then
            full_hostname=`cat /usr/local/etc/freeDiameter/hss.cert.pem | grep "Subject" | grep "CN" | cut -d '=' -f6`
#	    if [ $full_hostname = `hostname`.eur ];   then
	    if [ $full_hostname = hss.eur ];   then
315
                echo_success "S6A: Found valid certificate in /usr/local/etc/freeDiameter"
Navid Nikaein's avatar
 
Navid Nikaein committed
316
                return 0
317 318 319 320 321 322 323
            fi
        fi
    fi
    echo_error "S6A: Did not find valid certificate in /usr/local/etc/freeDiameter"
    echo_warning "S6A: generatting new certificate in /usr/local/etc/freeDiameter..."
    cd $OPENAIRCN_DIR/S6A/freediameter
    make_certs
Navid Nikaein's avatar
 
Navid Nikaein committed
324 325 326 327
    if [ $cnt = 0 ] ; then
	cnt=1
	check_s6a_certificate
    fi
328 329 330
    return 1
}

331 332 333 334 335 336
check_install_usrp_uhd_driver(){
    if [ ! -f /etc/apt/sources.list.d/ettus.list ] ; then 
	$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
    fi 
    $SUDO apt-get install -t $UBUNTU_REL_NAME uhd
337 338 339
    test_install_package python 
    test_install_package libboost-all-dev 
    test_install_package libusb-1.0-0-dev
340 341 342
    #test_install_package uhd
}

343 344 345
check_install_oai_software() {
    
    if [ ! -f ./.lock_oaibuild ]; then 
346
	$SUDO apt-get update
347
      	if [ $UBUNTU_REL = "12.04" ]; then 
348 349 350 351 352 353
	    test_uninstall_package nettle-dev
	    test_uninstall_package nettle-bin
        else 
            test_install_package nettle-dev
            test_install_package nettle-bin
	fi 
354 355 356 357 358 359 360 361 362
	test_install_package autoconf 
	test_install_package automake 
	test_install_package bison 
	test_install_package build-essential
	test_install_package flex 
	test_install_package gawk
	test_install_package gcc
	test_install_package gdb 
	test_install_package make
Navid Nikaein's avatar
Navid Nikaein committed
363
	test_install_package cmake
364 365
	test_install_package openssh-client
	test_install_package openssh-server
366
        sudo service ssh start
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
	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
#	if [ $MACHINE_ARCH = 64 ]; then
            test_install_package libconfig8-dev
#	else
#            test_install_package libconfig-dev
#	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 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
Navid Nikaein's avatar
Navid Nikaein committed
408
#	test_install_package linux-headers-`uname -r`
409
	test_install_package openssl
Navid Nikaein's avatar
Navid Nikaein committed
410
	test_install_package libssl-dev 
411 412 413 414 415 416
	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
417 418 419
	test_install_package doxygen
	test_install_package graphviz
	
420
# TODO: install the USRP UHD packages 
421 422
#	if [ $1 = "USRP" ] ; then 
	
423
#	test_install_package libboost-all-dev
424
	
425 426 427 428 429
	if [ $OAI_INSTALLED = 1 ]; then 
	    touch ./.lock_oaibuild
	fi 
    
     else
Navid Nikaein's avatar
 
Navid Nikaein committed
430
	echo_info "All the required packages installed: skip"
431 432 433
    fi 
    
}
434

435 436 437
check_install_hss_software() {
    if [ ! -f ./.lock_oaibuild ]; then 
	$SUDO apt-get update
438
	if [ $UBUNTU_REL = "12.04" ]; then 
Navid Nikaein's avatar
 
Navid Nikaein committed
439 440
	    test_uninstall_package nettle-dev
	    test_uninstall_package nettle-bin
441 442 443
        else 
            test_install_package nettle-dev
            test_install_package nettle-bin
Navid Nikaein's avatar
 
Navid Nikaein committed
444
	fi 
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
	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 
	test_install_package dkms
	test_install_package flex 
	test_install_package gawk
	test_install_package gcc
	test_install_package gdb 
	test_install_package guile-2.0-dev 
	test_install_package g++
	test_install_package libgmp-dev 
	test_install_package libgcrypt11-dev 
	test_install_package libidn11-dev 
	test_install_package libidn2-0-dev 
	test_install_package libmysqlclient-dev 
	test_install_package libtasn1-3-dev 
	test_install_package libsctp1 
	test_install_package libsctp-dev 
	test_install_package libxml2-dev 
Navid Nikaein's avatar
 
Navid Nikaein committed
467
#	test_install_package linux-headers-`uname -r` 
468 469 470 471 472 473
	test_install_package make
	test_install_package mysql-client-core-5.5 
	test_install_package mysql-server-core-5.5 
	test_install_package mysql-server-5.5 
	test_install_package openssh-client
	test_install_package openssh-server
474
        sudo service ssh start
475 476 477 478 479
	test_install_package phpmyadmin
	test_install_package python-dev 
	test_install_package sshfs
	test_install_package swig 
	test_install_package unzip 
Navid Nikaein's avatar
 
Navid Nikaein committed
480 481
#	test_install_package nettle-bin
#	test_install_package nettle-dev
482 483 484 485 486
	test_install_package valgrind 

	if [ $OAI_INSTALLED = 1 ]; then 
	    touch ./.lock_oaibuild
	fi 
Navid Nikaein's avatar
Navid Nikaein committed
487
	
488
    else
Navid Nikaein's avatar
 
Navid Nikaein committed
489
	echo_info "All the required packages installed: skip"
490 491 492 493 494 495 496 497
    fi 

}

check_install_epc_software() {

    if [ ! -f ./.lock_oaibuild ]; then 
	$SUDO apt-get update
498
	if [ $UBUNTU_REL = "12.04" ]; then 
Navid Nikaein's avatar
 
Navid Nikaein committed
499 500
	    test_uninstall_package nettle-dev
	    test_uninstall_package nettle-bin
501 502 503
        else 
            test_install_package nettle-dev
            test_install_package nettle-bin
Navid Nikaein's avatar
 
Navid Nikaein committed
504
	fi 
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
	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
	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
	test_install_package libatlas-base-dev
	test_install_package libatlas-dev
	test_install_package libblas
	test_install_package libblas-dev
Navid Nikaein's avatar
 
Navid Nikaein committed
528
#	if [ $MACHINE_ARCH = 64 ]; then
529
            test_install_package libconfig8-dev
Navid Nikaein's avatar
 
Navid Nikaein committed
530 531 532
#	else
#            test_install_package libconfig-dev
#	fi
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
	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
	test_install_package libtasn1-3-dev
	test_install_package libxml2
	test_install_package libxml2-dev
Navid Nikaein's avatar
 
Navid Nikaein committed
548
#	test_install_package linux-headers-`uname -r`
549 550 551
	test_install_package make
	test_install_package openssh-client
	test_install_package openssh-server
Navid Nikaein's avatar
Navid Nikaein committed
552
        $SUDO service ssh start
553 554 555 556 557 558 559 560 561 562 563 564
	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
Navid Nikaein's avatar
Navid Nikaein committed
565
	test_install_package libtool 
566 567 568 569
	
	if [ $OAI_INSTALLED = 1 ]; then 
	    touch ./.lock_oaibuild
	fi 
Navid Nikaein's avatar
Navid Nikaein committed
570
    
571
    else
Navid Nikaein's avatar
 
Navid Nikaein committed
572
	echo_info "All the required packages installed: skip"
573
    fi 
574

575 576 577 578 579
}

check_install_asn1c(){
    
    test_command_install_script   "asn1c" "$OPENAIRCN_DIR/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO"
580 581
    
    # One mor check about version of asn1c
582 583
    ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE="ASN.1 Compiler, v0.9.24"
    ASN1C_COMPILER_VERSION_MESSAGE=`asn1c -h 2>&1 | grep -i ASN\.1\ Compiler`
584
    ##ASN1C_COMPILER_VERSION_MESSAGE=`trim $ASN1C_COMPILER_VERSION_MESSAGE`
585
    if [ "$ASN1C_COMPILER_VERSION_MESSAGE" != "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE" ]; then
586
      #  diff <(echo -n "$ASN1C_COMPILER_VERSION_MESSAGE") <(echo -n "$ASN1C_COMPILER_REQUIRED_VERSION_MESSAGE")
587 588 589 590 591 592 593 594 595 596
        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
	    if [[ $answer = [YyNn] ]]; then
                [[ $answer = [Yy] ]] && $OPENAIRCN_DIR/SCRIPTS/install_asn1c_0.9.24.modified.bash $SUDO
                [[ $answer = [Nn] ]] && echo_error "Version of asn1c is not the required one, exiting." && exit 1
                break
	    fi
        done
    fi
597
    
598 599 600 601 602 603 604 605
}

#################################################
# 2. compile 
################################################
compile_hss() {
    cd $OPENAIRCN_DIR/OPENAIRHSS
    OBJ_DIR=`find . -maxdepth 1 -type d -iname obj*`
Navid Nikaein's avatar
 
Navid Nikaein committed
606 607 608 609
    if [ $1 = 1 ]; then
	echo_info "build a clean EPC"
	bash_exec "rm -rf obj"
    fi
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
    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
        echo_success "Invoking autogen"
        bash_exec "./autogen.sh"
        cd ./$OBJ_DIR
        echo_success "Invoking configure"
        ../configure 
    else
        cd ./$OBJ_DIR
    fi
    if [ -f Makefile ];  then
        echo_success "Compiling..."
        make -j $NUM_CPU
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
Navid Nikaein's avatar
 
Navid Nikaein committed
634 635 636 637
            return 1
	else 
	    cp -f ./openair-hss $OPENAIR_TARGETS/bin
	    return 0
638 639 640
        fi
    else
        echo_error "Configure failed, exiting"
Navid Nikaein's avatar
 
Navid Nikaein committed
641
        return 1
642 643 644 645 646 647
    fi
}


compile_epc() {
    cd $OPENAIRCN_DIR
Navid Nikaein's avatar
 
Navid Nikaein committed
648 649 650 651
    if [ $1 = 1 ]; then
	echo_info "build a clean EPC"
	bash_exec "rm -rf obj"
    fi
652 653 654 655 656 657 658 659 660 661 662 663 664
    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
        echo_success "Invoking autogen"
Navid Nikaein's avatar
Navid Nikaein committed
665 666
        bash_exec "libtoolize"        
	bash_exec "./autogen.sh"
667 668 669 670 671 672 673
        cd ./$OBJ_DIR
        echo_success "Invoking configure"
        ../configure --enable-standalone-epc --enable-raw-socket-for-sgi  LDFLAGS=-L/usr/local/lib
    else
        cd ./$OBJ_DIR
    fi

Navid Nikaein's avatar
 
Navid Nikaein committed
674 675
#    pkill oai_epc
#    pkill tshark
676 677 678 679 680 681

    if [ -f Makefile ]; then
        echo_success "Compiling..."
        make -j $NUM_CPU
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
Navid Nikaein's avatar
 
Navid Nikaein committed
682 683 684 685 686
            return 1
        else 
	    cp -f ./OAI_EPC/oai_epc  $OPENAIR_TARGETS/bin
	    return 0
	fi
687 688
    else
        echo_error "Configure failed, exiting"
Navid Nikaein's avatar
 
Navid Nikaein committed
689
        return 1
690 691 692
    fi
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
693 694 695 696 697 698 699
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...
}


700 701 702
compile_ltesoftmodem() {
    cd $OPENAIR_TARGETS/RT/USER
    if [ -f Makefile ];  then
703
       	echo "Compiling directives: $SOFTMODEM_DIRECTIVES"
704
     	make cleanall > /dev/null 2>&1
705 706 707
	make  $SOFTMODEM_DIRECTIVES 
	make -j $NUM_CPU $SOFTMODEM_DIRECTIVES 
        if [ $? -ne 0 ]; then
708 709 710 711 712 713 714
            if [ ! -f ./lte-softmodem ]; then 
		echo_error "Build lte-softmodem failed, returning"
		return 1
	    else 
		cp -f ./lte-softmodem  $OPENAIR_TARGETS/bin
		return 0	
	    fi 
715 716 717 718 719 720 721 722 723 724 725 726 727
	else
	    cp -f ./lte-softmodem  $OPENAIR_TARGETS/bin
	    return 0
        fi
    else
        echo_error "make file for oai softmodem not found, returning"
        return 1
    fi
}

compile_oaisim() {
    cd $OPENAIR_TARGETS/SIMU/USER
    if [ -f Makefile ]; then
728
        echo "Compiling for oaisim  target ($OAISIM_DIRECTIVES)"
729
       	make cleanall > /dev/null
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
	make $OAISIM_DIRECTIVES 
	make -j $NUM_CPU $OAISIM_DIRECTIVES 
        if [ $? -ne 0 ]; then
            echo_error "Build oaisim failed, returning"
            return 1
	else 
	    cp -f ./oaisim $OPENAIR_TARGETS/bin
	    return 0
        fi
    else
        echo_error "Makefile not found for oaisim target, returning"
        return 1
    fi
}

compile_unisim() {
    cd $OPENAIR1_DIR/SIMULATION/LTE_PHY
    if [ -f Makefile ]; then
748
        echo "Compiling for UNISIM target ..."
749 750
      	make cleanall
    	make  -j $NUM_CPU all 
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
        if [ $? -ne 0 ]; then
            echo_error "Build unisim failed, returning"
            return 1
	else 
	    cp -f ./dlsim     $OPENAIR_TARGETS/bin
	    cp -f ./ulsim     $OPENAIR_TARGETS/bin
	    cp -f ./pucchsim  $OPENAIR_TARGETS/bin
	    cp -f ./prachsim  $OPENAIR_TARGETS/bin
	    cp -f ./pdcchsim  $OPENAIR_TARGETS/bin
	    cp -f ./pbchsim   $OPENAIR_TARGETS/bin
	    cp -f ./mbmssim   $OPENAIR_TARGETS/bin
	    return 0
        fi
    else
        echo_error "Configure failed, exiting"
        return 1
    fi
}
################################################
# 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"
776
        echo_error "Check the compilation logs in bin/install_log.txt"
777 778 779 780 781
    fi
}

check_for_epc_executable() {
    if [ ! -f $OPENAIRCN_DIR/objs/OAI_EPC/oai_epc ]; then
Navid Nikaein's avatar
 
Navid Nikaein committed
782
        echo_error "Cannot find oai_epc executable object in directory $OPENAIRCN_DIR/objs/OAI_EPC/"
783 784 785 786
        echo_error "Please make sure you have compiled OAI EPC with --enable-standalone-epc option"
    fi
}

Navid Nikaein's avatar
 
Navid Nikaein committed
787 788 789 790 791 792 793
check_for_hss_executable() {
    if [ ! -f $OPENAIRCN_DIR/OPENAIRHSS/objs/openair-hss ]; then
        echo_error "Cannot find openair-hss executable object in directory $OPENAIRCN_DIR/OPENAIRHSS/objs/"
        echo_error "Please make sure you have compiled OAI HSS"
    fi
}

794 795 796 797 798 799 800 801 802 803
check_for_sgw_executable() {
    if [ ! -f $OPENAIRCN_DIR/objs/OAI_SGW/oai_sgw ]; then
        echo_error "Cannot find oai_sgw executable object in directory $OPENAIR3_DIR/OPENAIRMME/objs/OAI_SGW/"
        echo_fatal "Please make sure you have compiled OAI EPC without --enable-standalone-epc option"
    fi
}

check_for_oaisim_executable() {
    if [ ! -f $OPENAIR_TARGETS/SIMU/USER/oaisim ]; then
        echo_error "Cannot find oaisim executable object in directory $OPENAIR_TARGETS/SIMU/USER"
804
        echo_error "Check the compilation logs in bin/install_log.txt"
805 806 807 808 809 810
    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"
811
        echo_error "Check the compilation logs in bin/install_log.txt"
812 813 814 815 816 817
    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"
818
        echo_error "Check the compilation logs in bin/install_log.txt"
819 820 821 822 823 824
    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"
825
        echo_error "Check the compilation logs in bin/install_log.txt"
826 827 828 829 830 831
    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"
832
        echo_error "Check the compilation logs in bin/install_log.txt"
833 834 835 836 837 838
    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"
839
        echo_error "Check the compilation logs in bin/install_log.txt"
840 841 842 843 844 845
    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"
846
        echo_error "Check the compilation logs in bin/install_log.txt"
847 848 849 850 851 852
    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"
853
        echo_error "Check the compilation logs in bin/install_log.txt"
854 855
    fi
}
856 857 858 859 860

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

Navid Nikaein's avatar
Navid Nikaein committed
861 862 863
install_ltesoftmodem() {
    # RT
    if [ $1 = "RTAI" ]; then 
864
	if [ ! -f /tmp/init_rt_done.tmp ]; then
Navid Nikaein's avatar
Navid Nikaein committed
865
            echo_info "  8.1 Insert RTAI modules"
866 867 868 869 870 871 872
            $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
873
        else
Navid Nikaein's avatar
Navid Nikaein committed
874
            echo_warning "  8.1 RTAI modules already inserted"
875 876
        fi
    fi
Navid Nikaein's avatar
Navid Nikaein committed
877 878 879 880 881 882
    #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 
Navid Nikaein's avatar
Navid Nikaein committed
883
		$SUDO mknod -m 666 /dev/rtf$i c 150 $i; 
Navid Nikaein's avatar
Navid Nikaein committed
884 885 886 887 888 889 890 891 892 893 894 895 896 897
	    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

898 899
    fi
    
Navid Nikaein's avatar
Navid Nikaein committed
900 901 902 903 904
    # ENB_S1
    if [ $3 = 0 ]; then 
	cd $OPENAIR2_DIR && make clean && make nasmesh_netlink.ko  #|| exit 1
	cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make  # || exit 1
    fi
905 906 907 908 909
    
}

install_oaisim() {
   if [ $1 = 0 ]; then 
Navid Nikaein's avatar
Navid Nikaein committed
910 911
	cd $OPENAIR2_DIR && make clean && make nasmesh_netlink.ko  #|| exit 1
	cd $OPENAIR2_DIR/NAS/DRIVER/MESH/RB_TOOL && make clean && make  # || exit 1
912 913 914
   fi 
   
}
915

916 917 918 919 920 921 922 923 924 925
##################################
# create HSS DB
################################

# arg 1 is mysql user      (root)
# arg 2 is mysql password  (linux)
create_hss_database(){
    EXPECTED_ARGS=2
    E_BADARGS=65
    MYSQL=`which mysql`
Navid Nikaein's avatar
 
Navid Nikaein committed
926
    rv=0
927 928 929
    if [ $# -ne $EXPECTED_ARGS ]
    then
        echo_fatal "Usage: $0 dbuser dbpass"
Navid Nikaein's avatar
 
Navid Nikaein committed
930
	rv=1
931 932
    fi

933
    set_openair_env
934 935 936 937 938 939
    
    Q1="CREATE DATABASE IF NOT EXISTS ${BTICK}oai_db${BTICK};"
    SQL="${Q1}"
    $MYSQL -u $1 --password=$2 -e "$SQL"
    if [ $? -ne 0 ]; then
       echo_error "oai_db creation failed"
Navid Nikaein's avatar
 
Navid Nikaein committed
940
       rv=1
941 942 943 944 945 946 947
    else
       echo_success "oai_db creation succeeded"
    fi
    
    $MYSQL -u $1 --password=$2 oai_db < $OPENAIRCN_DIR/OPENAIRHSS/db/oai_db.sql
    if [ $? -ne 0 ]; then
       echo_error "oai_db tables creation failed"
Navid Nikaein's avatar
 
Navid Nikaein committed
948
       rv=1
949 950 951 952 953 954 955 956 957 958
    else
       echo_success "oai_db tables creation succeeded"
    fi
    
    Q1="GRANT ALL PRIVILEGES ON *.* TO 'hssadmin'@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION;"
    Q2="FLUSH PRIVILEGES;"
    SQL="${Q1}${Q2}"
    $MYSQL -u $1 --password=$2 -e "$SQL"
    if [ $? -ne 0 ]; then
       echo_error "hssadmin permissions failed"
Navid Nikaein's avatar
 
Navid Nikaein committed
959
       rv=1
960 961 962
    else
       echo_success "hssadmin permissions succeeded"
    fi
Navid Nikaein's avatar
 
Navid Nikaein committed
963
    return rv
964 965
}

966
################################
967
# set_openair_env
968 969 970
###############################
set_openair_env(){

971 972 973 974 975 976 977
    fullpath=`readlink -f $BASH_SOURCE`
    [ -f "/.$fullpath" ] || fullpath=`readlink -f $PWD/$fullpath`
    openair_path=${fullpath%/targets/*}
    openair_path=${openair_path%/openair-cn/*}
    openair_path=${openair_path%/openair[123]/*}

    export OPENAIR_DIR=$openair_path
978
    export OPENAIR_HOME=$openair_path
979 980 981 982 983
    export OPENAIR1_DIR=$openair_path/openair1
    export OPENAIR2_DIR=$openair_path/openair2
    export OPENAIR3_DIR=$openair_path/openair3
    export OPENAIRCN_DIR=$openair_path/openair-cn
    export OPENAIR_TARGETS=$openair_path/targets
984 985

}
986 987 988 989 990 991 992

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

print_help(){
    echo_success "Name : build_oai  - install and build OAI"
993
    echo_success "Usage: build_oai.bash -a -b -c -d -eRTAI -m -rREL8 -s -tOAISIM -wEXMIMO -x"
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
    echo_success "-a | --doxygen             : Enable doxygen for documentation (default disabled)"
    echo_success "-b | --disable-s1          : Disables S1 interface for eNB (default enabled)"
    echo_success "-c | --clean               : Enables clean OAI build (default disabled)"
    echo_success "-C | --config-file         : Set the config file local path"
    echo_success "-d | --debug               : Enables debug mode (default disabled)"
    echo_success "-e | --realtime            : Sets realtime mode: RTAI, NONE (default NONE)"
    echo_success "-g | --run-with-gdb        : Run with gdb"
    echo_success "-K | --itti-dump-file      : Set the execution events trace file"
    echo_success "-l | --build-target        : Sets the LTE build target: ENB,EPC,HSS,NONE (default ENB)"
    echo_success "-m | --build-from-makefile : Enables build from the makefile (default disabled)"
    echo_success "-r | --3gpp-release        : Sets the release: REL8, REL10 (default REL8)"
    echo_success "-s | --check               : Enables OAI testing and sanity check (default disabled)"
    echo_success "-t | --enb-build-target    : Sets the eNB build target: ALL, SOFTMODEM,OAISIM,UNISIM (default ALL)"
    echo_success "-V | --vcd                 : Log vcd events"
    echo_success "-w | --hardware            : sets the hardware platform: EXMIMO, USRP (also installs UHD driver), ETHERNET, NONE, (default EXMIMO)"
    echo_success "-x | --xforms              : enables xforms (default disabled)"
    echo_success "-z | --defaults            : sets the default build options"
1011
}
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
###############################
## 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}
1033 1034 1035 1036 1037 1038
    if [ $BUILD_FROM_MAKEFILE = 0 ]; then 
	echo -e -n "$color$message$reset_color"
	echo
    else 
	echo "$message"
    fi
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
    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
}
Navid Nikaein's avatar
Navid Nikaein committed
1082 1083 1084 1085 1086 1087 1088 1089 1090
echo_info() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
    done
    cecho "$my_string" $blue
}
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147

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
}