utils.bash 20.5 KB
Newer Older
Lionel Gauthier's avatar
Lionel Gauthier committed
1
################################################################################
Lionel Gauthier's avatar
Lionel Gauthier committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#   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
#
ghaddab's avatar
ghaddab committed
26
#  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
Lionel Gauthier's avatar
Lionel Gauthier committed
27
#
Lionel Gauthier's avatar
Lionel Gauthier committed
28 29 30 31 32 33 34
################################################################################
# file utils.bash
# brief
# author Lionel Gauthier
# company Eurecom
# email: lionel.gauthier@eurecom.fr
#
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

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'

ROOT_UID=0
E_NOTROOT=67

HOSTNAME=$(hostname -f)
50 51 52 53 54
if [ $? -eq 1 ]
then
    HOSTNAME=$(hostname)
fi

Lionel Gauthier's avatar
Lionel Gauthier committed
55
IPTABLES=`which iptables`
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

trim ()
{
    echo "$1" | sed -n '1h;1!H;${;g;s/^[ \t]*//g;s/[ \t]*$//g;p;}'
}

trim2()
{
    local var=$@
    var="${var#"${var%%[![:space:]]*}"}"   # remove leading whitespace characters
    var="${var%"${var##*[![:space:]]}"}"   # remove trailing whitespace characters
    echo -n "$var"
}

cecho()   # Color-echo
# arg1 = message
# arg2 = color
{
    local default_msg="No Message."
    message=${1:-$default_msg}
    color=${2:-$green}
    echo -e -n "$color$message$reset_color"
    echo
    return
}

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

Lionel Gauthier's avatar
Lionel Gauthier committed
92 93 94 95 96 97 98 99 100 101 102
echo_fatal() {
    local my_string=""
    until [ -z "$1" ]
    do
        my_string="$my_string$1"
        shift
        done
        echo_error "$my_string"
    exit -1
}

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
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
}

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

extract() {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2)    tar xvjf $1        ;;
            *.tar.gz)     tar xvzf $1        ;;
            *.bz2)        bunzip2  $1        ;;
            *.rar)        unrar    $1        ;;
            *.gz)         gunzip   $1        ;;
            *.tar)        tar xvf  $1        ;;
            *.tbz2)       tar xvjf $1        ;;
            *.tgz)        tar xvzf $1        ;;
            *.zip)        unzip    $1        ;;
            *.Z)          uncompress $1      ;;
            *.7z)         7z x     $1        ;;
            *)            echo_error "'$1' cannot be extracted via >extract<" ; return 1;;
        esac
    else
        echo_error "'$1' is not a valid file"
        return 1
    fi
    return 0
}

rotate_log_file () {
Lionel Gauthier's avatar
 
Lionel Gauthier committed
158 159 160 161 162 163 164 165 166 167
    FULLPATH=$1
    if [ -f $FULLPATH ]; then
        FILENAME=${FULLPATH##*/}
        FILEEXTENSION=${FILENAME##*.}
        BASEDIRECTORY=${FULLPATH%$FILENAME}
        if [ "a$BASEDIRECTORY" == "a" ]; then
            BASEDIRECTORY='.'
        fi
        FILENAME_NO_EXT=$(echo "$FILENAME" | sed 's/\.[^\.]*$//')

Lionel Gauthier's avatar
 
Lionel Gauthier committed
168 169
        # use file last modification time
        TIMESTAMP=`date -r $FULLPATH +%Y-%m-%d.%Hh_%Mm_%Ss`
Lionel Gauthier's avatar
 
Lionel Gauthier committed
170 171 172 173
        
        NEWLOGFILE=$TIMESTAMP.$FILENAME_NO_EXT.$FILEEXTENSION
        mv $FULLPATH /tmp/$NEWLOGFILE
        cat /dev/null > $FULLPATH
174
        sync
Lionel Gauthier's avatar
 
Lionel Gauthier committed
175
        gzip -c --name -f -9 /tmp/$NEWLOGFILE > $BASEDIRECTORY/$NEWLOGFILE.gz &
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 209 210 211 212 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 252
    fi
}

set_openair() {
    path=`pwd`
    declare -i length_path
    declare -i index
    length_path=${#path}

    for i in 'openair1' 'openair2' 'openair3' 'openair-cn' 'targets'
    do
        index=`echo $path | grep -b -o $i | cut -d: -f1`
        #echo ${path%$token*}
        if [[ $index -lt $length_path  && index -gt 0 ]]
           then
               index=`expr $index - 1`
               openair_path=`echo $path | cut -c1-$index`
               #openair_path=`echo ${path:0:$index}`
               export OPENAIR_DIR=$openair_path
               export OPENAIR_HOME=$openair_path
               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
               return 0
           fi
    done
    return -1
}

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" ] # Not enought parameters passed.
    then
        return $E_PARAM_ERR
    fi

    lineno=$2
    if [ ! $1 ]
    then
Lionel Gauthier's avatar
Lionel Gauthier committed
253 254
        echo_error "Assertion failed:  \"$1\""
        echo_fatal "File \"$0\", line $lineno"
255 256 257
    fi
}

258

Lionel Gauthier's avatar
Lionel Gauthier committed
259 260 261 262 263 264 265
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."
Lionel Gauthier's avatar
 
Lionel Gauthier committed
266
          apt-get install --assume-yes $1 
Lionel Gauthier's avatar
Lionel Gauthier committed
267
      }
268 269 270 271 272
  fi
}

