Chủ Nhật, 14 tháng 7, 2013

LINUX: Awesome error

Today, I met an awesome error when running a shell script file in Ubuntu.
tranlaman@tranlaman-VirtualBox:~/Desktop/workspace/partapp-r2$ ./run_partapp.sh bash: ./run_partapp.sh: /bin/sh^M: bad interpreter: No such file or directory
 The following link can fix the problem excellently:
http://www.gizmola.com/blog/archives/87-linux-shell-scripting-bad-interpreter-no-such-file-or-directory.html

Reason: Because the code was developed in Mac or somewhere, then I run it in Ubuntu. The file format is different.

Thứ Năm, 11 tháng 7, 2013

LD_LIBRARY_PATH all you need to know.

Hi all,
I have spent countless hour when trying to compile the C/C++ code in Linux (Ubuntu 12.04) using GCC or G++ compiler. I met a bunch of errors and then I figured out in Ubuntu the options -I -L and LD_LIBRARY_PATH are quite important. I read README and do exactly the same but still met the errors. Consequently, it is going to save your time if you understand a little bit about -I option, -L options and LD_LIBRARY_PATH.
-I (Include) specifies the directories of included headers file needed to compile your code, for example, the #include <xxx.h>
- L (Library) specifies the directories of shared libraries or static libraries for linking. It is used with -l (not number but an alphabet) options to specify the lib name. For example, a library is libxxx.so or libxxx.a would have -l option as -lxxx.
LD_LIBRARY_PATH (LinkDynamic Library Path -- I guess :-D) specifies the directories of shared libraries for linker during the run-time [2]. Also, it is used at the link-time, when linker looks for libraries and resolve external symbols in these directories. The problems are raised because of LD_LIBRARY_PATH since the directories at the link-time and run-time are different [3]. Some issues relate to incompatible versions of required libraries.
Refer to the links bellow for hands-on errors and solutions:
* The difference between -I and -L options:
[1] http://adf.ly/Rsfwr/what-is-the-difference-between-i-and-l-in-makefile
* The difference between LD_LIBRARY_PATH and -L at the run-time:
[2] http://adf.ly/RsgVz/what-is-the-difference-between-ld-library-path-and-l-at-link-time
* Why the LD_LIBRARY_PATH is bad?
[3] http://adf.ly/RskIY/UnixResource_dir/_/ldpath.html

Thứ Bảy, 15 tháng 6, 2013

Question: Where does my program reside if I install a program in Ubuntu?

Answer:
Normally, it would go to /usr/local. In /usr/local, you would have subdirectories such as /bin, /etc, /lib, /share, /src. These sub-folders contain appropriate files depending on the type of program that you want to install.

Thứ Sáu, 14 tháng 6, 2013

HOW-TO: Install OpenCV-2.4.5 and ffmpeg-1.2.1 in Ubuntu 64bits

Bug       
      After spending several days to install the latest ffmpeg with the latest OpenCV, I discovered that I made a stupid mistakes. The follow is a big-bug that I had met during installing ffmpeg-1.2.1 which create shared library in order for OpenCV to recognize it.
'libavutil/intfloat_readwrite.o: relocation R_X86_64_PC32 against undefined symbol `ldexp@@GLIBC_2.2.5'. 
This error because of bad symbolic link in ubuntu. The reason is that I placed my install folder in shared folder between my computer and Virtualbox VMs [4]. Anyway, if you meet this error, please moving your folder to a safer place, not a shared folder. On the other hand, installing ffmpeg and opencv require you to to have --enable-shared option which create shared-library. So, you need to do the same to all other dependencies, --enable-shared option as in [3]. Other possible remedy, you might want to run ldconfig command to update run-time linker default [5]. The exact structure for this command is
ldconfig [your ffmpeg installer folder].
Installation         
      I am writing this post to summerize steps to install ffmpeg a common media cross-platform for OpenCV-2.4.5 to localize it. I recommend you to follow the instructions in  [3]. You can also follow [1] and
[2]. Refering to [2], you can test if you install OpenCV correctly (testing section). I copy and paste here for easy to refer.
Testing
An easy way to test that the compilation went well is to use the OpenCV test utilities. For example, to test the core module go to OpenCV-2.4.5/build/bin and run:
./opencv_test_core
 You should see something like this:

Note that some failures when testing other modules may come from missing image files. To correctly run these tests or samples you should move the corresponding image files from OpenCV-2.4.5/samples to OpenCV-2.4.5/build/bin.

For testing that you can compile your own programs and link against the installed OpenCV libraries I have packaged the face detection sample with all the necessary files and a simple Makefile. Download it here, extract and type:
make
This should compile and run with a test image, so you should see something like this: 

Thứ Tư, 20 tháng 6, 2012

