install_prereq: Update FreeBSD libraries.
[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 pkg-config"
23 # Asterisk: basic requirements:
24 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libedit-dev libjansson-dev libsqlite3-dev uuid-dev libxml2-dev"
25 # Asterisk: for addons:
26 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libspeex-dev libspeexdsp-dev libogg-dev libvorbis-dev libasound2-dev portaudio19-dev libcurl4-openssl-dev xmlstarlet bison flex"
27 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libltdl-dev libneon27-dev libgmime-2.6-dev liblua5.2-dev liburiparser-dev libxslt1-dev libssl-dev"
28 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libvpb-dev libmysqlclient-dev libbluetooth-dev libradcli-dev freetds-dev libosptk-dev libjack-jackd2-dev bash"
29 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-common-dev libcpg-dev libcfg-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev"
30 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample1-dev libc-client2007e-dev binutils-dev libsrtp0-dev libsrtp2-dev libgsm1-dev doxygen graphviz zlib1g-dev libldap2-dev"
31 PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcodec2-dev libfftw3-dev libsndfile1-dev libunbound-dev"
32 # Asterisk: for the unpackaged below:
33 PACKAGES_DEBIAN="$PACKAGES_DEBIAN wget subversion"
34 # Asterisk: for ./configure --with-pjproject-bundled:
35 PACKAGES_DEBIAN="$PACKAGES_DEBIAN bzip2 patch python-dev"
36
37 # Basic build system:
38 PACKAGES_RH="make gcc gcc-c++ pkgconfig"
39 # Asterisk: basic requirements:
40 PACKAGES_RH="$PACKAGES_RH libedit-devel jansson-devel libuuid-devel sqlite-devel libxml2-devel"
41 # Asterisk: for addons:
42 PACKAGES_RH="$PACKAGES_RH speex-devel speexdsp-devel libogg-devel libvorbis-devel alsa-lib-devel portaudio-devel libcurl-devel xmlstarlet bison flex"
43 PACKAGES_RH="$PACKAGES_RH postgresql-devel unixODBC-devel libtool-ltdl-devel neon-devel gmime-devel lua-devel uriparser-devel libxslt-devel openssl-devel"
44 PACKAGES_RH="$PACKAGES_RH mysql-devel bluez-libs-devel radcli-devel freetds-devel jack-audio-connection-kit-devel bash"
45 PACKAGES_RH="$PACKAGES_RH net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libical-devel spandsp-devel"
46 PACKAGES_RH="$PACKAGES_RH libresample-devel uw-imap-devel binutils-devel libsrtp-devel gsm-devel doxygen graphviz zlib-devel openldap-devel hoard"
47 PACKAGES_RH="$PACKAGES_RH codec2-devel fftw-devel libsndfile-devel unbound-devel"
48 # Asterisk: for the unpackaged below:
49 PACKAGES_RH="$PACKAGES_RH wget subversion"
50 # Asterisk: for ./configure --with-pjproject-bundled:
51 PACKAGES_RH="$PACKAGES_RH bzip2 patch python-devel"
52
53 # Basic build system:
54 PACKAGES_OBSD="gmake"
55 # Asterisk: basic requirements:
56 PACKAGES_OBSD="$PACKAGES_OBSD libxml sqlite3 e2fsprogs jansson"
57 # Asterisk: for addons:
58 PACKAGES_OBSD="$PACKAGES_OBSD speex speexdsp libogg libvorbis portaudio-svn curl xmlstarlet bison"
59 PACKAGES_OBSD="$PACKAGES_OBSD postgresql-client iodbc libltdl neon gmime lua%5.2 uriparser libxslt"
60 PACKAGES_OBSD="$PACKAGES_OBSD mariadb-client radcli freetds"
61 PACKAGES_OBSD="$PACKAGES_OBSD net-snmp iksemel popt libical spandsp"
62 PACKAGES_OBSD="$PACKAGES_OBSD c-client libsrtp gsm doxygen graphviz"
63 PACKAGES_OBSD="$PACKAGES_OBSD fftw3 libsndfile"
64 # Asterisk: for the unpackaged below:
65 PACKAGES_OBSD="$PACKAGES_OBSD wget subversion"
66 # Asterisk: for ./configure --with-pjproject-bundled:
67 PACKAGES_OBSD="$PACKAGES_OBSD bzip2 python%2"
68
69 # Basic build system:
70 PACKAGES_FBSD="gmake pkgconf"
71 # Asterisk: basic requirements:
72 PACKAGES_FBSD="$PACKAGES_FBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
73 # Asterisk: for addons:
74 PACKAGES_FBSD="$PACKAGES_FBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
75 PACKAGES_FBSD="$PACKAGES_FBSD postgresql10-client unixODBC libltdl neon gmime26 lua52 uriparser libxslt openssl"
76 PACKAGES_FBSD="$PACKAGES_FBSD mysql57-client radcli freetds"
77 PACKAGES_FBSD="$PACKAGES_FBSD net-snmp iksemel corosync newt popt libical spandsp"
78 PACKAGES_FBSD="$PACKAGES_FBSD cclient libbfd libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
79 PACKAGES_FBSD="$PACKAGES_FBSD codec2 fftw3 libsndfile unbound"
80 # Asterisk: for the unpackaged below:
81 PACKAGES_FBSD="$PACKAGES_FBSD wget subversion"
82 # Asterisk: for ./configure --with-pjproject-bundled:
83 PACKAGES_FBSD="$PACKAGES_FBSD bzip2 patch python"
84
85 KVERS=`uname -r`
86
87 JANSSON_VER=2.11
88
89 case "$1" in
90 test)
91         testcmd=echo
92         ;;
93 install)
94         testcmd=''
95         ;;
96 install-unpackaged)
97         unpackaged="yes"
98         ;;
99 '')
100         usage
101         exit 0
102         ;;
103 *)
104         usage
105         exit 1
106         ;;
107 esac
108
109 in_test_mode() {
110         test "$testcmd" != ''
111 }
112
113 check_installed_debs() {
114         for pack in "$@" ; do
115                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
116         done
117         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
118         if [ ${#pkgs} -ne 0 ]; then
119                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
120         fi
121 }
122
123 # parsing the output of yum is close to impossible.
124 # We'll use rpm and hope for the best:
125 check_installed_rpms() {
126         for pack in "$@"
127         do
128                 if ! rpm -q $pack >/dev/null 2>/dev/null
129                 then echo $pack
130                 fi
131         done
132 }
133
134 check_installed_pkgs() {
135         for pack in "$@"
136         do
137                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
138                 echo $pack
139                 fi
140         done
141 }
142
143 check_installed_fpkgs() {
144         for pack in "$@"
145         do
146                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
147                 echo $pack
148                 fi
149         done
150 }
151
152 handle_debian() {
153         if ! [ -x "$(command -v aptitude)" ]; then
154                 apt-get install aptitude
155         fi
156         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
157         $testcmd aptitude update
158         if [ x"$extra_packs" != "x" ] ; then
159                 $testcmd aptitude install -y $extra_packs
160         fi
161 }
162
163 handle_rh() {
164         extra_packs=`check_installed_rpms $PACKAGES_RH`
165         if [ x"$extra_packs" != "x" ] ; then
166                 $testcmd yum install --skip-broken --assumeyes $extra_packs
167         fi
168 }
169
170 handle_obsd() {
171         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
172         if [ x"$extra_packs" != "x" ] ; then
173                 $testcmd pkg_add $extra_packs
174         fi
175 }
176
177 handle_fbsd() {
178         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
179         if [ x"$extra_packs" != "x" ] ; then
180                 $testcmd pkg install -y $extra_packs
181         fi
182 }
183
184 install_unpackaged() {
185         echo "*** Installing NBS (Network Broadcast Sound) ***"
186         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
187         cd nbs-trunk
188         make all install
189         cd ..
190
191         # Only install libresample if it wasn't installed via package
192         if ! test -f /usr/include/libresample.h; then
193                 echo "*** Installing libresample ***"
194                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
195                 cd libresample-trunk
196                 ./configure
197                 make all install
198                 cd ..
199         fi
200
201         # Only install Jansson if it wasn't installed via package
202         if ! test -f /usr/include/jansson.h; then
203                 echo "*** Installing jansson ***"
204                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
205                 cd jansson-${JANSSON_VER}
206                 ./configure
207                 make all install
208                 cd ..
209                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
210                 /sbin/ldconfig
211         fi
212
213         # Only install libsrtp2 if it wasn't installed via package
214         if ! test -f /usr/include/srtp/srtp.h; then
215                 if ! test -f /usr/include/srtp2/srtp.h; then
216                         echo "*** Installing libsrtp2 ***"
217                         wget -O - http://github.com/cisco/libsrtp/archive/v2.tar.gz | zcat | tar -xf -
218                         cd libsrtp-2
219                         ./configure --enable-openssl
220                         make shared_library install
221                         cd ..
222                         echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
223                         /sbin/ldconfig
224                 fi
225         fi
226
227         if ! test -f /usr/include/pjlib.h; then
228                 echo "PJProject not installed, yet. Therefore, please, run"
229                 echo "./configure --with-pjproject-bundled"
230         fi
231 }
232
233 if in_test_mode; then
234         echo "#############################################"
235         echo "## $1: test mode."
236         echo "## Use the commands here to install your system."
237         echo "#############################################"
238 elif test "${unpackaged}" = "yes" ; then
239         install_unpackaged
240         exit 0
241 fi
242
243 OS=`uname -s`
244 unsupported_distro=''
245
246 # A number of distributions we don't (yet?) support.
247 if [ "$OS" != 'Linux' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
248         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
249         exit 1
250 fi
251
252 if [ -f /etc/gentoo-release ]; then
253         unsupported_distro='Gentoo'
254 fi
255
256 if [ -f /etc/mandrake-release ]; then
257         unsupported_distro='Mandriva'
258 fi
259
260 if [ -f /etc/SuSE-release ]; then
261         unsupported_distro='SUSE'
262 fi
263
264 if [ -f /etc/slackware-version ]; then
265         unsupported_distro='Slackware'
266 fi
267
268 if [ "$unsupported_distro" != '' ]; then
269         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
270         exit 1
271 fi
272
273 # The distributions we do support:
274 if [ -r /etc/debian_version ]; then
275         handle_debian
276 elif [ -r /etc/redhat-release ]; then
277         handle_rh
278 elif [ "$OS" = 'OpenBSD' ]; then
279         handle_obsd
280 elif [ "$OS" = 'FreeBSD' ]; then
281         handle_fbsd
282 fi
283
284 if ! in_test_mode; then
285         echo "#############################################"
286         echo "## $1 completed successfully"
287         echo "#############################################"
288 fi