test_command_install_script() {
  # usage: test_command_install_script searched_binary script_to_be_invoked_if_binary_not_found
Lionel Gauthier's avatar
Lionel Gauthier committed
273
  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; };}
274 275 276 277
  echo_success "$1 available"
}


Lionel Gauthier's avatar
 
Lionel Gauthier committed
278

279 280 281 282

check_for_epc_executable() {
    if [ ! -f $OPENAIR3_DIR/OPENAIRMME/objs/OAI_EPC/oai_epc ]
        then
Lionel Gauthier's avatar
Lionel Gauthier committed
283 284
        echo_error "Cannot find oai_epc executable object in directory $OPENAIR3_DIR/OPENAIRMME/objs/OAI_EPC/"
        echo_fatal "Please make sure you have compiled OAI EPC with --enable-standalone-epc option"
285 286 287 288 289 290
        fi
}

check_for_sgw_executable() {
    if [ ! -f $OPENAIR3_DIR/OPENAIRMME/objs/OAI_SGW/oai_sgw ]
    then
Lionel Gauthier's avatar
Lionel Gauthier committed
291 292
        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"
293 294 295 296 297 298
    fi
}

check_for_mme_executable() {
    if [ ! -f $OPENAIR3_DIR/OPENAIRMME/objs/OAISIM_MME/oaisim_mme ]
    then
Lionel Gauthier's avatar
Lionel Gauthier committed
299 300
        echo_error "Cannot find oai_sgw executable object in directory $OPENAIR3_DIR/OPENAIRMME/objs/OAISIM_MME/"
        echo_fatal "Please make sure you have compiled OAI EPC without --enable-standalone-epc option"
301 302 303 304 305
    fi
}

check_for_root_rights() {
    if [[ $EUID -ne 0 ]]; then
Lionel Gauthier's avatar
Lionel Gauthier committed
306
        echo_fatal "This script must be run as root" 1>&2
307 308 309 310
    fi
}


Lionel Gauthier's avatar
Lionel Gauthier committed
311

Lionel Gauthier's avatar
 
