Merge "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_NBSD="gmake pkg-config"
55 # Asterisk: basic requirements:
56 PACKAGES_NBSD="$PACKAGES_NBSD editline jansson sqlite3 libuuid libxml2"
57 # Asterisk: for addons:
58 PACKAGES_NBSD="$PACKAGES_NBSD speex speexdsp libogg libvorbis alsa-lib portaudio-devel curl bison flex"
59 PACKAGES_NBSD="$PACKAGES_NBSD postgresql10-client unixodbc libltdl neon gmime lua52 uriparser libxslt openssl"
60 PACKAGES_NBSD="$PACKAGES_NBSD mysql-client radiusclient-ng freetds bash"
61 PACKAGES_NBSD="$PACKAGES_NBSD net-snmp iksemel popt libical spandsp"
62 PACKAGES_NBSD="$PACKAGES_NBSD imap-uw srtp gsm doxygen graphviz libzip openldap-client"
63 PACKAGES_NBSD="$PACKAGES_NBSD codec2 fftw libsndfile unbound"
64 # Asterisk: for the unpackaged below:
65 PACKAGES_NBSD="$PACKAGES_NBSD wget subversion-base"
66 # Asterisk: for ./configure --with-pjproject-bundled:
67 PACKAGES_NBSD="$PACKAGES_NBSD bzip2 patch python27"
68
69 # Basic build system:
70 PACKAGES_OBSD="gmake"
71 # Asterisk: basic requirements:
72 PACKAGES_OBSD="$PACKAGES_OBSD libxml sqlite3 e2fsprogs jansson"
73 # Asterisk: for addons:
74 PACKAGES_OBSD="$PACKAGES_OBSD speex speexdsp libogg libvorbis portaudio-svn curl xmlstarlet bison"
75 PACKAGES_OBSD="$PACKAGES_OBSD postgresql-client iodbc libltdl neon gmime lua%5.2 uriparser libxslt"
76 PACKAGES_OBSD="$PACKAGES_OBSD mariadb-client radcli freetds"
77 PACKAGES_OBSD="$PACKAGES_OBSD net-snmp iksemel popt libical spandsp"
78 PACKAGES_OBSD="$PACKAGES_OBSD c-client libsrtp gsm doxygen graphviz"
79 PACKAGES_OBSD="$PACKAGES_OBSD fftw3 libsndfile"
80 # Asterisk: for the unpackaged below:
81 PACKAGES_OBSD="$PACKAGES_OBSD wget subversion"
82 # Asterisk: for ./configure --with-pjproject-bundled:
83 PACKAGES_OBSD="$PACKAGES_OBSD bzip2 python%2"
84
85 # Basic build system:
86 PACKAGES_FBSD="gmake pkgconf"
87 # Asterisk: basic requirements:
88 PACKAGES_FBSD="$PACKAGES_FBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
89 # Asterisk: for addons:
90 PACKAGES_FBSD="$PACKAGES_FBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
91 PACKAGES_FBSD="$PACKAGES_FBSD postgresql10-client unixODBC libltdl neon gmime26 lua52 uriparser libxslt openssl"
92 PACKAGES_FBSD="$PACKAGES_FBSD mysql57-client radcli freetds"
93 PACKAGES_FBSD="$PACKAGES_FBSD net-snmp iksemel corosync newt popt libical spandsp"
94 PACKAGES_FBSD="$PACKAGES_FBSD cclient libbfd libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
95 PACKAGES_FBSD="$PACKAGES_FBSD codec2 fftw3 libsndfile unbound"
96 # Asterisk: for the unpackaged below:
97 PACKAGES_FBSD="$PACKAGES_FBSD wget subversion"
98 # Asterisk: for ./configure --with-pjproject-bundled:
99 PACKAGES_FBSD="$PACKAGES_FBSD bzip2 patch python"
100
101 KVERS=`uname -r`
102
103 JANSSON_VER=2.11
104
105 case "$1" in
106 test)
107         testcmd=echo
108         ;;
109 install)
110         testcmd=''
111         ;;
112 install-unpackaged)
113         unpackaged="yes"
114         ;;
115 '')
116         usage
117         exit 0
118         ;;
119 *)
120         usage
121         exit 1
122         ;;
123 esac
124
125 in_test_mode() {
126         test "$testcmd" != ''
127 }
128
129 check_installed_debs() {
130         for pack in "$@" ; do
131                 tocheck="${tocheck} ^${pack}$ ~P^${pack}$"
132         done
133         pkgs=$(aptitude -F '%c %p' search ${tocheck} 2>/dev/null | awk '/^p/{print $2}')
134         if [ ${#pkgs} -ne 0 ]; then
135                 echo $pkgs | sed -r -e "s/ ?[^ :]+:i386//g"
136         fi
137 }
138
139 # parsing the output of yum is close to impossible.
140 # We'll use rpm and hope for the best:
141 check_installed_rpms() {
142         for pack in "$@"
143         do
144                 if ! rpm -q $pack >/dev/null 2>/dev/null
145                 then echo $pack
146                 fi
147         done
148 }
149
150 check_installed_pkgs() {
151         for pack in "$@"
152         do
153                 if [ `pkg_info -a | grep $pack | wc -l` = 0 ]; then
154                 echo $pack
155                 fi
156         done
157 }
158
159 check_installed_fpkgs() {
160         for pack in "$@"
161         do
162                 if [ `pkg info -a | grep $pack | wc -l` = 0 ]; then
163                 echo $pack
164                 fi
165         done
166 }
167
168 handle_debian() {
169         if ! [ -x "$(command -v aptitude)" ]; then
170                 apt-get install aptitude
171         fi
172         extra_packs=`check_installed_debs $PACKAGES_DEBIAN`
173         $testcmd aptitude update
174         if [ x"$extra_packs" != "x" ] ; then
175                 $testcmd aptitude install -y $extra_packs
176         fi
177 }
178
179 handle_rh() {
180         extra_packs=`check_installed_rpms $PACKAGES_RH`
181         if [ x"$extra_packs" != "x" ] ; then
182                 $testcmd yum install --skip-broken --assumeyes $extra_packs
183         fi
184 }
185
186 handle_nbsd() {
187         extra_packs=`check_installed_pkgs $PACKAGES_NBSD`
188         if [ x"$extra_packs" != "x" ] ; then
189                 if [ -z "$PKG_PATH" ] ; then
190                         # see NetBSD Problem Report #48177
191                         export PKG_PATH="http://cdn.NetBSD.org/pub/pkgsrc/packages/$(uname -s)/$(uname -p)/$(uname -r)/All"
192                 fi
193                 $testcmd pkg_add $extra_packs
194         fi
195 }
196
197 handle_obsd() {
198         extra_packs=`check_installed_pkgs $PACKAGES_OBSD`
199         if [ x"$extra_packs" != "x" ] ; then
200                 $testcmd pkg_add $extra_packs
201         fi
202 }
203
204 handle_fbsd() {
205         extra_packs=`check_installed_fpkgs $PACKAGES_FBSD`
206         if [ x"$extra_packs" != "x" ] ; then
207                 $testcmd pkg install -y $extra_packs
208         fi
209 }
210
211 install_unpackaged() {
212         echo "*** Installing NBS (Network Broadcast Sound) ***"
213         svn co http://svn.digium.com/svn/nbs/trunk nbs-trunk
214         cd nbs-trunk
215         make all install
216         cd ..
217
218         # Only install libresample if it wasn't installed via package
219         if ! test -f /usr/include/libresample.h; then
220                 echo "*** Installing libresample ***"
221                 svn co http://svn.digium.com/svn/thirdparty/libresample/trunk libresample-trunk
222                 cd libresample-trunk
223                 ./configure
224                 make all install
225                 cd ..
226         fi
227
228         # Only install Jansson if it wasn't installed via package
229         if ! test -f /usr/include/jansson.h; then
230                 echo "*** Installing jansson ***"
231                 wget -O - http://www.digip.org/jansson/releases/jansson-${JANSSON_VER}.tar.gz | zcat | tar -xf -
232                 cd jansson-${JANSSON_VER}
233                 ./configure
234                 make all install
235                 cd ..
236                 echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
237                 /sbin/ldconfig
238         fi
239
240         # Only install libsrtp2 if it wasn't installed via package
241         if ! test -f /usr/include/srtp/srtp.h; then
242                 if ! test -f /usr/include/srtp2/srtp.h; then
243                         echo "*** Installing libsrtp2 ***"
244                         wget -O - http://github.com/cisco/libsrtp/archive/v2.tar.gz | zcat | tar -xf -
245                         cd libsrtp-2
246                         ./configure --enable-openssl
247                         make shared_library install
248                         cd ..
249                         echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local.conf
250                         /sbin/ldconfig
251                 fi
252         fi
253
254         if ! test -f /usr/include/pjlib.h; then
255                 echo "PJProject not installed, yet. Therefore, please, run"
256                 echo "./configure --with-pjproject-bundled"
257         fi
258 }
259
260 if in_test_mode; then
261         echo "#############################################"
262         echo "## $1: test mode."
263         echo "## Use the commands here to install your system."
264         echo "#############################################"
265 elif test "${unpackaged}" = "yes" ; then
266         install_unpackaged
267         exit 0
268 fi
269
270 OS=`uname -s`
271 unsupported_distro=''
272
273 # A number of distributions we don't (yet?) support.
274 if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
275         echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
276         exit 1
277 fi
278
279 if [ -f /etc/gentoo-release ]; then
280         unsupported_distro='Gentoo'
281 fi
282
283 if [ -f /etc/mandrake-release ]; then
284         unsupported_distro='Mandriva'
285 fi
286
287 if [ -f /etc/SuSE-release ]; then
288         unsupported_distro='SUSE'
289 fi
290
291 if [ -f /etc/slackware-version ]; then
292         unsupported_distro='Slackware'
293 fi
294
295 if [ "$unsupported_distro" != '' ]; then
296         echo >&2 "$0: Your distribution ($unsupported_distro) is currently not supported. Aborting."
297         exit 1
298 fi
299
300 # The distributions we do support:
301 if [ -r /etc/debian_version ]; then
302         handle_debian
303 elif [ -r /etc/redhat-release ]; then
304         handle_rh
305 elif [ "$OS" = 'NetBSD' ]; then
306         handle_nbsd
307 elif [ "$OS" = 'OpenBSD' ]; then
308         handle_obsd
309 elif [ "$OS" = 'FreeBSD' ]; then
310         handle_fbsd
311 fi
312
313 if ! in_test_mode; then
314         echo "#############################################"
315         echo "## $1 completed successfully"
316         echo "#############################################"
317 fi