HOW-TO: Manually Installing Mediaproxy 2.5 on Ubuntu 12.04 server 64 bits


      Media-proxy is a media relay for RTP/RTCP and UDP streams that works in tandem with OpenSIPS to provide NAT traversal capability for media streams from SIP user agents located behind NAT. Mediaproxy supports ICE negotiation by behaving like a TURN relay candidate and the policy can be controlled from OpenSIPS configuration.
       Mediaproxy 2 is a Python project from AG-projects which is consisted of  (at least) two components: A dispatcher and a relay.
       For more details, please skim at http://mediaproxy.ag-projects.com/
       If you want to install Mediaproxy by a Debian repository, you can refer to http://mediaproxy.ag-projects.com/projects/mediaproxy/wiki/InstallationGuide.
       There are many installation guide found on Internet such as
       But none of it is perfect for my case, Ubuntu server 12.04 64 bits, I tried to search on Google for solution and had this hand-on experience. This article is aimed to provide good example for installing Mediaproxy in Ubuntu server 64 bits. Try to do it step by step,  do it smoothly you need some knowledge about basic GNU installation and python installation.

Install kernel support
#apt-get install iptables
#apt-get install gcc
#apt-get install g++

Development libraries and headers for some existing packages
#apt-get install libgpg-error-dev
#apt-get install python-dev

Install Linux libnetfilter_conntrack
Libnfnetlink
Suggestion version: libnfnetlink-1.0.0.tar.bz2
Unzip #tar xvjf libnfnetlink-1.0.0.tar.bz2
Change to the sub-directory created when you unzipped the tarball: #cd libnfnetlink-1.0.0/
#./configure
#make
#make install

libnfnetlink-dev
#apt-get install libnfnetlink-dev

libnetfilter_conntrack
Similarly, we do the same thing with previous one.
libnetfilter_conntrack-dev
#apt-get install libnetfilter-conntrack-dev


Install Python 3.2.3
Install the new release of Python from the URL.
#tar -xf Python-3.2.3.tgz
#./configure
#make

Install some Python packages
Ctypes
Suggested version: ctypes-1.0.2.tar.gz
#wget http://downloads.sourceforge.net/project/ctypes/ctypes/1.0.2/ctypes-1.0.2.tar.gz
Unzip: #tar -xvzf ctypes-1.0.2.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd ctypes-1.0.2/
Build and install the library:
./setup.py build
./setup.py install

Python-application
Suggested version: python-application-1.3.1.tar.gz
#wget http://pypi.python.org/packages/source/p/python-application/python-application-1.3.1.tar.gz#md5=615d670fcda2aa5a01de7bc12baa1fdf
Unzip: #tar -xvzf python-application-1.3.1.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd python-application-1.3.1/
Build and install the library:
./setup.py build
./setup.py install

Python-cjson
Suggested version: python-cjson-1.0.5.tar.gz
#wget http://pypi.python.org/packages/source/p/python-cjson/python-cjson-1.0.5.tar.gz#md5=4d55b66ecdf0300313af9d030d9644a3
Unzip: #tar -xvzf python-cjson-1.0.5.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd python-cjson-1.0.5/
Build and install the library:
#./setup.py build
#./setup.py install


Python-gnutls
Suggested version: python-gnutls-1.2.4.tar.gz
#wget http://pypi.python.org/packages/source/p/python-gnutls/python-gnutls-1.2.4.tar.gz#md5=e3536c421291a791869d875a41dcb26a
Unzip: #tar -xvzf python-gnutls-1.2.4.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd python-gnutls-1.2.4/
Build and install the library:
#./setup.py build
#./setup.py install
Install Python-Zope Interface
Similarly, we do install this package from this url:
#wget http://old.zope.org/Products/ZopeInterface/3.3.0/zope.interface-3.3.0.tar.gz



Install Twisted
#wget http://pypi.python.org/packages/source/T/Twisted/Twisted-12.1.0.tar.bz2#md5=f396f1d6f5321e869c2f89b2196a9eb5
Install both of them similarly with other installation.

Install libgcrypt, gmp and gnutls from source tarball
In order to escape some unnecessary when installing media-proxy, you should install libgcrypt from source, albeit you can do in apt-get.
Libgcrypt
Suggested version: libgcrypt-1.5.0.tar.bz2
Unzip: #tar -xvjf libgcrypt-1.5.0.tar.bz2
Change to the sub-directory created when you unzipped the tarball:
#cd libgcrypt-1.5.0/
Build and install the library:
./configure --libdir=/usr/local/lib
make
make install

Gmp
Before installing nettle, you must install GMP. If you accidently install nettle previously, please install gmp first and then reinstall nettle.
Suggested version: gmp-5.0.5.tar.bz2
#wget  ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.5.tar.bz2
And don’t forget .sig file for untar: #wget ftp://ftp.gmplib.org/pub/gmp-5.0.5/gmp-5.0.5.tar.bz2.sig
Unzip: #tar -xvjf gmp-5.0.5.tar.bz2
Change to the sub-directory created when you unzipped the tarball:
#cd gmp-5.0.5/
Build and install the library:
./configure
make
make install