Lionel Gauthier committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
start_openswitch_daemon() {
  rmmod -s bridge
  if [[ -e "/lib/modules/`uname -r`/extra/openvswitch.ko" ]] ; then
      bash_exec "insmod /lib/modules/`uname -r`/extra/openvswitch.ko" > /dev/null 2>&1
  else
      echo_error "/lib/modules/`uname -r`/extra/openvswitch.ko not found"
      bash $OPENAIRCN_DIR/SCRIPTS/install_openvswitch1.9.0.bash
  fi
  is_process_started "ovsdb-server"
  if [ $? -ne 0 ]
  then
      ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,manager_options --pidfile --detach
      wait_process_started "ovsdb-server"
  fi
  # To be done after installation
  # ovs-vsctl    --no-wait init
  is_process_started "ovs-vswitchd"
  if [ $? -ne 0 ]
  then
      ovs-vswitchd --pidfile --detach
      wait_process_started "ovs-vswitchd"
Lionel Gauthier's avatar
Lionel Gauthier committed
333 334 335
  fi
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
336 337 338
stop_openswitch_daemon() {
    pkill ovs-vswitchd
    pkill ovsdb-server
339
    sync
Lionel Gauthier's avatar
 
Lionel Gauthier committed
340 341
    if  ! is_process_started ovs-vswitchd  ; then
        pkill -9 ovs-vswitchd
Lionel Gauthier's avatar
Lionel Gauthier committed
342
    fi
Lionel Gauthier's avatar
 
Lionel Gauthier committed
343 344 345 346
    if ! is_process_started ovsdb-server ; then
        pkill -9 ovsdb-server
    fi
    rmmod -f openvswitch
Lionel Gauthier's avatar
Lionel Gauthier committed
347 348
}

349

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
check_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`.eur ]
            then
                echo_success "S6A: Found valid certificate in /usr/local/etc/freeDiameter"
                return 1
            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.sh
    check_s6a_certificate
    return 1
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
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 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 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 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
generate_ssh_keys() {
    ssh-keygen -t dsa
}  
  
# arg 1 is dest machine
copy_ssh_keys() {
    ssh-copy-id -i ~/.ssh/id_dsa.pub $LOGNAME@$1
}

# arg 1 is mysql user      (root)
# arg 2 is mysql password  (linux)
create_hss_database(){
    EXPECTED_ARGS=2
    E_BADARGS=65
    MYSQL=`which mysql`
    
    if [ $# -ne $EXPECTED_ARGS ]
    then
        echo_fatal "Usage: $0 dbuser dbpass"
    fi

    set_openair
    
    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"
    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"
    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"
    else
       echo_success "hssadmin permissions succeeded"
    fi
}

check_install_hss_software() {
    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 
    test_install_package linux-headers-`uname -r` 
    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
    test_install_package phpmyadmin
    test_install_package python-dev 
    test_install_package sshfs
    test_install_package swig 
    test_install_package unzip 
    test_install_package valgrind 
}

check_install_vbox_software() {
    test_install_package dkms
    test_install_package openssh-client
    test_install_package openssh-server
    test_install_package sshfs
    test_install_package virtualbox
    test_install_package virtualbox-dkms
    test_install_package virtualbox-guest-additions-iso
    test_install_package virtualbox-qt
    test_install_package virtualbox-guest-utils
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
471 472 473 474 475
check_install_epc_software() {
    test_install_package autoconf
    test_install_package automake
    test_install_package bison
    test_install_package build-essential
Lionel Gauthier's avatar
 
Lionel Gauthier committed
476
    test_install_package check
Lionel Gauthier's avatar
 
Lionel Gauthier committed
477 478
    test_install_package cmake
    test_install_package cmake-curses-gui
Lionel Gauthier's avatar
 
Lionel Gauthier committed
479
    test_install_package ethtool
Lionel Gauthier's avatar
 
Lionel Gauthier committed
480 481 482 483 484 485 486
    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
Lionel Gauthier's avatar
Lionel Gauthier committed
487
    test_install_package gtkwave
Lionel Gauthier's avatar
 
Lionel Gauthier committed
488 489 490 491 492 493 494
    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
Raymond Knopp's avatar
 
Raymond Knopp committed
495 496 497 498
    if [ x$UTILS_ARCH == x64 ]; then
        test_install_package libconfig8-dev
    else
        test_install_package libconfig-dev
Lionel Gauthier's avatar
 
Lionel Gauthier committed
499
    fi
Lionel Gauthier's avatar
 
Lionel Gauthier committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    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
    test_install_package linux-headers-`uname -r`
    test_install_package make
Lionel Gauthier's avatar
 
Lionel Gauthier committed
517 518
    test_install_package openssh-client
    test_install_package openssh-server
Lionel Gauthier's avatar
 
Lionel Gauthier committed
519
    test_install_package openssl
Lionel Gauthier's avatar
 
Lionel Gauthier committed
520
    test_install_package openvpn
Lionel Gauthier's avatar
Lionel Gauthier committed
521
    test_install_package pkg-config
Lionel Gauthier's avatar
 
Lionel Gauthier committed
522
    test_install_package python-dev
Lionel Gauthier's avatar
 
Lionel Gauthier committed
523
    test_install_package sshfs
Lionel Gauthier's avatar
 
Lionel Gauthier committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
    test_install_package subversion
    test_install_package swig
    test_install_package tshark
    test_install_package uml-utilities
    test_install_package unzip
    test_install_package valgrind
    test_install_package vlan

    if [ ! -d /usr/local/etc/freeDiameter ]
        then
           # This script make certificates also
            cd $OPENAIRCN_DIR/S6A/freediameter && ./install_freediameter.sh
        else
            echo_success "freediameter is installed"
            check_s6a_certificate
    fi

    test_command_install_script   "asn1c" "$OPENAIRCN_DIR/SCRIPTS/install_asn1c_0.9.24.modified.bash"

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

Lionel Gauthier's avatar
 
Lionel Gauthier committed
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
function cgrp()
{
    OPTIND=1
    local case=""
    local usage="cgrp: find string in files.
    Usage: cgrp \"pattern\" "

    set_openair
    find $OPENAIR2_DIR    -name *.c -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIR1_DIR    -name *.c -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIR3_DIR    -name *.c -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIRCN_DIR   -name *.c -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIR_TARGETS -name *.c -exec grep  --color=auto -Hni $1 {} \;
}

function hgrp()
{
    OPTIND=1
    local case=""
    local usage="hgrp: find string in files.
    Usage: hgrp \"pattern\" "
    set_openair
    find $OPENAIR2_DIR    -name *.h -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIR1_DIR    -name *.h -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIR3_DIR    -name *.h -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIRCN_DIR   -name *.h -exec grep  --color=auto -Hni $1 {} \;
    find $OPENAIR_TARGETS -name *.h -exec grep  --color=auto -Hni $1 {} \;
}

function svn_find_str_in_file_history()
{
    for REV in `svn log $1 | grep ^r[0-9] | awk '{print $1}'`; do 
        svn cat $1 -r $REV | grep $2
        if [ $? -eq 0 ]; then 
            echo "$REV"
        fi 
    done
}

Lionel Gauthier's avatar
 
Lionel Gauthier committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
compile_hss() {
    cd $OPENAIRCN_DIR/OPENAIRHSS
    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"
        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 `cat /proc/cpuinfo | grep processor | wc -l`
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
            exit 1
        fi
    else
        echo_error "Configure failed, exiting"
        exit 1
    fi
}


Lionel Gauthier's avatar
 
Lionel Gauthier committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
compile_epc() {
    cd $OPENAIRCN_DIR
    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"
        bash_exec "./autogen.sh"
        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

    pkill oai_epc
    pkill tshark

    if [ -f Makefile ]
    then
        echo_success "Compiling..."
        make -j `cat /proc/cpuinfo | grep processor | wc -l`
        if [ $? -ne 0 ]; then
            echo_error "Build failed, exiting"
            exit 1
        fi
    else
        echo_error "Configure failed, exiting"
        exit 1
    fi
}
Lionel Gauthier's avatar
 
Lionel Gauthier committed
683

684 685 686 687 688 689 690 691 692 693 694 695 696
###########################################################
IPTABLES=/sbin/iptables
THIS_SCRIPT_PATH=$(dirname $(readlink -f $0))
declare -x OPENAIR_DIR=""
declare -x OPENAIR1_DIR=""
declare -x OPENAIR2_DIR=""
declare -x OPENAIR3_DIR=""
declare -x OPENAIRCN_DIR=""
declare -x OPENAIR_TARGETS=""
###########################################################

set_openair
cecho "OPENAIR_DIR     = $OPENAIR_DIR" $green
697
cecho "OPENAIR_HOME    = $OPENAIR_HOME" $green
698 699 700 701 702
cecho "OPENAIR1_DIR    = $OPENAIR1_DIR" $green
cecho "OPENAIR2_DIR    = $OPENAIR2_DIR" $green
cecho "OPENAIR3_DIR    = $OPENAIR3_DIR" $green
cecho "OPENAIRCN_DIR   = $OPENAIRCN_DIR" $green
cecho "OPENAIR_TARGETS = $OPENAIR_TARGETS" $green
Lionel Gauthier's avatar
 
Lionel Gauthier committed
703

Lionel Gauthier's avatar
Lionel Gauthier committed
704
export UTILS_ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
Lionel Gauthier's avatar
 
Lionel Gauthier committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718
if [ -f /etc/lsb-release ]; then
    . /etc/lsb-release
    export OS=$DISTRIB_ID
    export VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
    export OS=Debian  # XXX or Ubuntu??
    export VER=$(cat /etc/debian_version)
elif [ -f /etc/redhat-release ]; then
    # TODO add code for Red Hat and CentOS here
    ...
else
    export OS=$(uname -s)
    export VER=$(uname -r)
fi