pjproject_bundled: Various fixes discovered during testing of OSes
[asterisk/asterisk.git] / contrib / scripts / install_prereq
1 #! /bin/sh
2 #
3 # $Id$
4 #
5
6 # install_prereq: a script to install distribution-specific
7 # prerequirements
8
9 set -e
10
11 usage() {
12         echo "$0: a script to install distribution-specific prerequirement"
13         echo 'Revision: $Id$'
14         echo ""
15         echo "Usage: $0:                    Shows this message."
16         echo "Usage: $0 test                Prints commands it is about to run."
17         echo "Usage: $0 install             Really install."
18         echo "Usage: $0 install-unpackaged  Really install unpackaged requirements."
19 }
20
21 # Basic build system:
22 PACKAGES_DEBIAN="build-essential"
23 # Asterisk: basic requirements:
24 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libncurses-dev libz-dev libssl-dev libxml2-dev libsqlite3-dev uuid-dev uuid"
25 # Asterisk: for addons:
26 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcurl-dev libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-openssl-dev"
27 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libsqlite0-dev libmysqlclient15-dev libneon27-dev libgmime-dev libusb-dev liblua5.1-0-dev lua5.1"
28 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libopenh323-dev libvpb-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng-dev freetds-dev"
29 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev"
30 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev doxygen libjansson-dev libldap-dev"
31 PACKAGES_DEBIAN="$PACKAGES_DEBIAN subversion git libxslt1-dev automake libsrtp-dev libncurses5-dev python-dev"
32 PACKAGES_RH="automake bzip2 gcc gcc-c++ patch ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel"
33 PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
34 PACKAGES_RH="$PACKAGES_RH sqlite-devel libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
35 PACKAGES_RH="$PACKAGES_RH openldap-devel gmime22-devel sqlite2-devel mysql-devel bluez-libs-devel jack-audio-connection-kit-devel gsm-devel libedit-devel libuuid-devel"
36 PACKAGES_RH="$PACKAGES_RH jansson-devel libsrtp-devel pjproject-devel subversion git libxslt-devel python-devel"
37
38 PACKAGES_OBSD="popt gmake wget libxml libogg libvorbis curl iksemel spandsp speex iodbc freetds-0.63p1-msdblib mysql-client gmime sqlite sqlite3 jack libxslt"
39 PACKAGES_FBSD="autoconf gcc binutils popt gmake wget libxml2 libogg libvorbis curl iksemel spandsp speex unixODBC freetds-devel mysql55-client gmime2 sqlite"
40 PACKAGES_FBSD="$PACKAGES_FBSD sqlite3 libxslt jansson e2fsprogs-libuuid gsm libsrtp libsamplerate"
41
42 KVERS=`uname -r`
43
44 JANSSON_VER=2.4
45
46 case "$1" in
47 test)
48         testcmd=echo
49         ;;
50 install)
51         testcmd=''
52         ;;
53 install-unpackaged)
54         unpackaged="yes"
55         ;;
56 '')
57         usage
58         exit 0
59         ;;
60 *)
61         usage
62         exit 1
63         ;;
64 esac
65
66 in_test_mode() {
67         test "$testcmd" != ''
68 }
69
70 check_installed_debs() {
71         for pack in "$@" ; do
72                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
73         done
74         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
75         if [ ${#pkgs} -ne 0 ]; then
76                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
77         fi
78 }
79
80 # parsing the output of yum is close to impossible.
81 # We'll use rpm and hope for the best:
82 check_installed_rpms() {
83         for pack in "$@"
84         do
85                 if ! rpm -q $pack >/dev/null 2>/dev/null
86                 then echo $pack
87                 fi
88         done
89 }
90
91 check_installed_pkgs() {
92         for pack in "$@"
93         do
94                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
95                 echo $pack
96                 fi
97         done
98 }
99
100 check_installed_fpkgs() {
101         for pack in "$@"
102         do
103                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
104                 echo $pack
105                 fi
106         done
107 }
108
109 handle_debian() {
110         if ! [ -x "$(command -v aptitude)" ]; then
111                 apt-get install aptitude
112         fi
113         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
114         $testcmd aptitude update
115         if [ x"$extra_packs" != "x" ] ; then
116                 $testcmd aptitude install -y $extra_packs
117         fi
118 }
119
120 handle_rh() {
121         extra_packs=`check_installed_rpms $PACKAGES_RH`
122         if [ x"$extra_packs" != "x" ] ; then
123                 $testcmd yum install -y $extra_packs
124         fi
125 }
126
127 handle_obsd() {
128         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
129         if [ x"$extra_packs" != "x" ] ; then
130                 $testcmd pkg_add $extra_packs
131         fi
132 }
133
134 handle_fbsd() {
135         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
136         if [ x"$extra_packs" != "x" ] ; then
137                 $testcmd pkg install -y $extra_packs
138         fi
139 }
140
141 install_unpackaged() {
142         echo "*** Installing NBS (Network Broadcast Sound) ***"
143         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
144         cd nbs-trunk
145         make && make install
146         cd ..
147
148         # Only install libresample if it wasn't installed via package
149         if ! test -f /usr/include/libresample.h; then
150                 echo "*** Installing libresample ***"
151                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
152                 cd libresample-trunk
153                 ./configure && make && make install
154                 cd ..
155         fi
156
157         # Only install Jansson if it wasn't installed via package
158         if ! test -f /usr/include/jansson.h; then
159                 echo "*** Installing jansson ***"
160                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
161                 cd jansson-${JANSSON_VER}
162                 ./configure && make all && make install
163                 cd ..
164                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
165                 /sbin/ldconfig
166         fi
167
168         # Only install libsrtp if it wasn't installed via package
169         if ! test -f /usr/include/srtp/srtp.h; then
170                 echo "*** Installing libsrtp ***"
171                 if [ ! -d libsrtp ]; then
172                         git clone https://github.com/cisco/libsrtp.git
173                         cd libsrtp
174                 else
175                         cd libsrtp
176                         git pull
177                 fi
178                 ./configure CFLAGS=-fPIC && make libsrtp.a && make uninstall && make install
179                 cd ..
180                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
181                 /sbin/ldconfig
182         fi
183
184         # Only install pjproject if it wasn't installed via package
185         if ! test -f /usr/include/pjlib.h; then
186                 echo "*** Installing pjproject ***"
187                 if [ ! -d pjproject ]; then
188                         git clone https://github.com/asterisk/pjproject.git
189                         cd pjproject
190                 else
191                         cd pjproject
192                         git pull
193                 fi
194                 ./configure CFLAGS="-DNDEBUG -DPJ_HAS_IPV6=1" --enable-shared --with-external-speex --with-external-gsm --with-external-srtp --disable-sound --disable-resample && make && make install
195                 cd ..
196                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
197                 /sbin/ldconfig
198         fi
199 }
200
201 if in_test_mode; then
202         echo "#############################################"
203         echo "## $1: test mode."
204         echo "## Use the commands here to install your system."
205         echo "#############################################"
206 elif test "${unpackaged}" = "yes" ; then
207         install_unpackaged
208         exit 0
209 fi
210
211 OS=`uname -s`
212 unsupported_distro=''
213
214 # A number of distributions we don't (yet?) support.
215 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
216         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
217         exit 1
218 fi
219
220 if [ -f /etc/gentoo-release ]; then
221         unsupported_distro='Gentoo'
222 fi
223
224 if [ -f /etc/mandrake-release ]; then
225         unsupported_distro='Mandriva'
226 fi
227
228 if [ -f /etc/SuSE-release ]; then
229         unsupported_distro='SUSE'
230 fi
231
232 if [ -f /etc/slackware-version ]; then
233         unsupported_distro='Slackware'
234 fi
235
236 if [ "$unsupported_distro" != '' ]; then
237         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
238         exit 1
239 fi
240
241 # The distributions we do support:
242 if [ -r /etc/debian_version ]; then
243         handle_debian
244 elif [ -r /etc/redhat-release ]; then
245         handle_rh
246 elif [ "$OS" = 'OpenBSD' ]; then
247         handle_obsd
248 elif [ "$OS" = 'FreeBSD' ]; then
249         handle_fbsd
250 fi
251
252 if ! in_test_mode; then
253         echo "#############################################"
254         echo "## $1 completed successfully"
255         echo "#############################################"
256 fi