Install nettle
Suggested version: nettle-2.4.tar.gz
#wget  http://www.lysator.liu.se/~nisse/archive/nettle-2.4.tar.gz
Unzip: #tar -xvzf nettle-2.4.tar.gz
Change to the sub-directory created when you unzipped the tarball:
#cd nettle-2.4/
Build and install the library:
./configure
make
make install

Install zlib

Install p11-kit


Then install gnutls
Suggested version: gnutls-3.0.9.tar.xz
#wget  ftp://ftp.gnu.org/gnu/gnutls/gnutls-3.0.9.tar.xz
And don’t forget .sig file for untar: #wget ftp://ftp.gnu.org/gnu/gnutls/gnutls-3.0.9.tar.xz.sig
Unzip: #tar -xvzf gnutls-3.0.9.tar.xz
Change to the sub-directory created when you unzipped the tarball:
#cd gnutls-3.0.9/
Build and install the library:
./configure --with-included-libtasn1 --libdir=/usr/local/lib
make
make install

Manually copy some run-time libraries to /usr/lib
Copy the following dynamic libraries from /usr/local/lib to /usr/lib
libgcrypt.so.11.7.0 (only if you installed from source)
libgnutls.so.27
libgnutls.so.27.0.1
libgnutls-openssl.so.27
libgnutls-openssl.so.27.0.1


For the RADIUS accounting module


Mediaproxy 2
Suggested version: mediaproxy-2.5.2.tar.gz
#wget http://download.ag-projects.com/MediaProxy/mediaproxy-2.5.2.tar.gz
Suggested location to copy and then unzip the tarball: /usr/local
Unzip: #tar -xzf mediaproxy-2.5.2.tar.gz
Change to the sub-directory created when you unzipped the tarball
Build and install the library (system wide):
./setup.py build
./setup.py install

Enable IP Forwarding by making changes in /etc/sysctl.conf file... 
Permanently enable ip forwarding,,,
# gedit /etc/sysctl.conf &
...

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Then, try these commands
# echo 1 > /proc/sys/net/ipv4/ip_forward
# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

Make directory, copy necessary files to proper directories, and setup ownership:
#mkdir /var/run/mediaproxy
#cp config.ini.sample /etc/mediaproxy/config.ini
#cp tls/* /etc/mediaproxy/tls/
Config.ini
OpenSIPS+MediaProxy Integration:
# mkdir /var/run/mediaproxy
# gedit config.ini &

Make following changes in file...
Change IP address according to your server.

[Relay]
dispatchers = mydomain.net:5060 _sip._udp.mydomain.net
port_range = 50000:60000
log_level = DEBUG
on_hold_timeout = 1800

[Dispatcher]
listen = 10.1.10.205:50000
management_use_tls = no
log_level = DEBUG
accounting = radius

[Radius]
; This section needs to be configured if radius accounting is enabled
; OpenSIPS RADIUS configuration file. All RADIUS cofiguration parameters will
; be read from this file, including dictionary files.
;
;config_file = /etc/opensips/radius/client.conf
config_file = /etc/freeradius/clients.conf

; Additional dictionary file with MediaProxy specific attributes.
;additional_dictionary = radius/dictionary
additional_dictionary = /etc/freeradius/dictionary

[OpenSIPS]
socket_path = '/var/run/opensips/socket'


Now edit opensips.cfg file to include MediaProxy...
#
# ----- nat_traversal
#**
loadmodule "nat_traversal.so"
#**
modparam("nat_traversal", "keepalive_interval", 90)
modparam("nat_traversal", "keepalive_method", "OPTIONS")
modparam("nat_traversal", "keepalive_from", "sip:keepalive@mydomain.com")


#
# --> nathelper
#**
loadmodule "nathelper.so"
#**
modparam("nathelper", "natping_interval", 60)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", 7)
modparam("nathelper", "received_avp", "$avp(i:801)")
modparam("nathelper", "sipping_from", "sip:pinger@mydomain.com")

#
#**
loadmodule "mediaproxy.so"
#**
#--------------- Default Values
modparam("mediaproxy", "mediaproxy_socket", "/var/run/mediaproxy/dispatcher.sock")
modparam("mediaproxy", "mediaproxy_timeout", 500)
modparam("mediaproxy", "signaling_ip_avp", "$avp(s:nat_ip)")
modparam("mediaproxy", "media_relay_avp", "$avp(s:media_relay)")

#--------------- Main Routing Logic

#

Starting MediaProxy Dispatcher...
#./media-dispatcher --no-fork
#./media-dispatcher &

The most notorious error I have met: “Libnettle 2.4 was not found” although nettle was installed.
Solution: This is because I did not install GMP before install Nettle, so Nettle did not create libhogweed for gnutls installing progress.